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? :)
Written by Matt Carroll
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Vim
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#