VIM Custom arrow key mappings not working with window switching?
Asked Answered
C

2

7

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.

Clio answered 30/1, 2014 at 15:25 Comment(5)
Make sure KDE and the terminal emulator doesn't have shortcuts for <c-arrow>Catachresis
I've checked both, and neither use the c-arrow shortcuts I'm trying to use in vim.Clio
You can try using verbatim insert to get some insights: Type Ctrl+v and then e.g. Ctrl+up, to see the key codes. Please do that in the shell and in vim and update your question with the output.Disordered
I'm thinking that Ctrl+Arrow doesn't register in all terminal emulators. Try it in xterm and also in the console you get by pressing Ctrl+Alt+F1 and report back. Otherwise, consider using the leader-key instead of Ctrl. I have <leader>h for "Move left" and so on, which adheres more to Vi principles.Joiner
I tried copying your config options into my .vimrc, but my OS already had keyboard shortcuts that overrode it. I'm using Ubuntu with XFCE. I changed the commands a bit, and they work now with Ctrl-(hjkl). It's not exactly what you wanted, but maybe this will help somehow in your search: nmap <silent> <C-v> <c-w>v nmap <silent> <C-h> <c-w>h nmap <silent> <C-j> <c-w>j nmap <silent> <C-k> <c-w>k nmap <silent> <C-l> <c-w>lRoturier
K
2

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.

Kayleen answered 9/4, 2014 at 19:51 Comment(0)
G
0

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>
Guibert answered 20/7, 2014 at 23:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.