• Stars
    star
    112
  • Rank 305,073 (Top 7 %)
  • Language
    Lua
  • License
    MIT License
  • Created about 3 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Neovim commenting plugin in Lua. Support operator, motions and more than 60 languages! 🔥

commented.nvim

A commenting plugin written in Lua that actually works.

This plugin uses commentstring and custom comment definition for accurately comment and uncomment code.

normal mode demo

Latest features

Codetags (6-10-2021)

Use commented.nvim to toggle a comment with code tag. You can check all existing codetags here, PR welcomed.

vim.api.nvim_set_keymap(
	"n",
	"<leader>ff",
	"v:lua.require'commented'.codetags.fixme_line()",
	{ expr = true, silent = true, noremap = true }
)

No default is provided for the codetags binding. You can enable them like this or map them manually with vim.api.nvim_set_keymap. The key in codetags_keybindings has to match the key in codetags table:

-- packer.nvim example
use({
    "winston0410/commented.nvim",
    config = function()
        require("commented").setup({
            codetags_keybindings = {
                fixme = "<leader>f",
                fixme_line = "<leader>ff",
                todo = "<leader>t",
                todo_line = "<leader>tt",
                bug = "<leader>b",
                bug_line = "<leader>bb",
                note = "<leader>n",
                note_line = "<leader>nn",
                wont_fix = "<leader>w",
                wont_fix_line = "<leader>ww",
            },
        })
    end,
})

You can also create a custom tag, using commented function:

local foo = function()
    return commented("bar")
end
vim.api.nvim_set_keymap(
	"n",
	"<leader>d",
	"v:lua.require'filename'.foo()",
	{ expr = true, silent = true, noremap = true }
)

Features

  • Provide sensible comment symbols default for as much language as possible (Always a WIP, 50+ right now)

  • Handle multi-line block comment, both commenting and uncommenting

  • Commenting lines in normal mode and visual line mode

  • Support counts for commenting in normal mode (e.g. 2<leader>c2j, 3<leader>cc)

  • Toggleable commenting command

  • Handle uncommenting multiple comment patterns(inline and block comment) correctly

  • Handle comments with various spacing correctly

  • Comment ex-mode command that handles range included

  • Provide the correct commentstring for filetype not handled by neovim initially

  • Integrate with any plugin that dynamically switch cms based on embedded languages

Demo

Commenting in normal mode with count

normal mode demo

Commenting in visual line mode

visual-mode-demo

Uncommenting both inline and block comment

various comment patterns

Why another comment plugin?

I need a comment plugin that works in normal mode and virtual mode and accepts count. Neither does kommentary and nvim-comment provide counts, therefore I decided to write one for myself.

Installation

Paq.nvim

paq{'winston0410/commented.nvim'}

vim-plug

Plug 'winston0410/commented.nvim'

packer.nvim

Do not set this plugin as optional, as sensible default has been made with ftplugin

use{'winston0410/commented.nvim'}

Configuration

This is the default configuration.

local opts = {
	comment_padding = " ", -- padding between starting and ending comment symbols
	keybindings = {n = "<leader>c", v = "<leader>c", nl = "<leader>cc"}, -- what key to toggle comment, nl is for mapping <leader>c$, just like dd for d
	prefer_block_comment = false, -- Set it to true to automatically use block comment when multiple lines are selected
	set_keybindings = true, -- whether or not keybinding is set on setup
	ex_mode_cmd = "Comment" -- command for commenting in ex-mode, set it null to not set the command initially.
}

You can define your own mapping with require('commented').toggle_comment(mode)

If you are happy with it, just call setup() to make it start working.

require('commented').setup()

Doesn't work for the language I use

If this plugin doesn't work for the language you use, you can contribute and add those symbols here for that language. The key for the pattern doesn't matter.

Integration

This plugin integrates with those that change commentstring dynamically in two ways. Using nvim-ts-context-commentstring as an example:

You could use an autocommand to dynamically set the commentstring:

