Vim – Prevent NERDTree opening when invoked by git

gitnerdtreevimvimrc

Nice and simple, I'd like for NERDTree not to get involved when vim is invoked by git, for example when authoring a commit message or dealing with a rebase.

Presumably this is achievable by way of some kind of filetype detection (gitcommit etc), but precisely how to do it I have no idea. The relevant parts of my vimrc at the moment are:

autocmd vimenter * NERDTree
map <C-n> :NERDTreeToggle<CR>

I wish to retain the auto-opening of NERDTree in the general case. I've tried something along the lines of:

autocmd FileType gitcommit NERDTreeToggle

However the docs would suggest VimEnter as pretty much the last thing to fire after all buffers have been loaded etc, so I guess that's why this doesn't work.

Thanks in advance.

Best Answer

I think you already have all the pieces together: Just combine the launch of NERDTree with a conditional on the filetype; when VimEnter fires, this should already be set:

:autocmd VimEnter * if &filetype !=# 'gitcommit' | NERDTree | endif
Related Question