@FDinoff has shown the way, but actually you don't need to implement the NERDTree focus yourself. It's undocumented, but it's built in.
Try this mapping:
:nnoremap <leader>ne :NERDTreeFocus<CR>
Taken from this great answer by @kev.
Question
I am new to vim, so if this is really stupid I apologize in advance, but I can't seem to find it on google.
I found on stack overflow this snipped which sets the focus to nerdtree:
let mapleader = ","
nmap <leader>ne :NERDTree<cr>
But if i have a bunch of directories expanded when I run this command it resets, is there a way where it does not reset?
I am using Macvim if it helps.
Also, I know about :NERDTreeToggle
, but I want the tree visable all the time.
Solution
@FDinoff has shown the way, but actually you don't need to implement the NERDTree focus yourself. It's undocumented, but it's built in.
Try this mapping:
:nnoremap <leader>ne :NERDTreeFocus<CR>
Taken from this great answer by @kev.
OTHER TIPS
The nerdtree window has the filetype of nerdtree
Below is a function that will focus the first window that has filetype nerd tree or leave the cursor in the window it was originally in.
function! FocusNERDtree()
let initial_win_num = winnr()
for i in range(1, winnr('$'))
exec i.'wincmd w'
if &filetype == 'nerdtree'
return 1
endif
endfor
exec initial_win_num.'wincmd w'
return 0
endfunction
So you can just create a map for this.
nnoremap <leader>nf :call FocusNERDtree()<cr>
Or you could just move the window manually using <c-w>
and a direction (h
,j
,k
or l
)