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.
Asked
Active
Viewed 3.5k times
34
-
2http://stackoverflow.com/a/9499124/2836621 – Mark Setchell Dec 06 '16 at 08:48
4 Answers
33

Goblinhack
- 2,859
- 1
- 26
- 26
-
3
-
2Send text with "vim" special Chars will also take vim key map style syntax, ie. "\
". The leading backslash is required, see https://iterm2-discuss.narkive.com/2T4MenGn/send-text-with-vim-special-chars-sends-literal-chars – Parker Ault Jul 21 '21 at 17:15
32
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>
.
4
With IdeaVim you can use: <M-*>
, for example <M-c>
means Cmd + c

Eduard Kolosovskyi
- 1,396
- 12
- 18
-
What does the * stand for? Could you go into a little more detail, thank you. – Serkan Sipahi Dec 28 '22 at 17:17
-
3
-
@SerkanSipahi yes, * stands for any key you want. `
` means Cmd + c. – Eduard Kolosovskyi Jan 29 '23 at 14:23
2
An example in iTerm 2 of mapping CMD+p to vim's Meta P to call :CtrlP command. This has the advantage that Meta is usually not used for anything so it won't clash with existing commands.
And on .vimrc you'd add
map <M-p> :CtrlP<CR>

Guillermo Siliceo Trueba
- 4,251
- 5
- 34
- 47
-
You forgot to mention that you are using Iterm2. Maybe mention that in bold ? Great answer. – Harsh Verma Mar 24 '23 at 22:19
-
Thanks for the suggestion, I updated the answer with that fact. – Guillermo Siliceo Trueba Mar 28 '23 at 16:16