Always single line, comment sensitive, indentation preserving commenting.
Turn on notifications in Breaking Changes if using this plugin.
Simple and stupid, just complain and i will change some lua tables around and we are ready to work
Supports
Simplest of them all ~270 loc in a single file
It uses nvim-ts-context-commentstring automatically if available them tries to turn all results into line comments
Single line comments avoid unexpected results when commenting:
use {
"lucastavaresa/SingleComment.nvim",
}
{
"lucastavaresa/SingleComment.nvim",
}
There is no keybindings by default.
Those are all the available functions:
-- comments the current line, or a number of lines 5gcc
vim.keymap.set("n", "gcc", require("SingleComment").SingleComment, { expr = true })
-- comments the selected lines
vim.keymap.set("v", "gcc", require("SingleComment").Comment, {})
-- toggle a comment top/ahead of the current line
vim.keymap.set("n", "gca", require("SingleComment").ToggleCommentAhead, {})
-- comments ahead of the current line
vim.keymap.set("n", "gcA", require("SingleComment").CommentAhead, {})
-- comment a block, and removes the innermost block comment in normal mode
vim.keymap.set({ "n", "v" }, "gcb", require("SingleComment").BlockComment)
Get a table with comment beginning and end
Improved by ts-context-commentstring but also works without it automatically, them gets single-lined/tweaked by this plugin custom tables
Also updates the commentstring
Useful for custom utility functions that need accurate comment detection
-- you can pass "block", and it will *try* to get block comments
local comment = require("SingleComment").GetComment()
Those commands substitute all the above
use {
"lucastavaresa/SingleComment.nvim",
opt = true,
keybindings = { { { "n", "v" }, "gcc" }, { "n", "gca" } },
requires = {
"nvim-treesitter/nvim-treesitter",
"JoosepAlviste/nvim-ts-context-commentstring"
},
setup = function()
vim.keymap.set(
"n",
"gcc",
require("SingleComment").SingleComment,
{ expr = true }
)
vim.keymap.set("v", "gcc", require("SingleComment").Comment, {})
vim.keymap.set("n", "gca", require("SingleComment").ToggleCommentAhead, {})
vim.keymap.set("n", "gcA", require("SingleComment").CommentAhead, {})
vim.keymap.set({ "n", "v" }, "gcb", require("SingleComment").BlockComment)
end
}
{
"lucastavaresa/SingleComment.nvim",
lazy = true,
dependencies = {
"nvim-treesitter/nvim-treesitter",
"JoosepAlviste/nvim-ts-context-commentstring"
},
init = function()
vim.keymap.set("n", "gcc", require("SingleComment").SingleComment, { expr = true })
vim.keymap.set("v", "gcc", require("SingleComment").Comment, {})
vim.keymap.set("n", "gca", require("SingleComment").ToggleCommentAhead, {})
vim.keymap.set("n", "gcA", require("SingleComment").CommentAhead, {})
vim.keymap.set({ "n", "v" }, "gcb", require("SingleComment").BlockComment)
end,
},