4

On my previous setup, I used the following binding to move between my splits

nmap <silent> <A-Up> :wincmd k<CR>
nmap <silent> <A-Down> :wincmd j<CR>
nmap <silent> <A-Left> :wincmd h<CR>
nmap <silent> <A-Right> :wincmd l<CR>

Now I want to switch them to something more vim-like, using the 'hjkl' keys instead of the arrow pad. To do such, I mapped it like this :

nmap <silent> <A-k> :wincmd k<CR>
nmap <silent> <A-j> :wincmd j<CR>
nmap <silent> <A-h> :wincmd h<CR>
nmap <silent> <A-l> :wincmd l<CR>

But its not working.

Is there a specific thing to bind it to the alt key, or do I have to unbind it somewhere?

Thanks

4

Alt-key combos emit different things on different systems. One thing you can do is map the actual key code that your system emits. Instead of something like <A-K> enter Ctrl+V followed by Alt+K. On my system that appears as ë but has the desired effect when I do Alt-K in Normal mode.

Of course, if you copy your vimrc file to a different system it may not work there.

Important general tip: Unless you have a definitive need to do otherwise always use nnoremap rather than nmap (same for inoremap, cnoremap, etc.)

  • Is there a way I can see what my system emits on the Alt-key combo? – bl4ckb0ne Dec 16 '17 at 18:03
  • Create the mapping the way I suggest and you'll see. Most places in Vim where you can input text you can do Ctrl-V then the Alt key and you'll see. – B Layer Dec 16 '17 at 19:31
  • I ended up mapping my split nav on Ctrl-{hjkl}, and put the tab nav on Ctrl-{op}, thanks for the help – bl4ckb0ne Dec 19 '17 at 16:22
  • No problem. Were you able to get things working with Alt (even if you decided to use something else)? – B Layer Dec 19 '17 at 16:42
  • 1
    Hmm. Okay, well if you come back to it let me know...it should work. Also take a look at the update to my answer as it has an important general tip. – B Layer Dec 21 '17 at 15:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.