Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible to access the NERDTree buffer in vimscript?

Tags:

vim

nerdtree

I'm working on a plugin for NERDTree that I asked about here.

I've got a proof of concept plugin working up on Github and a pull request in to NERDTree with the hooks I need to edit the display strings.

The next thing I'd like to get working is refreshing the NERDTree buffer whenever a file is saved. I was thinking that the NERDTree api function "NERDTreeRender()" would be all I needed - something like:

autocmd BufWrite * call NERDTreeRender()

would work, but it called NERDTreeRender() on the buffer that was written, instead of the NERDTree one. Is there any way to have an autocmd run on bufwrite to that specific buffer? Running :buffers in vim doesn't give me any indication that NERDTree has a numbered buffer unfortunately.

Barring firing the autocmd on write to that specific buffer, does anyone have any other suggested ways to go about this?

like image 644
Scott Avatar asked Apr 15 '26 07:04

Scott


1 Answers

You can switch to the NERDTree buffer by setting switchbuf to useopen and calling sbuf NERD*

Something like:

autocmd BufWrite * call DoRender()

function! DoRender()
    set switchbuf+=useopen
    sbuf NERD*
    call NERDTreeRender()
endfunction
like image 83
mihai Avatar answered Apr 17 '26 23:04

mihai