I want to map my F2
for nerdtree with the following entry:
map :NERDTreeToggle
But even before that, and
Your problem is that vim does not know what does terminal emit when you press <F2>
. On some terminals it emits something like <Esc>[12~
, so the vim quits current mode (or just beeps if it can't) (<ESC>
), does nothing ([1
: there must be some key after [
, but not 1, so it does nothing) and changes case of two letters (2~
). So, you should open .vimrc and write there the following:
set <F2>=<C-v><F2>
where <C-v><F2> means that you must press <C-v>
and then <F2>
. This line should tell the Vim the exact sequence of codes which is emitted by terminal when you press <F2>
. After that, use noremap <F2> whatever
and it should work. If it is not the only terminal that you are using, then you may want to put if $TERM==#"<C-r>=$TERM<CR>"
before this line and endif
after.
:map <F2> :NERDTreeToggle<CR>
After starting Vim you can look with
:map <F2>
what F2 is mapped to. It is possible that the plugins change the mapping (not visible in .vimrc)