Reputation: 2542
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?
Upvotes: 52
Views: 19376
Reputation: 1011
Currently works well. I'm using vim 9.1 patch 1-650 in macOS Sonoma 14.5 M2 CPU.
Upvotes: 0
Reputation: 10247
Here is how you can do it regaining the selection if you are in visual mode:
nmap <C-_> <Plug>NERDCommenterToggle
vmap <C-_> <Plug>NERDCommenterToggle<CR>gv
Upvotes: 24
Reputation: 109
If you're using iTerm2 + vim, maybe the following steps can help you:
Add following code to your .vimrc
file.
map ,cc <plug>NERDCommenterToggle
or if you have defined your <leader> as ,
map <leader>cc <plug>NERDCommenterToggle
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.
Upvotes: 2
Reputation: 1181
Just to sum up the information from other answers. For me (there might be a difference due to the fact that I'm using neovim) <C-/>
works fine on Windows, but I need to use <C-_>
on Linux:
if has('win32')
nmap <C-/> <leader>c<Space>
vmap <C-/> <leader>c<Space>
else
nmap <C-_> <leader>c<Space>
vmap <C-_> <leader>c<Space>
endif
Upvotes: 4
Reputation: 17537
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 /
.
Upvotes: 74