VIM Custom arrow key mappings not working with window switching?

醉酒当歌 提交于 2019-12-10 15:07:36

问题


I've been trying to create a shortcut for switching between open window splits in vim, rather than having to use ctrl+w+[arrowkey] I would prefer to just be able to use ctrl+[arrow keys].

This is what I currently have in my vimrc:

map <silent> <C-v> <c-w>v
map <silent> <C-Left> <c-w>h
map <silent> <C-Down> <c-w>j
map <silent> <C-Up> <c-w>k
map <silent> <C-Right> <c-w>l

The first shortcut for doing the vsplit works fine, however none of the others work. I've tried several variations of this and yet none of them do anything.

I'm using standard debian wheezy with KDE, vim is running from konsole and the only plugins I have installed are NERDTree and Airline.

I'm hoping someone can help provide a solution because I've been searching online for hours and trying hundreds of options and nothing seems to make any difference.

EDIT verbatim insert for the shortcuts doesn't output anything at all, neither in shell or vim.


回答1:


First, make sure that <C-Left> is not handled by konsole. Start a fresh one and use cat:

$ cat
^[[1;5D

That is how it should work for <C-Left>. Similar for other arrows. If <C-Left> doesn't work in such a way, search for "\e[1;5D": ... in /etc/inputrc and ~/.inputrc and comment it. You may have to log out and log in to get effect of these changes.

Next, use

:verbose map

in vim to display all mapped shortcuts and their source. You should see your bindings in this list. Your bindings are correct and all work in my case.




回答2:


try this:

nnoremap <C-DOWN> <C-W><C-J>
nnoremap <C-UP> <C-W><C-K>
nnoremap <C-RIGHT> <C-W><C-L>
nnoremap <C-LEFT> <C-W><C-H>


来源:https://stackoverflow.com/questions/21460514/vim-custom-arrow-key-mappings-not-working-with-window-switching

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