Last Updated: February 25, 2016
·
1.356K
· oholiab

Auto toggle-off NERDTree in a small terminal

In my vimrc I have a little bit of code to automatically turn on the NERDTree sidebar and then put focus in the editing window to the right of it:

autocmd vimenter * NERDTree
autocmd vimenter * wincmd l
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
nmap <silent> <C-l> :NERDTreeToggle<CR>

However, I tend to find that when editing in a small terminal (especially when using pane splitting in Terminator or iTerm2), having the navigation pane pop up is really annoying, so I added this little conditional after the above code:

if winwidth(0) < 80
  autocmd vimenter * NERDTreeToggle
endif

If the terminal that I invoke vim from is smaller than 80 columns, NERDTree is automatically toggled as if I pressed ^L on loading up. This way I save myself a whole 2 keystrokes - after all, isn't that what computers are for? :)