HiPhish / nvim-ts-rainbow2

Rainbow delimiters for Neovim through Tree-sitter
https://gitlab.com/HiPhish/nvim-ts-rainbow2
Apache License 2.0
338 stars 35 forks source link

More clear instructions for custom color definitions #29

Closed opossalite closed 1 year ago

opossalite commented 1 year ago

Hello, I'm just trying to create a simple yellow-magenta-cyan color scheme. I recognize I must reorder the entries in hlgroups, however I have no idea how to set my own color hex definitions, and I've looked through the documentation. I am not advanced with lua, and I don't care about advanced dynamically pairing colors with themes, I just want to set the simple color scheme of "#ffd700", "#da70d6", "#179fff". I've set the hlgroups variable to this, and I'm not sure how to move forward:

hlgroups = {
    'TSRainbowYellow',
    'TSRainbowMagenta',
    'TSRainbowBlue',
}
HiPhish commented 1 year ago

The value of hlgroups is a list of Neovim highlight group names. You need to define those first. See :h :highlight (Vim script) or :h nvim_set_hl (Lua and API). The manual is written with the assumption that the reader is already familiar with how to define highlight groups since that's a standard Neovim feature.

TL;DR: First define your highlight groups, then reference them. Here is an example using Lua:

-- First define the highlight groups
vim.api.nvim_set_hl(0, 'TSRainbowYellow', {fg = '#ffd700'})
vim.api.nvim_set_hl(0, 'TSRainbowMagenta', {fg = '#da70d6'})
vim.api.nvim_set_hl(0, 'TSRainbowBlue', {fg = '#179fff'})

-- Now use them in your configuration
require'nvim-treesitter.configs'.setup {
    rainbow = {
        enable = true,
        hlgroups = {
            'TSRainbowYellow',
            'TSRainbowMagenta',
            'TSRainbowBlue',
        }
    }
}

The advantage of doing it like this is that we can leverage Neovim's built-in facilities for most of the work. Plus, once you learn how to define highlight groups in general you can use this knowledge in your other configuration and in other plugins as well.

opossalite commented 1 year ago

Thank you for explaining this, I'm still learning Vim in general and this is good information to have. Colors are working as expected now.

HiPhish commented 1 year ago

Closing as resolved

ghost commented 9 months ago

The value of hlgroups is a list of Neovim highlight group names. You need to define those first. See :h :highlight (Vim script) or :h nvim_set_hl (Lua and API). The manual is written with the assumption that the reader is already familiar with how to define highlight groups since that's a standard Neovim feature.

TL;DR: First define your highlight groups, then reference them. Here is an example using Lua:

-- First define the highlight groups
vim.api.nvim_set_hl(0, 'TSRainbowYellow', {fg = '#ffd700'})
vim.api.nvim_set_hl(0, 'TSRainbowMagenta', {fg = '#da70d6'})
vim.api.nvim_set_hl(0, 'TSRainbowBlue', {fg = '#179fff'})

-- Now use them in your configuration
require'nvim-treesitter.configs'.setup {
    rainbow = {
        enable = true,
        hlgroups = {
            'TSRainbowYellow',
            'TSRainbowMagenta',
            'TSRainbowBlue',
        }
    }
}

The advantage of doing it like this is that we can leverage Neovim's built-in facilities for most of the work. Plus, once you learn how to define highlight groups in general you can use this knowledge in your other configuration and in other plugins as well.

Thank you, I was looking for this and you save me, thank you very much.