yaohunzhanyue / collcetion

6 stars 0 forks source link

Automatically quit vim if netrw is last and only buffer #12

Open yaohunzhanyue opened 4 years ago

yaohunzhanyue commented 4 years ago

This is simillar to this question , but I'm not using NERDTree , instead netrw for same purpose. I have tried tweaking the script in my .vimrc a little bit , but I have no idea what do netrw buffers are named as.

With NERDTree this went well , but having tough luck with netrw.

autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif

Thanks :)

Add to your .vimrc file

aug netrw_close
  au!
  au WinEnter * if winnr('$') == 1 && getbufvar(winbufnr(winnr()), "&filetype") == "netrw"|q|endif
aug END

Warnings

Netrw can easily be the only open window. This would mean your Vim instance would close unexpectedly. It would be better to learn how to use :qa if you want to close all the windows.