38

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.

1

4 Answers 4

35

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

35

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

enter image description here

2
6

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.

iTerm key config for CMD+p

And on .vimrc you'd add

map <M-p> :CtrlP<CR>
3
  • You forgot to mention that you are using Iterm2. Maybe mention that in bold ? Great answer. Mar 24, 2023 at 22:19
  • Thanks for the suggestion, I updated the answer with that fact. Mar 28, 2023 at 16:16
  • However command+P in MacOS is command for "Print" iterm2 also use it
    – Sebastian
    Jan 14 at 13:25
5

With IdeaVim you can use: <M-*>, for example <M-c> means Cmd + c

3
  • What does the * stand for? Could you go into a little more detail, thank you. Dec 28, 2022 at 17:17
  • 3
    I think it just means "any key you want"
    – awvalenti
    Jan 27, 2023 at 15:27
  • @SerkanSipahi yes, * stands for any key you want. <M-c> means Cmd + c. Jan 29, 2023 at 14:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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