I use vim under iterm2. I'm using the NERDCommenter plugin, and I'd like to use Ctrl+/ to toggle comments (Trying to switch from Idea/Eclipse to vim). This is my mapping in the .vimrc :
nmap <C-/> <leader>c<Space> vmap <C-/> <leader>c<Space>
But it doesn't seem to work. What can be the reason?
Go to first character on the first line you want to comment out. Hit Ctrl + q in GVIM or Ctrl + v in VIM, then go down to select first character on the lines to comment out. Then press c , and add the comment character.
On MS-Windows, if the mswin. vim file is used, then CTRL-V is mapped to paste text from the clipboard. In this case, you can use CTRL-Q or CTRL+SHIFT+V instead of CTRL-V to escape control characters. In the above command to enter a single ^V, you have to press Ctrl and v.
In vim, control-left and control-right are back and forward whitespace-separated word (i.e. synonyms for B and W), the same as web textareas and bash . But when running screen , these keys stop working. When pressed, vim instead switches to its command line and enters 5C or 5D there.
<silent> tells vim to show no message when this key sequence is used. <leader> means the key sequence starts with the character assigned to variable mapleader -- a backslash, if no let mapleader = statement has executed yet at the point nmap executes.
Check if you can use ,cc to toggle comments in vim. Open iTerm2 -> Preferences -> Keys, click the + button. Select Send Text with "vim" Special Chars, enter ,cc, like this. Now you can use C-/ to toggle comments in vim.
Once this is done, put the following in your vimrc : The mappings use Ctrl-A to comment and Ctrl-B to uncomment. Replace these with any convenient keys. To use it, just select the lines to comment by pressing V then moving the cursor up or down to select lines. Then, press Ctrl-A to comment. Similarly, you can uncomment them.
Key mapping refers to creating a shortcut for repeating a sequence of keys or commands. You can map keys to execute frequently used key sequences or to invoke an Ex command or to invoke a Vim function or to invoke external commands. Using key maps you can define your own Vim commands.
Hit Ctrl + q in GVIM or Ctrl + v in VIM, then go down to select first character on the lines to comment out. Then press c, and add the comment character. Uncommenting works the same way, just type a space instead of the comment character. c deletes the first character as well.
For some reason, vim registers <C-/>
as <C-_>
(you can see it in insert mode using <C-v><C-/>
). It can be the terminal or a historical design thing that terminal apps have to suffer.
And Gvim doesn't even try to recognize <C-/>
. Sees it as single /
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With