Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to map <C-/> to toggle comments in vim?

Tags:

vim

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?

like image 732
dev_nut Avatar asked Jan 29 '12 08:01

dev_nut


People also ask

How do I toggle comments in vim?

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.

How to map control key in vim?

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.

What is C left in vim?

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.

What is the silent key in vim?

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

How do I toggle comments in Vim?

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.

How to uncomment and uncomment 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.

What is key mapping in Vim?

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.

How do I comment out a line in gvim?

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.


1 Answers

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

like image 138
mike3996 Avatar answered Oct 07 '22 08:10

mike3996