{"id":13412954,"url":"https://github.com/terrortylor/nvim-comment","last_synced_at":"2025-03-14T19:30:40.931Z","repository":{"id":38300814,"uuid":"337338733","full_name":"terrortylor/nvim-comment","owner":"terrortylor","description":"A comment toggler for Neovim, written in Lua","archived":false,"fork":false,"pushed_at":"2024-05-29T18:47:23.000Z","size":39,"stargazers_count":473,"open_issues_count":14,"forks_count":22,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-07-31T20:51:42.494Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/terrortylor.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-02-09T08:28:40.000Z","updated_at":"2024-07-23T15:33:08.000Z","dependencies_parsed_at":"2024-10-26T08:36:41.858Z","dependency_job_id":"63d0b416-8a00-4279-9fd5-52a11c21c708","html_url":"https://github.com/terrortylor/nvim-comment","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/terrortylor%2Fnvim-comment","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/terrortylor%2Fnvim-comment/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/terrortylor%2Fnvim-comment/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/terrortylor%2Fnvim-comment/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/terrortylor","download_url":"https://codeload.github.com/terrortylor/nvim-comment/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243635198,"owners_count":20322896,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T20:01:31.553Z","updated_at":"2025-03-14T19:30:40.633Z","avatar_url":"https://github.com/terrortylor.png","language":"Lua","funding_links":[],"categories":["Editing Support","Lua"],"sub_categories":["Comment"],"readme":"# nvim-comment\n\nToggle comments in Neovim, using built in `commentstring` filetype option;\nwritten in Lua. Without a doubt this plugin **is not required** and is a rip off\nof [TPope's Commentary](https://github.com/tpope/vim-commentary) with less\nfeatures! What makes this plugin stand out over the numerous other comment\nplugins written in Lua are:\n\n- Comments each line, rather than adds block comments; making it easier to\n  toggle code when debugging\n- Uses the built in `commentstring` buffer option to define comment markers\n- Where a marker doesn't have a **space** character as padding this is added,\n  configurable (this can be disabled in the options, see below but is useful\n  when working with numerous linters)\n- Supports motions\n- Dot `.` repeatable\n\nWhen the plugin is called it works out the range to comment/uncomment; if all\nlines in the given range are commented then it uncomments, otherwise it comments\nthe range. This is useful when commenting a block out for testing with a real\nlike comment in it; as for the plugin a comment is a comment.\n\n## Usage\n\nEither use the command `CommentToggle`, e.g.:\n\n- `CommentToggle` comment/uncomment current line\n- `67,69CommentToggle` comment/uncomment a range\n- `'\u003c,'\u003eCommentToggle` comment/uncomment a visual selection\n\nOr use the default mappings:\n\n- `gcc` comment/uncomment current line, this does not take a count, if you want\n  a count use the `gc{count}{motion}`\n- `gc{motion}` comment/uncomment selection defined by a motion (as lines are\n  commented, any comment toggling actions will default to a linewise):\n  - `gcip` comment/uncomment a paragraph\n  - `gc4w` comment/uncomment current line\n  - `gc4j` comment/uncomment 4 lines below the current line\n  - `dic` delete comment block\n  - `gcic` uncomment commented block\n\n### Configure\n\nThe comment plugin needs to be initialised using:\n\n```lua\nrequire('nvim_comment').setup()\n```\n\nHowever you can pass in some config options, the defaults are:\n\n```lua\n{\n  -- Linters prefer comment and line to have a space in between markers\n  marker_padding = true,\n  -- should comment out empty or whitespace only lines\n  comment_empty = true,\n  -- trim empty comment whitespace\n  comment_empty_trim_whitespace = true,\n  -- Should key mappings be created\n  create_mappings = true,\n  -- Normal mode mapping left hand side\n  line_mapping = \"gcc\",\n  -- Visual/Operator mapping left hand side\n  operator_mapping = \"gc\",\n  -- text object mapping, comment chunk,,\n  comment_chunk_text_object = \"ic\",\n  -- Hook function to call before commenting takes place\n  hook = nil\n}\n```\n\n- Ignore Empty Lines\n\n```lua\nrequire('nvim_comment').setup({comment_empty = false})\n```\n\n- Don't trim trailing comment whitespace when commenting empty line\n```lua\nrequire('nvim_comment').setup({comment_empty_trim_whitespace = false})\n```\n\nThe default for this is `true`, meaning that a commented empty line will not\ncontain any whitespace. Most `commentstring` comment prefixes have some\nwhitespace padding, disable this to keep that padding on empty lines.\n\n- Disable mappings\n\n```lua\nrequire('nvim_comment').setup({create_mappings = false})\n```\n\n- Custom mappings\n\n```lua\nrequire('nvim_comment').setup({line_mapping = \"\u003cleader\u003ecl\", operator_mapping = \"\u003cleader\u003ec\", comment_chunk_text_object = \"ic\"})\n```\n\n- Disable marker padding\n\n```lua\nrequire('nvim_comment').setup({marker_padding = false})\n```\n\n- Hook function called before reading `commentstring`\n\nYou can run arbitrary function which will be called before plugin reads value of\n`commentstring`. This can be used to integrate with\n[JoosepAlviste/nvim-ts-context-commentstring](https://github.com/JoosepAlviste/nvim-ts-context-commentstring):\n\n```lua\nrequire('nvim_comment').setup({\n  hook = function()\n    if vim.api.nvim_buf_get_option(0, \"filetype\") == \"vue\" then\n      require(\"ts_context_commentstring.internal\").update_commentstring()\n    end\n  end\n})\n```\n\n- Changing/Setting `commentstring`\n\nIf you want to override the comment markers or add a new filetype just set the\n`commentstring` options:\n\n```lua\n-- Assumes this is being run in the context of the filetype...\nvim.api.nvim_buf_set_option(0, \"commentstring\", \"# %s\")\n```\n\nYou can also use an autocommand to automatically load your `commentstring` for\ncertain file types:\n\n```vim\n\" when you enter a (new) buffer\naugroup set-commentstring-ag\nautocmd!\nautocmd BufEnter *.cpp,*.h :lua vim.api.nvim_buf_set_option(0, \"commentstring\", \"// %s\")\n\" when you've changed the name of a file opened in a buffer, the file type may have changed\nautocmd BufFilePost *.cpp,*.h :lua vim.api.nvim_buf_set_option(0, \"commentstring\", \"// %s\")\naugroup END\n```\n\nOr add the comment string option in the relevant `filetype` file:\n\n```vim\nlet commentstring=\"# %s\"\n```\n\n```lua\nvim.api.nvim_buf_set_option(0, \"commentstring\", \"# %s\")\n```\n\n## Installation\n\nInstall just as you would a normal plugin, here are some options:\n\n### Built in package manager\n\n```bash\nmkdir -p ~/.local/share/nvim/site/pack/plugins/start\ncd ~/.local/share/nvim/site/pack/plugins/start\ngit clone https://github.com/terrortylor/nvim-comment\n```\n\n### Via a plugin manager\n\nUsing [packer.nvim](https://github.com/wbthomason/packer.nvim):\n\n```lua\nuse \"terrortylor/nvim-comment\"\nrequire('nvim_comment').setup()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fterrortylor%2Fnvim-comment","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fterrortylor%2Fnvim-comment","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fterrortylor%2Fnvim-comment/lists"}