Neovim plugin to comment out/in a text written in lua. Support comment out a single line, a visual selection and a motion.
- Neovim 0.5+
use 'shoukoo/commentary.nvim'
Plug 'shoukoo/commentary.nvim'
The default keybindings are the same as in vim-commentary, meaning your can use the following keybindings
gcc
to comment out a single line,gc
to comment out a visual selectiongc<motion>
to commentout with a motion i.e.gc5j
If you don't like the default mappings, set use_default_mappings
to false in init.lua/vimrc
require("commentary").setup({
use_default_mappings = false
})
You can also bind your own keys. Insert the following lines into your init.lua
and replace <your key>
with the valid keys.
vim.api.nvim_set_keymap("x", "<your key>", "<Plug>commentary", { silent = true })
vim.api.nvim_set_keymap("n", "<your key>", "<Plug>commentary", { silent = true })
vim.api.nvim_set_keymap("n", "<your key>", "<Plug>commentary_motion", { silent = true })
Currently, this plugin only supports a few languages, feel free to create a PR and add them in here. Otherwise, you can also pass them into the setup function like this:
require("commentary").setup({languages=
{
go = {single_line_comment = "//", multiline_comment = {"/*", "*/"}, prefer_multiline = true}
typescript = {single_line_comment = "//", multiline_comment = {"/**", "*/"}, prefer_mutiline = true}
}
})