Giter Club home page Giter Club logo

rodvicj / rainbow-delimiters.nvim Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hiphish/rainbow-delimiters.nvim

0.0 0.0 0.0 1.53 MB

Rainbow delimiters for Neovim with Tree-sitter

Home Page: https://gitlab.com/HiPhish/rainbow-delimiters.nvim

License: Apache License 2.0

Shell 1.18% JavaScript 0.83% Ruby 0.23% C++ 0.57% Scheme 25.60% Python 0.40% C 0.68% PHP 0.31% Java 0.79% Common Lisp 0.11% Lua 62.68% Haskell 0.55% Clojure 0.09% R 0.14% Verilog 0.48% Go 1.01% C# 1.80% Racket 0.39% Rust 1.74% Elixir 0.41%

rainbow-delimiters.nvim's Introduction

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

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 = {
        -- ...
    },
}

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.

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

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 the rainbow-blocks query to highlight the entire \begin and \end instructions.

Screenshot of a LaTeX document with alternating coloured delimiters

Lua

Using the rainbow-blocks query to highlight the entire keywords like function, if, else and end.

Screenshot of a Lua script with alternating coloured delimiters

rainbow-delimiters.nvim's People

Contributors

akhilrobert avatar alexander-p30 avatar amopel avatar aspeddro avatar bomgar avatar brokenbyte avatar c-a-v-a avatar catthingy avatar danielkonge avatar delphinus avatar folliehiyuki avatar gelio avatar github-actions[bot] avatar hiphish avatar jcapblancq avatar kawre avatar liljaylj avatar luozhiya avatar mattyoung101 avatar mrcjkb avatar p00f avatar qsdrqs avatar ram02z avatar reo101 avatar rodvicj avatar sunjon avatar thehamsta avatar tradiff avatar tuanha168 avatar tzachar avatar

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.