Question

Is it possible to configure NERDTree so that :NERDTreeToggle acts like :NERDTreeFind if a buffer is not open (instead of the default :NERDTree) ?

Failing that, would it be possible to create a mapping/small script that could check the visibility of the NERDTree window and if open close it, if closed invoke NERDTreeFind ? I looked at the NERDTree documentation to find if the visibility of the NERDTree window was open, but could not find it.

Was it helpful?

Solution

You can set let NERDTreeQuitOnOpen=1 to close the tree when you select a file, and create a mapping for find:

nmap <leader>p :NERDTreeFind<CR>

OTHER TIPS

there is a function, which may help you to distinguish if the NERDTree is opened.

nerdtree#isTreeOpen()

you could test a little bit with :echom nerdtree#isTreeOpen() when you opened/closed the Nerdtree.

I'm now learning to use Vim too and had the same desire to make NERDTreeToggle to use NERDTreeFind when opening. After some digging/googling, I had a go at writing a simple Vim script below, and it seems to work for me! :]

function! ToggleNERDTreeFind()
    if g:NERDTree.IsOpen()
        execute ':NERDTreeClose'
    else
        execute ':NERDTreeFind'
    endif
endfunction

And I just bound the above function to a shortcut key to use for both finding/closing NERDTree. Hope this helps.

nnoremap <leader>f :call ToggleNERDTreeFind()<CR>

small improvment of the function provided by thomaswhyyou which also works if current buffer is empty:

function! ToggleNERDTreeFind()
    if g:NERDTree.IsOpen()
        execute ':NERDTreeClose'
    else
      if bufname('%') == ''
          execute ':NERDTree'
      else
          execute ':NERDTreeFind'
      endif
    endif
endfunction
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top