Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I map Alt Gr key combinations in vim?

Suppose I wanted to map the command :!python % <ENTER> to pressing the keys Alt Gr and j together?

like image 524
Bentley4 Avatar asked May 25 '12 09:05

Bentley4


2 Answers

AltGr is interpreted by your keyboard driver, so Vim isn't aware of it in terms of a modifier key. However, there are two ways getting the key code for AltGr-j. In insert mode:

  1. press Ctrl-v and then AltGr-j (shows the literal character code)
  2. hold down Ctrl-v, press AltGr-j and then release Ctrl-v (shows the terminal code)

The result depends on your keyboard layout. If you just get j then you're out of luck.

like image 103
Stefan Avatar answered Sep 30 '22 04:09

Stefan


Due to the way that the keyboard input is handled internally, many key combinations cannot be used, even in GVIM. This is a known pain point, and the subject of various discussions on vim_dev and the #vim IRC channel.

A basic rule is: If the key combination yields a visible character in command-line mode, it can be mapped. But in particular for AltGr, it may be the same mapping as Alt, depending on what your OS returns when it's combined with the other key.

Some people (foremost Paul LeoNerd Evans) want to fix that (even for console Vim in terminals that support this), and have floated various proposals, cp. http://groups.google.com/group/vim_dev/browse_thread/thread/626e83fa4588b32a/bfbcb22f37a8a1f8

But as of today, no patches or volunteers have yet come forward, though many have expressed a desire to have this in a future Vim 8 major release.

like image 41
Ingo Karkat Avatar answered Sep 30 '22 03:09

Ingo Karkat