This Neovim plugin provides alternating syntax highlighting (“rainbow parentheses”) for Neovim, powered by Tree-sitter. The goal is to have a hackable plugin which allows for different configuration of queries and strategies, both globally and per file type. Users can override and extend the built-in defaults through their own configuration.
This is a fork of nvim-ts-rainbow2, which was implemented as a module for nvim-treessiter. However, since nvim-treesitter has deprecated the module system I had to create this standalone plugin.
Install it like any other Neovim plugin. You will need a Tree-sitter parser for each language you want to use rainbow delimiters with.
No configuration is needed to get started, this plugin has reasonable defaults
which you can override. Configuration is done by setting entries in the Vim
script dictionary g:rainbow_delimiters
. Here is an example configuration:
let 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',
\ ],
\ }
The equivalent code in Lua:
-- This module contains a number of default definitions
local rainbow_delimiters = require 'rainbow-delimiters'
---@type rainbow_delimiters.config
vim.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 the manual for more details. For those who prefer a setup
function there is the module rainbow-delimiters.setup
that accepts all the
same parameters as g:rainbow-delimiters
.
require('rainbow-delimiters.setup').setup {
strategy = {
-- ...
},
query = {
-- ...
},
highlight = {
-- ...
},
}
There are only so many languages which I understand to the point that I can write queries for them. If you want support for a new language please consider contributing code. See the CONTRIBUTING for details.
Tree-sitter support in Neovim is still experimental. This plugin and its API should be considered stable insofar as breaking changes will only happen if changes to Neovim necessitates them.
Licensed under the Apache-2.0 license. Please see the LICENSE file for details.
Rainbow-Delimiters uses different settings than nvim-ts-rainbow2, but converting the configuration is straight-forward. The biggest change is where the settings are stored.
g:rainbow-delimiters
, which has
the same keys as the old settings''
(empty string) instead of 1
RainbowDelimiter
instead of
TSRainbow
, e.g. RainbowDelimiterRed
instead of TSRainbowRed
rainbow-delimiters
instead of
rainbow-parens
rainbow-delimiters
instead of ts-rainbow
The name of the default query is now rainbow-delimiters
because for some
languages like HTML the notion of "parentheses" does not make any sense. In
HTML the only meaningful delimiter is the tag. Hence the generic notion of a
"delimiter".
This is a fork of a previous Neovim plugin, the original repository is available under https://sr.ht/~p00f/nvim-ts-rainbow/.
Huge thanks to @vigoux, @theHamsta, @sogaiu, @bfredl and @sunjon and @steelsojka for all their help
Using the rainbow-blocks
query to highlight the entire \begin
and \end
instructions.
Using the rainbow-blocks
query to highlight the entire keywords like
function
, if
, else
and end
.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。