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.

  • 3
    Make sure KDE and the terminal emulator doesn't have shortcuts for `` – FDinoff Jan 30 '14 at 16:42
  • I've checked both, and neither use the c-arrow shortcuts I'm trying to use in vim. – historymaker118 Jan 30 '14 at 17:01
  • 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 [tag:shell] and in [tag:vim] and update your question with the output. – pfnuesel Jan 30 '14 at 18:01
  • 2
    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 h for "Move left" and so on, which adheres more to Vi principles. – DBedrenko Feb 14 '14 at 16:28
  • 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 v nmap h nmap j nmap k nmap l` – Kyle Challis Mar 18 '14 at 21:42

2 Answers2

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.

Andrey
  • 2,503
  • 3
  • 30
  • 39
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>
linusx
  • 306
  • 2
  • 10