4

I try to create a mapping for Alt < and Alt >:

inoremap <M-<> foo-bar-baz
inoremap <M->> baz-bar-foo

This doesn't work, most probably because < and > are themselves characters used to define the mapping. So, how can I create such a mapping?

Vivian De Smedt
  • 16,336
  • 3
  • 18
  • 37
René Nyffenegger
  • 2,105
  • 20
  • 36

1 Answers1

3

As said in my comment, the <Alt-X> combination insert a special character. So instead of mapping to <Alt-X>, you can map it to the special character.

So

inoremap <M-<> foo-bar-baz
inoremap <M->> baz-bar-foo

becomes

inoremap ¯ foo-bar-baz
inoremap ˘ baz-bar-foo

Note : This was working on a Mac, on iterm2, tmux and macvim. The behaviour may change depending the configuration ...

Edit : You can look at those posts :

nobe4
  • 16,033
  • 4
  • 48
  • 81
  • 2
    FYI, with xterm on Linux I get 0x1b 0x3e and 0x1b 0x3c With Alt+< and Alt+> (in other words, I get the expected Esc+key, instead of the MACRON and BREVE characters). – Martin Tournoij Aug 13 '15 at 09:00
  • @Carpetsmoker Depending on your keyboard settings, you may need to use to type those letters. And you can also map them. With ALTGR i get 'ł€¶ŧ←↓→øþæßðđŋħł«»¢“”nµ·' (and others) that I can map to vim goodness. I can also get ' ̈́' but have managed to type UpperBar yet. – Alex Stragies Aug 13 '15 at 20:07
  • 1
    @AlexStragies AltGr and Alt are different keys. Alt+character sends ESC followed by that character on most terminals, translated from the Alt+key keychord by the terminal emulator. AltGr+character inserts a different character which depends on the keyboard layout and is managed by the OS/GUI environment, not by the terminal emulator. – Gilles 'SO- stop being evil' Aug 13 '15 at 22:19
  • @Gilles, I was aware of the ability to (exit Insert Mode+) with ALT-CMDKEY, because it sends . I was trying to point out how to get many mappable characters with ALTGR. For me the 2 Keys from the OP example require ALTGR – Alex Stragies Aug 13 '15 at 22:38