You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Stephen Seo edf814111b Minor fix to error printing 6 months ago
images Add gif for override feature demo 7 months ago
plugin Minor fix to error printing 6 months ago
LICENSE Add LICENSE 7 months ago Impl uncommenting with leading whitespace 6 months ago

NVim QuickComment

Quick comment demo

Quickly comment lines in a file with a single command.


Create the directory structure ${HOME}/.config/nvim/pack/plugins/start/ and place nvim-quickcomment/ in start/, or use a plugin manager.


Add the following to your init.lua (replace "q" with the key you want to map to):

vim.cmd('nmap q :lua vim.g.quickcomment_togglecommentline()<CR>')
vim.cmd('vmap q :luado vim.g.quickcomment_togglecommentline(linenr)<CR>')

Or in init.vim:

nmap q :lua vim.g.quickcomment_togglecommentline()<CR>
vmap q :luado vim.g.quickcomment_togglecommentline(linenr)<CR>

Whitespace before comment string

If b:quickcomment_whitespaceprefix or g:quickcomment_whitespaceprefix is set to true, then quickcomment will uncomment comments with leading whitespace.

In init.vim this option can be set globally with:

let g:quickcomment_whitespaceprefix = 1

or locally with:

let b:quickcomment_whitespaceprefix = 1

Or in init.lua set this option with:

vim.g.quickcomment_whitespaceprefix = true
vim.b.quickcomment_whitespaceprefix = true

The b (local) variant holds precendence over the g (global) variant.


Say you want to use // to comment lines in C files instead of /* ... */.
Set an override string like the following:

let b:quickcomment_commentstring_override = '// %s'

This will override how the comment is set for the current buffer.
It can also be set globally:

let g:quickcomment_commentstring_override = '/* a comment: %s */'

Note that b:quickcomment_... has precedence over g:quickcomment_.... Also note that %s must be in the override commentstring which denotes where the line content is relative to the comment symbols.

Quick comment override demo