a simple lua script to help you comment and uncomment faster
- Single line comment/uncomment
- Visual mode multi-line comment/uncomment
- True block comment support (e.g.
/* */,--[[ ]],""" """) - Automatic selection of block vs line comments based on a configurable line threshold
- Detecting languages and using the correct comment sign
- Remapable keymap shortcuts available
Plug 'EvgeniGenchev/comment-nvim'use({
'EvgeniGenchev/comment-nvim',
})-- include the package in your init.lua
require('comment').setup()You can change the shortcuts of the commands.
-- Change the default singleline comment shortcut
vim.api.nvim_set_keymap('n', '?', ':Comment<CR>', {noremap=true, silent=false})
-- Change the visual mode multiline comment shortcut
vim.api.nvim_set_keymap('v', '?', ':CommentMore<CR>', {noremap=true, silent=false})You can add languages or override existing ones in init.lua. Each language takes a { single, multi } pair where single is the single-line comment prefix and multi is a { open, close } pair for block comments. Use nil if a style is not supported by the language.
require('comment').setup({
languages = {
sh = { "#", nil },
zsh = { "#", nil },
php = { "//", { "/*", "*/" } },
java = { "//", { "/*", "*/" } },
css = { nil, { "/*", "*/" } },
},
})You can also configure the threshold which is the minimum number of selected lines at which block comment syntax is used instead of line-by-line comments. Defaults to 4.
require('comment').setup({
threshold = 5,
})- add support for spaces
- add support for multiline comment signs
- per-language threshold configuration
Copyright © 2023-present EvgeniGenchev
