I am unable to map <C-/> in Neovim. In particular, it does not work for visual mode. I have created the mappings below:

vim.keymap.set('i', '<C-/>', '<Esc>:Commentary<CR>')    
vim.keymap.set('n', '<C-/>', 'gcc')    
vim.keymap.set('v', '<C-/>', 'gc')

Using vim I have the mapping below, which works fine:

imap <C-_> <Esc>:Commentary<CR>
nmap <C-_> gcc
vmap <C-_> gc

But <C-_> also does not work for Neovim. I can also confirm using <C-V> <C-/> that Neovim indeed sees <C-/> and not <C-_> like vim.

I am aware of this question, but it seems Neovim has different behavior from vim.

Edit: I found out it is a problem with Kitty, other terminals do send <C-_>

1 Answer 1


Setting remap = true solves the issue.

vim.keymap.set('i', '<C-/>', '<Esc>:Commentary<CR>')
vim.keymap.set('n', '<C-/>', 'gcc', { remap = true })
vim.keymap.set('v', '<C-/>', 'gc',  { remap = true })
  • I tried to map gcc to another command and remap=true got it working, but I'm not clear why, can you expand? Oct 16, 2023 at 17:32
  • remap makes the mapping recursive. That is, it allows a mapping to call another mapping. By default, remap is set to false. Commentary has a default mapping for gcc. So, if remap = false, then we are prevented from mapping <C-/> to the existing mapping for gcc. It is worth noting that Neovim v0.10 now provides the defaults commenting functionality mapped to gc and gcc. Depending on your needs, Commentary may no longer be necessary. See github.com/neovim/neovim/blob/…
    – Mike
    May 17 at 13:13

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.