tags:

views:

58

answers:

2

I want to map my f2 for nerdtree with the following entry. map :NERDTreeToggle But even before that , and after saving the vimrc , whenever i press f2 , it jus switches the case of the letters on which the cursor is present. Later found out that any function key does it.f5 switches case of 5 characters and so on.Is this because of some other plugin?i presently use c.vim , snippetsEmu , surround , nerdtree , and minibufexpl there are no keymappings to any function key in my vimrc.

+1  A: 
: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)

michael.kebe
i tried that.. it says no mapping found.btb, for specifying F2 , u hav to press "F" and "2" right? or do we hav to use ctrl+v?i tried both..still not working.Also I am using SSH Secure Shell Client to login to a FreeBSD server.
MIkhail
You could try loading vim without any set upgvim -u NONE -U NONE -Nthen in insert mode see what happens when you press the function keys should insert <f2>.Then Try mapping something simpler to f2 eg:map <f2> "+yy (yank current line to paste buffer)Also can you map any function key?(yes you do type f and 2)
zzapper
Also type to see what and where f2 thinks it is set to:verbose map <f2>
zzapper
f2 verbose showed not mappings. and i tried running vim without any setup.f2 is still behaving wierd.mapping something similar is not working either.i do feel it is some problem with my linux machine , since in my home laptop , function key mappings were working fine. i jus dont know how to figure out wat is wrong. :(
MIkhail
@Mlkhail Have you seen my explanation of this behavior?
ZyX
+3  A: 

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.

ZyX
@Mlkhail Have you read what I have written?
ZyX
oops. I missed the top part last time.it is working now.Thanx.also , wat does noremap do?
MIkhail
@Mlkhail Like `map`, but prevents using other user mappings. For example, if you have `imap a b` and `imap b c`, then pressing `a` will result in `c`. If you have `inoremap a b` then pressing `a` will result in `b` no matter whether `b` is remapped or not. I recommend never use `?map` unless you do know that you need remapping (for example, with `<Plug>` mappings).
ZyX
@Zyx , thanx a lot :) f2 is up and running.
MIkhail
one more thing.now , i hav set <F2>=(Press)(C-V)<F2>. can i generalise the command for all function keys in one command (using some parameter), or do i hav to give them separately?
MIkhail
@Mlkhail Only separately. You can automate that using `:while` and `:execute`, but you have to be sure that this is correct. In most of my terminal emulators the result of pressing `<F1>`-`<F4>` is slightly different from the result of pressing `<F5>`-....
ZyX