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

Rainbow delimiters for Neovim with Tree-sitter

License

NotificationsYou must be signed in to change notification settings

HiPhish/rainbow-delimiters.nvim

Repository files navigation

This Neovim plugin provides alternating syntax highlighting (“rainbowparentheses”) for Neovim, powered byTree-sitter. The goal is to have ahackable plugin which allows for different configuration of queries andstrategies, both globally and per file type. Users can override and extend thebuilt-in defaults through their own configuration.

This is a fork ofnvim-ts-rainbow2, which was implemented as a module fornvim-treessiter. However, since nvim-treesitter has deprecated the modulesystem I had to create this standalone plugin.

Installation and setup

Installation

Install it like any other Neovim plugin; you do not need the Git submodules ofthis repository. They are just used for development and won't cause any harm,they will just bloat your setup.

You will need a Tree-sitter parser for each language you want to use rainbowdelimiters with.

Setup

No configuration is needed to get started, this plugin has reasonable defaultswhich you can override. Configuration is done by setting entries in the Vimscript dictionaryg:rainbow_delimiters. Here is an example configuration:

letg:rainbow_delimiters= {\'strategy': {\'':'rainbow-delimiters.strategy.global',\'vim':'rainbow-delimiters.strategy.local'\},\'query': {\'':'rainbow-delimiters',\'lua':'rainbow-blocks',\},\'priority': {\'':110,\'lua':210,\},\'highlight': [\'RainbowDelimiterRed',\'RainbowDelimiterYellow',\'RainbowDelimiterBlue',\'RainbowDelimiterOrange',\'RainbowDelimiterGreen',\'RainbowDelimiterViolet',\'RainbowDelimiterCyan',\],\}

The equivalent code in Lua:

---@typerainbow_delimiters.configvim.g.rainbow_delimiters= {strategy= {        ['']='rainbow-delimiters.strategy.global',vim='rainbow-delimiters.strategy.local',    },query= {        ['']='rainbow-delimiters',lua='rainbow-blocks',    },priority= {        ['']=110,lua=210,    },highlight= {'RainbowDelimiterRed','RainbowDelimiterYellow','RainbowDelimiterBlue','RainbowDelimiterOrange','RainbowDelimiterGreen','RainbowDelimiterViolet','RainbowDelimiterCyan',    },}

Please refer to themanual for more details. For those who prefer asetupfunction there is the modulerainbow-delimiters.setup that accepts all thesame parameters asg:rainbow-delimiters.

require('rainbow-delimiters.setup').setup {strategy= {-- ...    },query= {-- ...    },highlight= {-- ...    },}

Help wanted

There are only so many languages which I understand to the point that I canwrite queries for them. If you want support for a new language please considercontributing code. See theCONTRIBUTING for details.

Contributing

TL;DR: Run these steps first if you want to run tests:

ln -s .submodules .gitmodulesgit submodule initgit submodule updated --checkout

To provide some context, there are dependencies needed to run tests. These areincluded as Git submodules. The problem is that a number of package managerswill download submodules by default, which means that users will end up with abunch of stuff installed that they don't want. There is no way to tell Git touse a different file, so we have to create a symbolic link instead if weactually do want to download these submodules.

Status of the plugin

Tree-sitter support in Neovim is still experimental. This plugin and its APIshould be considered stable insofar as breaking changes will only happen ifchanges to Neovim necessitates them.

License

Licensed under the Apache-2.0 license. Please see theLICENSE file fordetails.

Migrating from nvim-ts-rainbow2

Rainbow-Delimiters uses different settings than nvim-ts-rainbow2, butconverting the configuration is straight-forward. The biggest change is wherethe settings are stored.

  • Settings are stored in the global variableg:rainbow-delimiters, which hasthe same keys as the old settings
  • The default strategy and query have index'' (empty string) instead of1
  • Default highlight groups have the prefixRainbowDelimiter instead ofTSRainbow, e.g.RainbowDelimiterRed instead ofTSRainbowRed
  • The default query is now calledrainbow-delimiters instead ofrainbow-parens
  • The public Lua module is calledrainbow-delimiters instead ofts-rainbow

The name of the default query is nowrainbow-delimiters because for somelanguages like HTML the notion of "parentheses" does not make any sense. InHTML the only meaningful delimiter is the tag. Hence the generic notion of a"delimiter".

Attribution

This is a fork of a previous Neovim plugin, the original repository isavailable underhttps://sr.ht/~p00f/nvim-ts-rainbow/.

Attributions from the original author

Huge thanks to @vigoux, @theHamsta, @sogaiu, @bfredl and @sunjon and@steelsojka for all their help

Screenshots

Bash

Screenshot of a Bash script with alternating coloured delimiters

C

Screenshot of a C program with alternating coloured delimiters

Common Lisp

Screenshot of a Common Lisp program with alternating coloured delimiters

HTML

Screenshot of an HTML document with alternating coloured delimiters

Java

Screenshot of a Java program with alternating coloured delimiters

LaTeX

Using therainbow-blocks query to highlight the entire\begin and\endinstructions.

Screenshot of a LaTeX document with alternating coloured delimiters

Lua

Using therainbow-blocks query to highlight the entire keywords likefunction,if,else andend.

Screenshot of a Lua script with alternating coloured delimiters

About

Rainbow delimiters for Neovim with Tree-sitter

Resources

License

Contributing

Stars

Watchers

Forks

Sponsor this project

  •  

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp