A Neovim plugin for setting the
commentstring option based on the cursor
location in the file. The location is checked via treesitter queries.
This is useful when there are embedded languages in certain types of files. For example, Vue files can have many different sections, each of which can have a different style for comments.
Note that this plugin only changes the
commentstring setting. It does not
add any mappings for commenting. It is recommended to use a commenting plugin
Comment.nvim alongside this
Use your favorite plugin manager. For example, here's how it would look like with lazy.nvim:
Defaults work out of the box.
vim.g.skip_ts_context_commentstring_module = true somewhere in your configuration to skip backwards compatibility routines and speed up loading.
If you want to change the configuration, call the
setup function of this plugin, e.g.:
enable_autocmd = false,
There is a minimal configuration file available at
Don't forget to use
:h lua-heredocif you're using
It is recommended to use a commenting plugin that has an integration available
with this plugin. Then, the
commentstring calculation can be triggered only
when commenting. The available integrations are listed in the
The following plugins have an integration available:
However, if an integration is not set up, then the default behavior is to
commentstring on the
CursorHold autocmd, meaning that the
:h updatetime should be set to a smaller value than the default of 4s:
vim.opt.updatetime = 100
For more advanced configuration options, see