5

I'm running into a problem that I've never really ran into before with my setup. I've set up my NERDTree config in the .vimrc so that every time that I open a directory NERDTree will also open but it should also stay open when I open a file (NERDTree to the left and buffers to the right) however, it doesn't do that. Right now it does open NERDTree but once I click enter on the file I want to open, NERDTree closes and I'm left only with the file I opened (no NERDTree on the left). The code is as follows:

autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif

this is the config I've been using on my .vimrc for NERDTree for quite some time, usually I just copy+paste my .vimrc into any new install of vim and it works after setting everything up. And in this case, everything else works, and even NERDTree, but it just closes after I open the file.

1
  • 1
    What does :echo NERDTreeQuitOnOpen show when you are in the context that is causing problems?
    – B Layer
    Dec 19, 2017 at 14:15

2 Answers 2

1

I have these in my config. This works well.

"Open NERDtree automatically on vim startup
autocmd vimenter * NERDTree

"close NERDtree if that is the last window left
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
0

Try this:

" don't quit NERDTree after opening a buffer
let NERDTreeQuitOnOpen = 0
" start NERDTree when vim starts
autocmd VimEnter * NERDTree

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.