0

I am a newbie of Vim and I am using MacOS. In MacOS we usually use cmd and \ to comment the code block and I also want to achieve this in my Vim setting. Following to this post, I know how to modify the ~/.vimrc to comment different languages like C++ and Python. The remaining part is setting a shortcut key for commenting which I have no clue on that. Is it possible to set cmd and \ as a shortcut key for commenting in Vim? Or is it possible to use non-alphabetic symbols to form shortcut keys?

sweenish
  • 4,793
  • 3
  • 12
  • 23
Ricky Pang
  • 101
  • 3

1 Answers1

0

First…

In MacOS we usually use cmd and \ to comment the code block

No, this has very little to do with macOS. Beyond the basics like "open file", "copy", etc. what sequence or combination of keys does what is decided at the application level. The only OS-specific part, here, is the use of the command key but macOS editors/IDEs can use whatever they want (IntelliJ uses cmd+/, for example).

Second…

When Vim is executed in a terminal emulator on macOS, it is incapable of seeing the cmd key or any combination that includes the cmd key so you can forget about mapping anything to cmd+\ in that context.

When using the MacVim GUI, the cmd key can be used in mappings as <D-: cmd+\ would be <D-\>. While that would work in the MacVim GUI, I would advise against doing it because it is not portable.

dlmeetei
  • 9,905
  • 3
  • 31
  • 38
romainl
  • 186,200
  • 21
  • 280
  • 313