2

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?

6

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.

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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.