Giter Club home page Giter Club logo

nvim-ts-context-commentstring's Introduction

nvim-ts-context-commentstring

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 like Comment.nvim alongside this plugin.

Demo gif

Getting started

Requirements:

Installation:

Use your favorite plugin manager. For example, here's how it would look like with lazy.nvim:

require('lazy').setup {
  'JoosepAlviste/nvim-ts-context-commentstring',
}

Setup:

Defaults work out of the box.
Set 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.:

require('ts_context_commentstring').setup {
  enable_autocmd = false,
}

Note

There is a minimal configuration file available at utils/minimal_init.lua for reference.

Note

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

Configuration

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 wiki. The following plugins have an integration available:

However, if an integration is not set up, then the default behavior is to calculate the 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

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 nesting with language tree. This sort of nesting of languages works without any extra configuration in the plugin.

nested

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.