如果 netrw 是最后且唯一的缓冲区,则自动退出 vim
Automatically quit vim if netrw is last and only buffer
这与 question 类似,但我没有使用 NERDTree,而是出于相同目的使用 netrw。我试过稍微调整我的 .vimrc 中的脚本,但我不知道 netrw 缓冲区被命名为什么。
使用 NERDTree 时一切顺利,但使用 netrw 时运气不佳。
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
谢谢:)
添加到您的 .vimrc
文件
aug netrw_close
au!
au WinEnter * if winnr('$') == 1 && getbufvar(winbufnr(winnr()), "&filetype") == "netrw"|q|endif
aug END
警告
我没有测试上面的代码。
Netrw 很容易成为唯一打开的 window。这意味着您的 Vim 实例会意外关闭。如果你想关闭所有 windows.
最好学习如何使用 :qa
这与 question 类似,但我没有使用 NERDTree,而是出于相同目的使用 netrw。我试过稍微调整我的 .vimrc 中的脚本,但我不知道 netrw 缓冲区被命名为什么。
使用 NERDTree 时一切顺利,但使用 netrw 时运气不佳。
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
谢谢:)
添加到您的 .vimrc
文件
aug netrw_close
au!
au WinEnter * if winnr('$') == 1 && getbufvar(winbufnr(winnr()), "&filetype") == "netrw"|q|endif
aug END
警告
我没有测试上面的代码。
Netrw 很容易成为唯一打开的 window。这意味着您的 Vim 实例会意外关闭。如果你想关闭所有 windows.
最好学习如何使用:qa