Skip to content

Linux terminal configurations for correct meta key handling

Michael Mior edited this page Apr 8, 2015 · 3 revisions

Ever wondered why your Alt+ key combinations are not working in your terminal? Chances are your terminal is in 7bit mode.

And that is exactly why you can't use Alt-p, Alt-P key combinations of YankStack (they are default mappings)

There is a ticket regarding this, if you want some background.

Hence, you have 3 options:

  • remap YankStack key bindings (more details is in the readme)
  • start terminal in 8bit mode (if that option available) for example rxvt --meta8
  • Ask vim to handle it by adding following piece of code into your .vimrc
set <m-p> = ^[p   " rotate yanks forward
set <m-P> = ^[P   " rotate yanks backward
" note that, the ^[ is an Esc char that comes before the 'p'
" In most default configurations, ^[p may be typed by pressing first <C-v>, then <M-p>

A more generic solution will be adding following to your .vimrc so that any other Alt key combinations will work:

" fix meta-keys which generate <Esc>a .. <Esc>z
let c='a'
while c <= 'z'
  exec "set <M-".toupper(c).">=\e".c
  exec "imap \e".c." <M-".toupper(c).">"
  let c = nr2char(1+char2nr(c))
endw

Above snippet is obtained from Vim Wikia. For more in-depth understanding of the problem and solution there of read Get Alt key to work in terminal and Fix meta keys that break out of inset mode

Clone this wiki locally