Map F2 to NEERDTreeToggle
Asked Answered
A

2

11

I want just to open and close NERDTree, pushing the F2 button. I've mapped it in this way :

map <silent>  <F2> NERDTreeToggle 

But, Actually this doesn't work properly and I haven't understood why...

Apocynaceous answered 24/4, 2012 at 18:8 Comment(4)
nmap <silent> <F2> :execute 'NERDTreeToggle ' . getcwd()<CR>Vanadinite
Now it's perfect! Thanks... But can you explain me why you needed to add . getcwd()<CR>Apocynaceous
The <CR> is the necessary bit. It just means hit the Enter key to execute the command. But: nmap <silent> <F2> :NERDTreeToggle<CR> will do.Idou
getcwd() is used to set working directory.Vanadinite
O
15

Here is my config for NERDTree.

silent! nmap <C-p> :NERDTreeToggle<CR>
silent! map <F3> :NERDTreeFind<CR>

let g:NERDTreeMapActivateNode="<F3>"
let g:NERDTreeMapPreview="<F4>"

F3 will open NERDTree panel and highlight current file. And when you're in the NERDTree panel, F3 will open file under cursor. So, I can use one button to jump between buffer and NERDTree. (And F4 for preview because it's next to F3)

Oxpecker answered 2/5, 2012 at 16:19 Comment(3)
Is there a way to get the same behavior but open the file inder cursor in a split or vertical split?Lillianalillie
C-W v, C-W s. Here is a good answer vi.stackexchange.com/questions/3364/…Oxpecker
turns out it can be done very easily with let g:NERDTreeMapOpenSplit="<F3>".Lillianalillie
A
10

your mapping:

map <silent> <F2> NERDTreeToggle

should be:

map <F2> :NERDTreeToggle<CR>

I think you'll find that'll work (you basically missed the colon and the <CR> to make the action happen...

Abirritant answered 25/10, 2012 at 21:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.