Skip to content

meithon/idemcolor.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

idemcolor

A Neovim extension to highlight same-name identifiers with the same color.

Note: This is a maintained fork of markid by David Kunz, which is no longer actively maintained.

Motivation

Syntax highlighting is mostly based on element kinds of the abstract syntax tree. This sometimes leads to different visual representations of the same variable, consider this example:

Here, myParam has the colors yellow and white, making it hard for the developer to recognise that both represent the same thing.

Now with idemcolor, it's ensured that same-name identifiers are represented with the same color:

Here's a slightly more complicated example, try to track the flow of qux:

Installation

Requirements: nvim-treesitter including a parser for your language

For vim-plug:

Plug 'meithon/idemcolor.nvim'

For packer:

use 'meithon/idemcolor.nvim'

For lazy.nvim:

{ 'meithon/idemcolor.nvim' }

Option 1: Standalone setup (recommended for nvim-treesitter 1.0+)

require('idemcolor').setup()

Option 2: Via nvim-treesitter module (legacy, for nvim-treesitter < 1.0)

require'nvim-treesitter.configs'.setup {
  idemcolor = { enable = true }
}

Options

These are the configuration options (with defaults):

local m = require'idemcolor'

-- Standalone setup
m.setup({
  enable = true,
  colors = m.colors.medium,
  queries = m.queries,
})

-- Or via nvim-treesitter (legacy)
require'nvim-treesitter.configs'.setup {
  idemcolor = {
    enable = true,
    colors = m.colors.medium,
    queries = m.queries,
  }
}

m.colors = {
    dark = { "#619e9d", "#9E6162", "#81A35C", "#7E5CA3", "#9E9261", "#616D9E", "#97687B", "#689784", "#999C63", "#66639C" },
    bright = {"#f5c0c0", "#f5d3c0", "#f5eac0", "#dff5c0", "#c0f5c8", "#c0f5f1", "#c0dbf5", "#ccc0f5", "#f2c0f5", "#d8e4bc" },
    medium = { "#c99d9d", "#c9a99d", "#c9b79d", "#c9c39d", "#bdc99d", "#a9c99d", "#9dc9b6", "#9dc2c9", "#9da9c9", "#b29dc9" }
}

m.queries = {
  default = '(identifier) @idemcolor',
  javascript = [[
          (identifier) @idemcolor
          (property_identifier) @idemcolor
          (shorthand_property_identifier_pattern) @idemcolor
          (shorthand_property_identifier) @idemcolor
        ]]
}
m.queries.typescript = m.queries.javascript

The m.queries table above can be used to define language-specific highlighting rules via custom Treesitter queries. Alternatively, idemcolor can also source queries from standalone files located in your local runtime queries/ directory. Simply create a new directory in your nvim config folder for your language of choice, e.g. $HOME/.config/nvim/queries/python, and write your query in a file called idemcolor.scm.

Custom Highlight Groups

For more control, you can define the highlight groups idemcolor1, idemcolor2, ..., idemcolor10, this is especially useful for theme designers.

Example:

vim.api.nvim_set_hl(0, 'idemcolor1', { fg = '#c99d9d', bg = '#003844', underline = true })
vim.api.nvim_set_hl(0, 'idemcolor2', { fg = '#c9a99d', bg = '#003844', underline = true })
-- ...
vim.api.nvim_set_hl(0, 'idemcolor10', { fg = '#c9b79d', bg = '#003844', underline = true })

About

No description or website provided.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages