Meta on Mac

165 views
Skip to first unread message

Haodong Du

unread,
Mar 6, 2021, 8:25:56 PM3/6/21
to vim_mac
Hi All,
I'm wondering if there is a way to enable meta key for vim on mac. I'm using it from terminal. I read an earlier post in the mail list about MavVim.app GUI. But I want to stick to the stock Vim. What I have found out working:

1. NeoVim works with <M-x> out of the box. Of course you need to turn on Meta emulation of your terminal.
2. Vim works with <M-n>-->˜ kind of mapping when turning meta emulation off.
3. Vim works with <ESC>n kind of mapping when turning meta emulation on.

So far, my best option seems to use <ESC>n types of mapping. But not sure if this kind of mapping works with linux or not. Also for plugins using Meta, I have to remap manually. I hope there are better options to have Meta natively on Mac.

Regards,
Haodong Du

Bailey Stoner

unread,
Mar 6, 2021, 8:33:12 PM3/6/21
to vim...@googlegroups.com
If you’re in the default terminal app, you’ll need to go to the keyboard settings and change option to meta instead of the default :)
--
--
You received this message from the "vim_mac" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_mac" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_mac+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_mac/7a504a47-a86e-43a9-b017-b3ed4ce5ede1n%40googlegroups.com.


Tony Mechelynck

unread,
Mar 6, 2021, 8:39:41 PM3/6/21
to vim_mac

I suggest a two-step solution:

map <Esc>x <M-x>  " IMPORTANT: do not use :noremap here
map <M-x> whatever

This way, for all the mappings thus defined, Esc and Meta will  be interpreted the same way. You may also want to set timeouts as follows:
'timeout'   (boolean) on
'timeoutlen' (milliseconds) slower than your slowest typing speed for the {lhs} of a single mapping
'ttimeoutlen' (milliseconds) faster than your fastest typing speed but slower than the interval between successive bytes sent by the system for a single keypress.

Best regards,
Tony.

Haodong Du

unread,
Mar 6, 2021, 8:50:52 PM3/6/21
to vim...@googlegroups.com
Thanks Bailey and Tony,

Turning on opt as Meta only sends a ESC before the character. Still, vim cannot recognize it as <M-x>. Instead <ESC>x mapping does work that way as I summarized.

A remapping of ESC to M- is what I just find in the fandom vim wiki. It appears to be working well. I don't quite understand why Vim developers chose not to enable this, since NeoVim seems to be recognizing ESC prefix as M-.
``
for i in range(97,122)
  let c = nr2char(i)
  exec "map \e".c." <M-".c.">"
  exec "map! \e".c." <M-".c.">"
endfor
``
Could you explain a bit about when I would need the timeout setting?  I'm using many combination keys with no issues so far.

Best regards,
Haodong Du

Haodong Du

unread,
Mar 6, 2021, 10:31:23 PM3/6/21
to vim...@googlegroups.com
Thanks Tony, I think I kinda understand why you mentioned setting timeout. With this setting, sometimes you get the upper-ed characters when you don't want it. Setting a timeout would help. TBH, this is not ideal. Thank you!

Best regards,
Haodong Du
Reply all
Reply to author
Forward
0 new messages