Vim key mapping works in command editor, not in .vimrc - why?

▼魔方 西西 提交于 2019-12-24 00:55:43

问题


When I create the following key mapping via the command buffer it works as expected moving the cursor 5 lines down:

map ^[[1;3B 5<Down>

When I add it to my .vimrc file so that it works across sessions, pressing Alt+Down moves backwards 1 line (to somewhere not vertically above - maybe it's going to a previous sentence). My :map output is this:

0             ^
^[[1;3B       5<Down>
n  gx         <Plug>NetrwBrowseX
n  <Plug>NetrwBrowseX * :call netrw#NetrwBrowseX(expand("<cWORD>"),0)<CR>

Press ENTER or type command to continue

Why doesn't this vimrc mapping work similarly to what I type in the command buffer?

My version of vim is:

VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Jan 10 2014 00:22:49)
Included patches: 1-135
Compiled by <cygwin@cygwin.com>

UPDATE

There are 2 issues.

  1. my version of Vim doesn't understand map <M-Down> 5<Down> but does understand map <M-Down> 5j
  2. Something in my .vimrc file prevents map <M-Down> 5j from working. I had to put a bunch of hacks in to get "normal" vim behavior in my Cygwin environment:
"==================
" Keyboard trouble
"=================

" Every so often I am using a system that inserts a A, B, C, or D
" when using the arrow keys within the Vim editors insert mode.
" Vim is for VI Improved. While I did not dig into the exact reasons
" as to why (terminal emulation?) it happens, it is quite annoying.
set nocompatible
"set term=cons25

" This fixes Cygwin's vim's page up, home, end etc. keys
" http://superuser.com/questions/480215/
" how-to-map-pagedown-and-pageup-keys-to-function-normally
set term=mintty
set backspace=2 " backspace on Cygwin Windows Objy was not deleting properly. 
" But this doesn't solve other cursor movements like
"home and end
"source /home/sarnobat/.vim/cscope_maps.vim
"g:CCTreeCscopeDb = "/home/sarnobat/cscope/cscope.files"

"==============================
" Key bindings
"==============================
map 0 ^

回答1:


I don't understand those characters: ^[[1;3B. In vim you can choose the Alt key as letter M and the arrow letter as down, so:

map <M-down> 5<Down>

will work in either command-line and from your vimrc file.




回答2:


you could try the following:

map <M-down> 5j

Tried it on cygwin and it worked. hjkl is the preferred method of navigating left, down, up and right.



来源:https://stackoverflow.com/questions/22106741/vim-key-mapping-works-in-command-editor-not-in-vimrc-why

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!