I want to map my F2
for nerdtree with the following entry:
map <F2> :NERDTreeToggle<CR>
But even before that, and after saving the vimrc , whenever i press F2
, it just 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.
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.
Creating a set of key bindings that is familiar, eases the learning curve of any new editor, and the flexibility vim allows in this configuration makes it easy to not only leverage the power of vim, but also make it feel like a familiar old friend.
1 Answer. Explanation: The map command lets us assign the undefined keys or reassign the defined ones so that when such a key is pressed, it expands to a command sequence.
xmap creates a mapping for just Visual mode whereas vmap creates one for both Visual mode and Select mode. As far as I understand, the intent of Select mode was to make Vim behave just like every other non-modal editor when text is selected, i.e., typing anything immediately replaces the selection with the typed text.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With