https://github.com/brenoprata10/nvim-highlight-colors
Highlight colors for neovim
https://github.com/brenoprata10/nvim-highlight-colors
colors neovim nvim plugin vim
Last synced: 7 months ago
JSON representation
Highlight colors for neovim
- Host: GitHub
- URL: https://github.com/brenoprata10/nvim-highlight-colors
- Owner: brenoprata10
- Created: 2022-07-17T11:09:45.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-05-21T12:37:47.000Z (over 1 year ago)
- Last Synced: 2024-05-21T13:49:40.371Z (over 1 year ago)
- Topics: colors, neovim, nvim, plugin, vim
- Language: Lua
- Homepage:
- Size: 127 KB
- Stars: 486
- Watchers: 5
- Forks: 25
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
- awesome-neovim - brenoprata10/nvim-highlight-colors - A plugin to highlight colors with Neovim. (Color / Assembly)
- awesome-neovim-sorted - brenoprata10/nvim-highlight-colors
- awesome-neovim-sorted - brenoprata10/nvim-highlight-colors
README
> Highlight colors within Neovim

## Features
- Realtime color highlighting
- Supports hex, rgb, hsl, CSS variables, and Tailwind CSS
- LSP support! For any LSP that supports `textDocument/documentColor` like [tailwindcss](https://github.com/tailwindlabs/tailwindcss-intellisense) and [csslsp](https://github.com/microsoft/vscode-css-languageservice)
- Multiple rendering modes: background, foreground, and virtual text
## Usage
Install via your preferred package manager:
```lua
'brenoprata10/nvim-highlight-colors'
```
Initialize the plugin:
```lua
-- Ensure termguicolors is enabled if not already
vim.opt.termguicolors = true
require('nvim-highlight-colors').setup({})
```
### `nvim-cmp` integration
```lua
require("cmp").setup({
... other configs
formatting = {
format = require("nvim-highlight-colors").format
}
})
```
or
```lua
require("cmp").setup({
... other configs
formatting = {
format = function(entry, item)
item = -- YOUR other configs come first
return require("nvim-highlight-colors").format(entry, item)
end
}
})
```
#### `lspkind` integration
The out of the box `format` function does not necessarily play nicely with `lspkind` and potentially other formatters provided by plugins and may require manual intervention. Here is an example of making the integration work nicely with `lspkind`:
```lua
require("cmp").setup({
... other configs
formatting = {
format = function(entry, item)
local color_item = require("nvim-highlight-colors").format(entry, { kind = item.kind })
item = require("lspkind").cmp_format({
-- any lspkind format settings here
})(entry, item)
if color_item.abbr_hl_group then
item.kind_hl_group = color_item.abbr_hl_group
item.kind = color_item.abbr
end
return item
end
}
})
```
### `blink.cmp` integration
```lua
require("blink.cmp").setup {
completion = {
menu = {
draw = {
components = {
-- customize the drawing of kind icons
kind_icon = {
text = function(ctx)
-- default kind icon
local icon = ctx.kind_icon
-- if LSP source, check for color derived from documentation
if ctx.item.source_name == "LSP" then
local color_item = require("nvim-highlight-colors").format(ctx.item.documentation, { kind = ctx.kind })
if color_item and color_item.abbr then
icon = color_item.abbr
end
end
return icon .. ctx.icon_gap
end,
highlight = function(ctx)
-- default highlight group
local highlight = "BlinkCmpKind" .. ctx.kind
-- if LSP source, check for color derived from documentation
if ctx.item.source_name == "LSP" then
local color_item = require("nvim-highlight-colors").format(ctx.item.documentation, { kind = ctx.kind })
if color_item and color_item.abbr_hl_group then
highlight = color_item.abbr_hl_group
end
end
return highlight
end,
},
},
},
},
},
}
```
## Options
```lua
require("nvim-highlight-colors").setup {
---Render style
---@usage 'background'|'foreground'|'virtual'
render = 'background',
---Set virtual symbol (requires render to be set to 'virtual')
virtual_symbol = '■',
---Set virtual symbol suffix (defaults to '')
virtual_symbol_prefix = '',
---Set virtual symbol suffix (defaults to ' ')
virtual_symbol_suffix = ' ',
---Set virtual symbol position()
---@usage 'inline'|'eol'|'eow'
---inline mimics VS Code style
---eol stands for `end of column` - Recommended to set `virtual_symbol_suffix = ''` when used.
---eow stands for `end of word` - Recommended to set `virtual_symbol_prefix = ' ' and virtual_symbol_suffix = ''` when used.
virtual_symbol_position = 'inline',
---Highlight hex colors, e.g. '#FFFFFF'
enable_hex = true,
---Highlight short hex colors e.g. '#fff'
enable_short_hex = true,
---Highlight rgb colors, e.g. 'rgb(0 0 0)'
enable_rgb = true,
---Highlight hsl colors, e.g. 'hsl(150deg 30% 40%)'
enable_hsl = true,
-- Highlight hsl colors without function, e.g. '--foreground: 0 69% 69%;'
enable_hsl_without_function = true,
---Highlight CSS variables, e.g. 'var(--testing-color)'
enable_var_usage = true,
---Highlight named colors, e.g. 'green'
enable_named_colors = true,
---Highlight tailwind colors, e.g. 'bg-blue-500'
enable_tailwind = false,
---Set custom colors
---Label must be properly escaped with '%' to adhere to `string.gmatch`
--- :help string.gmatch
custom_colors = {
{ label = '%-%-theme%-primary%-color', color = '#0f1219' },
{ label = '%-%-theme%-secondary%-color', color = '#5a5d64' },
},
-- Exclude filetypes or buftypes from highlighting e.g. 'exclude_buftypes = {'text'}'
exclude_filetypes = {},
exclude_buftypes = {},
-- Exclude buffer from highlighting e.g. 'exclude_buffer = function(bufnr) return vim.fn.getfsize(vim.api.nvim_buf_get_name(bufnr)) > 1000000 end'
exclude_buffer = function(bufnr) end
}
```
### Render modes
> Examples shown use `enable_tailwind = true`
**Background**

**Foreground**

**Virtual text**

**nvim-cmp integration**

## Commands
| Command | Description |
| :-------------------------- | :--------------------------- |
| `:HighlightColors On` | Turn highlights on |
| `:HighlightColors Off` | Turn highlights off |
| `:HighlightColors Toggle` | Toggle highlights |
| `:HighlightColors IsActive` | Highlights active / disabled |
Commands are also available in lua:
```lua
require("nvim-highlight-colors").turnOn()
require("nvim-highlight-colors").turnOff()
require("nvim-highlight-colors").toggle()
require("nvim-highlight-colors").is_active()
```