Toggle line or block comments on any code file in Neovim using gcc or gbc without leaving the editor.
Comment multiple lines or a visual selection at once using motion keys like gcip or gc2j.
Handle mixed-language files like HTML with embedded JavaScript by letting treesitter pick the right comment syntax automatically.
Requires Neovim, treesitter support for mixed-language files needs the nvim-treesitter plugin installed separately.
Comment.nvim is a plugin for the Neovim text editor that makes it easy to comment and uncomment lines or blocks of code using keyboard shortcuts, without leaving the editor. The plugin uses a keymap pattern familiar to Vim users. In normal mode, pressing gcc toggles a line comment on the current line, while gbc does the same with a block comment. A number prefix like 3gcc comments three lines at once. In visual mode, gc and gb comment whatever text is selected. Motion keys extend this further: gcip comments a whole paragraph, gc2j comments the next two lines below the cursor, and similar combinations let you target ranges of code using the same movement system as other Vim commands. Comment.nvim can detect the correct comment syntax for the file type you are editing using the commentstring setting. It also supports treesitter, a tool that parses code into a structured syntax tree. When a file mixes more than one language, such as a template file containing both HTML and JavaScript, treesitter support lets the plugin apply the right comment style for whichever language the cursor is currently inside. There are known limitations with JSX and TSX files. Two hook points called pre_hook and post_hook let users run custom Lua functions before or after the comment operation. These are useful for cases where the default behavior does not cover a particular comment style or integration need. The README includes an example showing how to wire in a companion plugin for better JSX comment handling. Configuration is done through a setup function call. Most options have sensible defaults and the full list is documented in the plugin's help file, accessible inside Neovim by running the help command. The plugin is written in Lua and supports installation through popular plugin managers including lazy.nvim, packer.nvim, and vim-plug.
← numtostr on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.