All Projects → winston0410 → commented.nvim

winston0410 / commented.nvim

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

Programming Languages

lua
6591 projects
Vim Script
2826 projects

Projects that are alternatives of or similar to commented.nvim

cmp-tmux
Tmux completion source for nvim-cmp and nvim-compe
Stars: ✭ 98 (-10.91%)
Mutual labels:  neovim-plugin
skim.vim
vim support for skim
Stars: ✭ 127 (+15.45%)
Mutual labels:  neovim-plugin
AutoSave.nvim
🧶 Automatically save your changes in NeoVim
Stars: ✭ 349 (+217.27%)
Mutual labels:  neovim-plugin
auto-session
A small automated session manager for Neovim
Stars: ✭ 688 (+525.45%)
Mutual labels:  neovim-plugin
nvim-cheat.sh
cheat.sh integration for neovim in elegant way
Stars: ✭ 130 (+18.18%)
Mutual labels:  neovim-plugin
modes.nvim
Prismatic line decorations for the adventurous vim user
Stars: ✭ 299 (+171.82%)
Mutual labels:  neovim-plugin
ftFT.nvim
I love highlights! I love f{char}!
Stars: ✭ 28 (-74.55%)
Mutual labels:  neovim-plugin
gitabra
Magit-lite for neovim
Stars: ✭ 55 (-50%)
Mutual labels:  neovim-plugin
stable-windows
Keeps vim windows stable on layout changes
Stars: ✭ 41 (-62.73%)
Mutual labels:  neovim-plugin
buftabline.nvim
A low-config, minimalistic buffer tabline Neovim plugin written in Lua.
Stars: ✭ 74 (-32.73%)
Mutual labels:  neovim-plugin
nvim-config
My neovim config
Stars: ✭ 63 (-42.73%)
Mutual labels:  neovim-plugin
bad-practices.nvim
A plugin to help give up bad practices in vim.
Stars: ✭ 41 (-62.73%)
Mutual labels:  neovim-plugin
nvim-lsp-ts-utils
Utilities to improve the TypeScript development experience for Neovim's built-in LSP client.
Stars: ✭ 437 (+297.27%)
Mutual labels:  neovim-plugin
vim-readme-viewer
📖 Viewing plugin's README easily like vim help
Stars: ✭ 26 (-76.36%)
Mutual labels:  neovim-plugin
doctor.nvim
Emacs greatest feature, now also in neovim!
Stars: ✭ 27 (-75.45%)
Mutual labels:  neovim-plugin
package-info.nvim
✍️ All the npm/yarn commands I don't want to type
Stars: ✭ 248 (+125.45%)
Mutual labels:  neovim-plugin
persistence.nvim
💾 Simple session management for Neovim
Stars: ✭ 238 (+116.36%)
Mutual labels:  neovim-plugin
nvim-todoist.lua
Todoist plugin for Neovim in pure Lua, inspired by https://github.com/romgrk/todoist.nvim, which you should use instead
Stars: ✭ 22 (-80%)
Mutual labels:  neovim-plugin
iris.nvim
🌈 Generate color palettes based on Neovim colorschemes.
Stars: ✭ 45 (-59.09%)
Mutual labels:  neovim-plugin
trouble.nvim
🚦 A pretty diagnostics, references, telescope results, quickfix and location list to help you solve all the trouble your code is causing.
Stars: ✭ 2,663 (+2320.91%)
Mutual labels:  neovim-plugin

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].