• Stars
    star
    240
  • Rank 167,479 (Top 4 %)
  • Language
    Lua
  • License
    Apache License 2.0
  • Created about 1 year ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Rainbow delimiters for Neovim with Tree-sitter

Rainbow delimiters for Neovim

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.

Installation and setup

Installation

Install it like any other Neovim plugin. You will need a Tree-sitter parser for each language you want to use rainbow delimiters with.

Setup

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',
    \ },
    \ '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'

vim.g.rainbow_delimiters = {
    strategy = {
        [''] = rainbow_delimiters.strategy['global'],
        vim = rainbow_delimiters.strategy['local'],
    },
    query = {
        [''] = 'rainbow-delimiters',
        lua = 'rainbow-blocks',
    },
    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.

Help wanted

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.

Status of the plugin

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.

Warning

There is currently a shortcoming in Neovim's Tree-sitter API which makes it so that only the first node of a capture group can be highlighted. Please see neovim/neovim#17099 for details. Affected queries:

  • HTML rainbow-delimiters
  • JSX (Javascript + React.js) rainbow-delimiters-react (affects React tags only)
  • Python (rainbow-delimiters) (affects only the for ... in inside comprehensions)
  • TSX (Typescript + React.js) rainbow-delimiters-react (affects React tags only)
  • Vue.js rainbow-delimiters

Most of these are related to HTML-like tags, so you can use an alternative query instead. See the manual (:h ts-rainbow-query) for a list of extra queries.

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

Java

Screenshot of a Java program with alternating coloured delimiters

LaTeX

Using the blocks query to highlight the entire \begin and \end instructions.

Screenshot of a LaTeX document with alternating coloured delimiters

License

Licensed under the Apache-2.0 license. Please see the LICENSE file for details.

Migrating from nvim-ts-rainbow2

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.

  • Settings are stored in the global variable g:rainbow-delimiters, which has the same keys as the old settings
  • The default strategy and query have index '' (empty string) instead of 1
  • Default highlight groups have the prefix RainbowDelimiter instead of TSRainbow, e.g. RainbowDelimiterRed instead of TSRainbowRed
  • The default query is now called rainbow-delimiters instead of rainbow-parens
  • The public Lua module is called 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".

Attribution

This is a fork of a previous Neovim plugin, the original repository is available under https://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

More Repositories

1

nvim-ts-rainbow2

Rainbow delimiters for Neovim through Tree-sitter
Lua
314
star
2

info.vim

Browse info files from Vim (mirror)
Vim Script
35
star
3

awk-ward.nvim

Mirror of https://gitlab.com/HiPhish/awk-ward.nvim
Vim Script
22
star
4

debugpy.nvim

Command and configuration frontend for Debugpy and nvim-dap
Lua
19
star
5

Game-Source-Documentation

17
star
6

Wolf3DExtract

Command-line tool for extracting assets from Wolfenstein 3D for PC
C
15
star
7

jinja.vim

Filetype detection an syntax support for Jinja templates.
Vim Script
14
star
8

XeenTools

Open-source library for resource files of the *Might & Magic: World of Xeen* games.
C
13
star
9

guile.vim

[mirror] Syntax highlighting and file type detect of GNU Guile code in Vim
Vim Script
11
star
10

nvim-cmp-vlime

(Mirror) Completion source for nvim-cmp using Vlime for Common Lisp completions.
Lua
9
star
11

Newton-method

Newton's method in C, using an arithmetic expression compiler and virtual machine
C
8
star
12

guile-repl.nvim

The GNU Guile REPL for Nvim
Vim Script
7
star
13

desktop-notify-nvim

[mirror] Neovim notifications on your desktop
Lua
6
star
14

gradle.nvim

[mirror] Gradle integration for Neovim
Java
5
star
15

ncm2-vlime

Common Lisp completions for NCM2 using Vlime [mirror]
Vim Script
5
star
16

repl.nvim

The universal, extendible and configurable REPL plugin
Vim Script
4
star
17

workshop

Content and static site generator for my website
Scheme
3
star
18

HiPhish.github.io

GitHub Pages website
HTML
3
star
19

msgpack-racket

msgpack.org[Racket] Mirror of the MessagePack implementation for Racket
Racket
2
star
20

anno-1503-resolution-patcher

Python script to enable higher resolutions in the game Anno 1503. (mirror)
Python
2
star
21

cl-cmark

CommonMark implementation for Common Lisp based on libcmark. This system wraps the official reference implementation library, written in C, and provides lispy bindings for Common Lisp.
Common Lisp
2
star
22

fennel-repl.nvim

Interactive Fennel REPL inside Neovim (mirror)
Lua
1
star
23

quicklisp.nvim

Neovim client for Quicklisp (mirror)
Common Lisp
1
star
24

completion-nvim-vlime

[Mirror] Vlime source for completion-nvim, adds Common Lisp completion
Vim Script
1
star
25

guile-msgpack

MessagePack implementation for GNU Guile (mirror) msgpack.org[GNU Guile]
Scheme
1
star