nipunlakshank / ts-comments.nvim

Tiny plugin to enhance Neovim's native comments

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

🚀 ts-comments.nvim

Tiny plugin to enhance Neovim's native comments:

  • Easily override the comment string for a given treesitter language
  • Supports different comment strings for different treesitter node types
  • Relaxed rules for uncommenting
  • Add proper whitespace when needed
  • Supports multiple commentstrings for the same language. The first one is used for adding comments. All are used for uncommenting.

⚡️ Requirements

  • Neovim >= 0.10.0

📦 Installation

Using lazy.nvim:

{
  "folke/ts-comments.nvim",
  opts = {},
  event = "VeryLazy",
  enabled = vim.fn.has("nvim-0.10.0") == 1,
}

⚙️ Configuration

ts-comments.nvim uses the default Neovim commentstring as a fallback, so there's no need to configure every language.

Default configuration:

{
  lang = {
    astro = "<!-- %s -->",
    c = "// %s",
    cpp = "// %s",
    css = "/* %s */",
    cue = "// %s",
    c_sharp = "// %s",
    gleam = "// %s",
    glimmer = "{{! %s }}",
    handlebars = "{{! %s }}",
    hcl = "# %s",
    html = "<!-- %s -->",
    ini = "; %s",
    javascript = {
      "// %s", -- default commentstring when no treesitter node matches
      "/* %s */",
      call_expression = "// %s", -- specific commentstring for call_expression
      jsx_attribute = "// %s",
      jsx_element = "{/* %s */}",
      jsx_fragment = "{/* %s */}",
      spread_element = "// %s",
      statement_block = "// %s",
    },
    lua = { "-- %s", "--- %s" }, -- langs can have multiple commentstrings
    php = "// %s",
    rego = "# %s",
    rescript = "// %s",
    rust = { "// %s", "/* %s */", "/// %s" },
    svelte = "<!-- %s -->",
    terraform = "# %s",
    tsx = {
      "// %s", -- default commentstring when no treesitter node matches
      "/* %s */",
      call_expression = "// %s", -- specific commentstring for call_expression
      jsx_attribute = "// %s",
      jsx_element = "{/* %s */}",
      jsx_fragment = "{/* %s */}",
      spread_element = "// %s",
      statement_block = "// %s",
    },
    twig = "{# %s #}",
    typescript = "// %s",
    vim = '" %s',
    vue = "<!-- %s -->",
  },
}

🔗 Related

About

Tiny plugin to enhance Neovim's native comments

License:Apache License 2.0


Languages

Language:Lua 98.1%Language:Shell 1.9%