Toggle between comment highlights and normal code view using tree-sitter grammars.
Normal Comments | Highlighted Comments |
---|---|
In most color schemes, comments are intentionally kept subtle. This is desirable in the normal modus operandi, i.e., when working in a well-known codebase. When exploring or skimming, however, comments can provide a valuable shortcut to understanding unfamiliar code. This plugin aims to help you switch between those mental modes.
- Neovim >= 0.9.1 (not tested on older versions but may also work)
nvim-treesitter
>= 0.9.0 (not tested on older versions but may also work)
Install with any package manager of your choosing, e.g. folke/lazy.nvim
:
{
"leon-richardt/comment-highlights.nvim",
dependencies = { "nvim-treesitter/nvim-treesitter" },
opts = {},
cmd = "CHToggle",
keys = {
{
"<leader>cc",
function() require("comment-highlights").toggle() end,
desc = "Toggle comment highlighting"
},
},
},
There are just a few options to configure, with the following defaults:
{
-- Base priority to render highlight groups with. The actual priorities
-- used by `comment-highlights.nvim` are derived from this value.
base_priority = 200,
}
The style of the backdrop and comments can be configured using the two highlight groups
CommentHighlightsBackdrop
(linked to theComment
highlight group per default) andCommentHighlightsComment
(linked to theSearch
highlight group per default).
The default value will be used if the respective highlight group is not already defined when the plugin is loaded. The groups can be set by the user or a color theme.
Example with custom highlight groups
{
"leon-richardt/comment-highlights.nvim",
dependencies = { "nvim-treesitter/nvim-treesitter" },
cmd = "CHToggle",
keys = {
{
"<leader>cc",
function() require("comment-highlights").toggle() end,
desc = "Toggle comment highlighting"
},
},
config = function()
vim.api.nvim_set_hl(0, "CommentHighlightsBackdrop", {
bg = "#424242",
fg = "#424242",
})
vim.api.nvim_set_hl(0, "CommentHighlightsComment", {
bg = "#FFFFFF",
fg = "#FF0000",
})
require("comment-highlights").setup()
end,
},
:CHToggle
: Toggle comment highlighting for the current bufferrequire("comment-highlights").enable()
: Enable comment highlighting for the current bufferrequire("comment-highlights").disable()
: Disable comment highlighting for the current bufferrequire("comment-highlights").toggle()
: Toggle comment highlighting for the current buffer
- ... to @stswed for the tree-sitter-comment grammar
- ... to @folke for letting me "borrow" his style of READMEs