4

I'd like to bind some combinations to Alt-_some-key_, but not quite sure about how to do it correctly. Here is one of my current setup (example):

vnoremap <ESC>c "+y

This is because my terminal accept Alt-c as <ESC>c. But I suppose it's not portable.

Is there a way to specify some alias (like Alt) and set its meaning to ESC so I could change it in case I moved to another terminal?

statox
  • 49,782
  • 19
  • 148
  • 225
Dmitrii Bundin
  • 285
  • 1
  • 3
  • 7

2 Answers2

9

From :h keycodes and more precisely :h meta:

<M-...> alt-key or meta-key

So on most system the mapping you're looking for is:

vnoremap <M-c>  "+y

Note that the behavior of <M-...> may be dependent of your system and your terminal emulator if you use one.

statox
  • 49,782
  • 19
  • 148
  • 225
2

You could define a global variable containing the key that might change, and then use an execute normal! construct to setup your mapping.

For your example, that could be:

let g:MyAltKey = "<Esc>"
execute 'normal! :vnoremap ' . g:MyAltKey . 'c "+y' . "\r"

Also, you might consider using the <leader> or <localleader> constructs which serve a purpose similar to what you want (see :help leader).

Dalker
  • 455
  • 2
  • 10