With the NERDTree window open and in focus, I enter the buffer delete (:bd) command. Then :NERDTreeToggle results in the following error:
Error detected while processing function <SNR>15_toggle..<SNR>15_renderView:
E121: Undefined variable: b:NERDTreeRoot
E15: Invalid expression: b:NERDTreeRoot.path.str({'format': 'UI', 'truncateTo': winwidth(0)})
E121: Undefined variable: header
E116: Invalid arguments for function setline
E121: Undefined variable: b:NERDTreeRoot
E15: Invalid expression: b:NERDTreeRoot.renderToString()
At this point the only way to fix NERDTreeToggle is to enter the :NERDTree command.
Vi IMproved 7.3 (2010 Aug 15, compiled Aug 2 2011 16:49:30)
NerdTree v4.2.0
Using gVim on Windows XP
same here
I have the following in my ~/.vimrc
" Close all the buffers
map <leader>ca :1,1000 bd<cr>
When I execute this, nerdtreetoggle does not give me any errors, its buffer just dissapears. When I type :NERDTreeToggle, an empty split shows up where nerdtree usually apperas, and I can't get it to actually show anything. I have to restart vim to get it back.
Hello, anything new on this?
I have the same issue, only NERDTree installed and when I get the NERDTree buffer if I kill that buffer with for example :bd, then it is gone. And when NERDTree is called back, it comes as an empty buffer and everything is broken after that. Any ideas?
Thanks.
Assuming toggle usually fails when the tree is closed and lacking buffers, this little hack does the job:
nmap <silent> <Leader>t :call g:WorkaroundNERDTreeToggle()<CR>
function! g:WorkaroundNERDTreeToggle()
try | :NERDTreeToggle | catch | :NERDTree | endtry
endfunction
The function above fails for me. The issue is that ":NERDTree" executes with errors and fails. This small fix worked for me:
nmap <silent> <Leader>t :call g:WorkaroundNERDTreeToggle()<CR>
function! g:WorkaroundNERDTreeToggle()
try | NERDTreeToggle | catch | silent! NERDTree | endtry
endfunction
Note the "silent!"
Edit: achieved the same results in a NERDTree-only vim environment.
Thanks for the update @rbong, the one I posted before used to work, but since I updated NERDTree to current master a few days ago, it stopped working and I haven't had the chance to look into it. Thanks for sharing, I'll give it a try.
Just verified the silent! before the NERDTree call kept the workaround valid for the current NERDTree stable.
:+1: This fix/thread is fantastic. Saving my sanity.
problem silenced in my workstation, Ubuntu 14.04
I'm still having issues even with the g:WorkaroundNERDTreeToggle function.
The "errors" (status-line execution errors) are no longer being thrown, but the behavior of NERDTree opening is still off, as it causes a strange issue where my current buffer is opened in just a NERDTree size split window.
Regardless, the g:WorkaroundNERDTreeToggle function is a hacky workaround... the plugin should really be detecting the condition where the buffer no longer exists, and then handle that appropriately (fall-back to a reopening?).
Hmm, actually this seems to be fixed by 0544ff524c5209cf885984739dde941fd9fd37af, which was a fix for #375.
Should this be closed @scrooloose? Maybe a patch release (5.0.1?) for the bugfix?
_Actually_, I'm still getting weird behavior, even after upgrading to the newest master:

😞
This issue seems to have been fixed, as mentioned above. Closing....
Im still experiencing this issue today (as of commit f554c20).
I know what's causing this. The :RemoveHiddenBuffers command must be running the :bwipeout command instead of the :bdelete command.
@whiteShtef, is this your issue as well (i.e., is a call to :bwipeout the root of your problem)? Also, @Rican7, can you confirm that :bwipeout was the original cause of the bug you reported?
If we can confirm this, I'll reopen.
I know what's causing this. The
:RemoveHiddenBufferscommand must be running the:bwipeoutcommand instead of the:bdeletecommand.
That's precisely what's happening: https://github.com/Rican7/dotfiles/blob/7ecd8991ff650ae3fca506820269a0d52874c226/config-rc/.vimrc#L265
Is there a simple fix to this?
@whiteShtef The simple fix is to just use :bdelete in the NERDTree buffer for now. I realize that's not a long-term solution, but it works for the moment.
I've diagnosed the problem, and it will likely be the next bug that I tackle. It's somewhat tricky, but a fix is definitely feasible soon.
@Rican7 Thanks for getting back to me.
I believe this was fixed by #814. @Rican7 and @whiteShtef, can you verify that for me?
Now I'm getting
Error detected while processing function 200[2]..201:
line 5:
E121: Undefined variable: b:NERDTree
line 7:
E121: Undefined variable: b:NERDTree
😕 Am I missing something?
I'll need more information to know for sure. Can you share your vimrc file? And to be sure we're talking about the same problem, describe how you reproduce these errors.
The relevant part of my vimrc:
"NERDTree config
autocmd vimenter * NERDTree " open on start
autocmd BufWinEnter * NERDTreeMirror " open in every new tab
autocmd BufWinEnter * wincmd p " when opened in new tab, switch to FILE buffer (default is the NERDTree buffer)“
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif " autoclose window/tab if last buffer is nerdtree
map <C-n> :NERDTreeToggle<CR>
The last line bounds NERDTreeToggle to C-n. I get the error when toggling the previously closed (toggled) NERDTree buffer.
@whiteShtef, I can't reproduce your errors with the snippet you provided. Can you share all of your vimrc? Remove any confidential information, of course. There are lots of options that could be affecting NERDTree's behavior.
@whiteShtef , I just took a closer, more careful look at your issue (sorry it took so long). I'd failed to see your last sentence, and indeed, I can recreate your issue now. Anyway, I think I figured out what's causing the error, but not necessarily why. If you change your autocmds from BufWinEnter to TabNew, the problem will go away. It's not necessary to mirror your NERDTree when opening a file in a new window (a split on the current tab), because that tab already has a NERDTree. Only when you create a new tab will you need to mirror the NERDTree.
If this solves your issue, go ahead and close this issue again.
Correct. Works like a charm. However, I didn't open this issue ergo I can't close it :)
No problem. I got you covered.
Most helpful comment
@whiteShtef The simple fix is to just use
:bdeletein the NERDTree buffer for now. I realize that's not a long-term solution, but it works for the moment.I've diagnosed the problem, and it will likely be the next bug that I tackle. It's somewhat tricky, but a fix is definitely feasible soon.
@Rican7 Thanks for getting back to me.