Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to check if NERDTree is open in vimscript?

Tags:

vim

nerdtree

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.

like image 929
Rupert Avatar asked Jan 09 '17 05:01

Rupert


People also ask

How do I know if NERDTree is installed?

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() ).

How do I know if Vim is open?

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')) .

How do I open a NERDTree file?

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.


1 Answers

The NERDTree plugin itself already has a function for this purpose.

g:NERDTree.IsOpen()

Example:

if exists("g:NERDTree") && g:NERDTree.IsOpen()
    ....
endif
like image 191
Jongwook Choi Avatar answered Sep 21 '22 01:09

Jongwook Choi