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.
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() ).
In vim, you can check if a file is open in the current buffer with bufexists . For a short filename (not full path), you can check if it's open using bufexists(bufname('filename')) .
If you want to use NERDTree, you can open NERDTree (type :NERDTree ), navigate to your file, and then press t with cursor on the file name. This will open specific file in new tab.
The NERDTree plugin itself already has a function for this purpose.
g:NERDTree.IsOpen()
Example:
if exists("g:NERDTree") && g:NERDTree.IsOpen()
....
endif
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With