Always single line, comment sensitive, indentation preserving commenting.
Turn on notifications in Breaking Changes if using this plugin.
- Features
- Installation
- Keybindings
- Lazy load it Quickstart
-
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:
- uncomments only when all the text selected is commented, avoiding confusion when getting big blocks of code out of the way for debugging
- always comments at the most shallow comment to make maintaining different levels of commented code easier
- when you have block comments at the end of lines other plugins fail on the simple task of getting this line out of the way, this plugin should never fail
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
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
- with packer i did not test this, please inform me if it works :)
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
}
- with lazy:
{
"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,
},