Go to file
Stephen Seo edf814111b Minor fix to error printing 2022-11-22 14:24:08 +09:00
images Add gif for override feature demo 2022-11-03 15:28:06 +09:00
plugin Minor fix to error printing 2022-11-22 14:24:08 +09:00
LICENSE Add LICENSE 2022-11-03 13:10:39 +09:00
README.md Impl uncommenting with leading whitespace 2022-11-19 18:15:19 +09:00

README.md

NVim QuickComment

Quick comment demo

Quickly comment lines in a file with a single command.

Installation

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

Usage

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.

Overrides

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