Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to map mac command key in vim?

Tags:

vim

macos

I want to map my NERDTREE toggle to Cmd + space but I don't know what character represents Mac's command key in .vimrc. I searched and found that we can use 'D' to represent cmd key from this link, but it doesn't work. BTW I am using vim from the terminal not MacVim.

like image 874
UtkarshPramodGupta Avatar asked Dec 06 '16 07:12

UtkarshPramodGupta


People also ask

How to use command key in Vim?

Click the box next to "Keyboard Shortcut" and then press ⌘P – you should see it appear in the box. Then, choose the "Send Text with 'Vim' Special Characters" option from the "Action" dropdown. Then, simply type the Vim binding you want to map this key to, like \<C-p> or \<C-s> .

Does Mac have vim?

Vim is a free and powerful text editor that comes with your Mac.


2 Answers

iTerm2 can do this - here I mapped command enter to :wq

enter image description here

like image 99
Goblinhack Avatar answered Oct 04 '22 14:10

Goblinhack


It is true that <D- maps to command key. You can see it by :help <D-.

However, this will not work in your vim+terminal. It only works in MacVim. See here

The best shot for your intention is to map the combination as hex code, sending to terminal.

Still I will not recommend doing this. command is too important for mac os environment. For example, anyone uses an input method can't map it to command+space.\

Please consider using the usual method here: <leader>.

like image 29
halfelf Avatar answered Oct 04 '22 13:10

halfelf