Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Neovim treesitter plugin for setting the commentstring based on the cursor location in a file.

License

NotificationsYou must be signed in to change notification settings

Imlimp/nvim-ts-context-commentstring

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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.

Demo gif

Getting started

Requirements:

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 atutils/minimal_init.lua for reference.

Note

Don't forget to use:h lua-heredoc if you're usinginit.vim.

Configuration

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:

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.

More demos

React:

React demo gif

Svelte:

Svelte demo gif

HTML:

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.

nested

About

Neovim treesitter plugin for setting the commentstring based on the cursor location in a file.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Lua97.1%
  • Shell2.9%

[8]ページ先頭

©2009-2025 Movatter.jp