- Notifications
You must be signed in to change notification settings - Fork0
Neovim treesitter plugin for setting the commentstring based on the cursor location in a file.
License
Imlimp/nvim-ts-context-commentstring
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A Neovim plugin for setting thecommentstring option based on the cursorlocation in the file. The location is checked via treesitter queries.
This is useful when there are embedded languages in certain types of files. Forexample, Vue files can have many different sections, each of which can have adifferent style for comments.
Note that this pluginonly changes thecommentstring setting. It does notadd any mappings for commenting. It is recommended to use a commenting pluginlikeComment.nvim alongside thisplugin.
Requirements:
- Neovim version 0.9.4
- Tree-sitter parsers (e.g. installed withnvim-treesitter)
Installation:
Use your favorite plugin manager. For example, here's how it would look likewithlazy.nvim:
require('lazy').setup {'JoosepAlviste/nvim-ts-context-commentstring',}
Setup:
For most commenting plugins, this is all you need and the defaults should workout of the box. However, some commenting plugins require a bit more set up. SeetheConfiguration section for more details about the differentplugins.
If you want to change the configuration, call thesetup function of thisplugin, e.g.:
require('ts_context_commentstring').setup {enable_autocmd=false,}
Note
There is a minimal configuration file available at
utils/minimal_init.luafor reference.
Note
Don't forget to use
:h lua-heredocif you're usinginit.vim.
It is recommended to use a commenting plugin that has an integration availablewith this plugin. Then, thecommentstring calculation can be triggered onlywhen commenting. The available integrations are listed in thewiki.The following plugins have an integration available:
- Native Neovim commenting
b3nj5m1n/kommentaryterrortylor/nvim-commentnumToStr/Comment.nvimechasnovski/mini.nvim/mini-commenttpope/vim-commentary
However, if an integration is not set up, then the default behavior is tocalculate thecommentstring on theCursorHold autocmd, meaning that the:h updatetime should be set to a smaller value than the default of 4s:
vim.opt.updatetime=100
Note
For more advanced configuration options, see
:h ts-context-commentstring.
React:
Svelte:
HTML:
Nesting:
I injected HTML into JavaScript strings and created multiple levels of nestingwith language tree. This sort of nesting of languages works without any extraconfiguration in the plugin.
About
Neovim treesitter plugin for setting the commentstring based on the cursor location in a file.
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Languages
- Lua97.1%
- Shell2.9%