require'nvim-treesitter.configs'.setup {
  context_commentstring = {
    enable = true,
    -- This plugin provided an autocommand option
    enable_autocmd = true,
  }
}

But this will depends on updatetime, which may be slow. Another approach is to use hook, which is faster and doesn't depend on updatetime:

require("commented").setup({
    hooks = {
        before_comment = require("ts_context_commentstring.internal").update_commentstring,
    },
})

Inspiration

kommentary

nvim-comment

More Repositories

1

range-highlight.nvim

An extremely lightweight plugin (~ 120loc) that hightlights ranges you have entered in commandline.
Lua
193
star
2

mark-radar.nvim

Lua
34
star
3

glory-svelte-preprocess

A svelte preprocess for safely minimizing CSS class footprint for unbeliveable performance gain. 🚀 🚀 🚀
JavaScript
23
star
4

glory

The world fastest framework agonistic CSS-in-JS library. Available in any frontend framework you use, like React, Vue and Svelte.
JavaScript
22
star
5

mkNodePackage

A helper flake for building Node.js package easily with Nix.
Nix
10
star
6

smart-cursor.nvim

Auto-indenting your cursor with treesitter
Lua
10
star
7

freedom-editor

Freedom Editor is a lightweight, fully extensible, zero-dependencies, framework agonistic block editor.
JavaScript
10
star
8

postcss-rfs-autopilot

A PostCSS plugin that will auto markup your CSS with rfs() for RFS
JavaScript
9
star
9

nixos-dotfiles

My dotfiles for NixOS, acting as a client for my multiple flakes structure.
Nix
8
star
10

cmd-parser.nvim

A command-line parser for neovim for plugin authors.
Lua
8
star
11

better-O.nvim

A plugin that insert newline better than the default O.
Lua
6
star
12

postcss-sparrow-auto-content-visibility

A PostCSS plugin that helps you add the new experimental CSS declaration, content-visibility: auto to any selectors with display: none for boosting render performance.
JavaScript
6
star
13

xdg.nix

A flake to make your system XDG compliance.
Nix
5
star
14

tree-sitter-hjson

Treesitter grammar for hjson.
C
4
star
15

bevy-nixos

Rust
3
star
16

ramda-dom-utilities

An utility library that enables currying and piping for DOM manipulation functions with Ramda
JavaScript
3
star
17

neovim-dotfiles

Lua
3
star
18

old-dotfiles

Lua
2
star
19

snowpack-plugin-prefetch-data

A plugin to help you save API response as JSON during `snowpack build`.
JavaScript
2
star
20

sparrow

A PostCSS plugin that helps you remove, replace, append or prepend CSS declarations without the need of writing another PostCSS plugin
JavaScript
2
star
21

bewater

A PostCSS plugin that helps you automatically apply `clamp()` to values to achieve a fluid design efficently.
JavaScript
2
star
22

svelte-use-resize-observer

A simple svelte action for using `ResizeObserver`.
TypeScript
1
star
23

ogs-client

OGS Client for arranging games easily.
Svelte
1
star
24

ory-flake

Nix
1
star
25

limelight.nvim

Lua
1
star
26

jyut.info

1
star
27

fastify-mongo-example

TypeScript
1
star
28

postcss-sparrow-props-filter

A PostCSS Sparrow plugin that helps you search CSS declarations by properties.
JavaScript
1
star
29

universal-dotfiles

My stateful universal dotfiles, sharing configuration across platforms through Nix Flake.
Lua
1
star
30

fix-hash

JavaScript
1
star
31

buf-num-nav.nvim

Navigate buffers in neovim like in tmux with numbers.
Lua
1
star
32

better-fastify-405

A better plugin for handling 405 in Fastify.
TypeScript
1
star
33

svelte-glory

SCSS
1
star
34

atom-setting

Less
1
star
35

suitcase.nvim

Lua
1
star
36

portfolio-2021

My portfolio site! Built with SvelteKit, PostCSS.
Svelte
1
star