In case it's relevant, this is on MacOS and iTerm.

How do I use key mappings that involve the Meta key, e.g. <M-e>?

For example, the auto-pairs plugin has a keybinding that allows you to convert (|)foo to (foo) by pressing <M-e>, where | represents cursor position.

In iTerm > Preferences > Profiles > Keys, I have the following options selected:

enter image description here

So whenever I pressed <M-e>, the behavior becomes <Esc>e. Note that changing the options to Normal or Meta in iTerm did not fix this issue.

In the end, I was only able to get this plugin command to work by adding the following to my .vimrc: set <M-e>=^[e, where ^[ is the escape literal achieved by pressing Ctrl-v followed by Esc.

In general, this is far from an ideal solution, since I'd having to manually set every single mapping involving Meta.

So my question is: how can I get all keybindings involving the Meta key to perform as expected, without needing to manually remap each individual instance?

  • 2
    Meta behavior is not ideal in case you are using vim in terminal. Terminal emulators handle meta keys two ways, mostly using <Esc>. So, if you are using vim in a terminal emulator that is not supporting meta by default, you should not use meta. Otherwise you can adopt something that tpope did in vim-rsi plugin. – klaus Apr 6 '19 at 8:55

Your Answer

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

Browse other questions tagged or ask your own question.