I tried to write a command to save session compatible with NERDTree, I need to check if the NERDTree is open, I can't find any info though Google.
NERDTree internally stores the name of its scratch buffer (that represents the tree contents in Vim) in a tab-local variable. With bufwinnr()
, you can ask Vim whether the buffer is currently loaded in a window.
I use the following function to check for the NERDTree existence (in the current tab page; if you need this globally, you'd have to iterate over all tabs with gettabvar()
).
function! IsNerdTreeEnabled()
return exists('t:NERDTreeBufName') && bufwinnr(t:NERDTreeBufName) != -1
endfunction
The NERDTree plugin itself already has a function for this purpose.
g:NERDTree.IsOpen()
Example:
if exists("g:NERDTree") && g:NERDTree.IsOpen()
....
endif
NERDTree internally stores the name of its scratch buffer (that represents the tree contents in Vim) in a tab-local variable. With bufwinnr()
, you can ask Vim whether the buffer is currently loaded in a window.
I use the following function to check for the NERDTree existence (in the current tab page; if you need this globally, you'd have to iterate over all tabs with gettabvar()
).
function! IsNerdTreeEnabled()
return exists('t:NERDTreeBufName') && bufwinnr(t:NERDTreeBufName) != -1
endfunction
© 2022 - 2024 — McMap. All rights reserved.