Search code examples
vim

Mapping Alt + left|right to move tabs


Ideally, I'd like <A-left> to execute :tabmove -1 and <A-right> to execute :tabmove +1. However, when I put

nnoremap <A-left> :tabmove -1<cr>
nnoremap <A-right> :tabmove +1<cr>

in my .vimrc and try or , vim beeps and moves my cursor one character over in the direction I pressed. However, typing :tabmove -1<cr> directly into command mode gives the desired effect. How can I fix this? Thanks in advance.


Solution

  • Due to the way that the keyboard input is handled internally, this unfortunately isn't possible today in most terminals, but should work in GVIM. Some key combinations, like Ctrl + non-alphabetic cannot be mapped, and Ctrl + letter vs. Ctrl + Shift + letter cannot be distinguished. This is a known pain point, and the subject of various discussions on vim_dev and the #vim IRC channel.

    As a workaround, use different keys, e.g. <Leader><Left> / <Leader><Right>.