• Stars
    star
    2,302
  • Rank 20,006 (Top 0.4 %)
  • Language
    Lua
  • License
    Other
  • Created about 5 years ago
  • Updated 4 months ago

Reviews

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

Repository Details

The fastest Neovim colorizer.

colorizer.lua

luadoc

A high-performance color highlighter for Neovim which has no external dependencies! Written in performant Luajit.

Demo.gif

Demo.mp4

Installation and Usage

Requires Neovim >= 0.4.0 and set termguicolors (I'm looking into relaxing these constraints). If you don't have true color for your terminal or are unsure, read this excellent guide.

Use your plugin manager or clone directly into your runtimepath.

Plug 'norcalli/nvim-colorizer.lua'

As long as you have malloc() and free() on your system, this will work. Which includes Linux, OSX, and Windows.

One line setup. This will create an autocmd for FileType * to highlight every filetype. NOTE: You should add this line after/below where your plugins are setup.

lua require'colorizer'.setup()

Why another highlighter?

Mostly, RAW SPEED.

This has no external dependencies, which means you install it and it just works. Other colorizers typically were synchronous and slow, as well. Being written with performance in mind and leveraging the excellent LuaJIT and a handwritten parser, updates can be done in real time. There are plugins such as hexokinase which have good performance, but it has some difficulty with becoming out of sync. The downside is that this only works for Neovim, and that will never change.

Additionally, having a Lua API that's available means users can use this as a library to do custom highlighting themselves.

Customization

  DEFAULT_OPTIONS = {
	RGB      = true;         -- #RGB hex codes
	RRGGBB   = true;         -- #RRGGBB hex codes
	names    = true;         -- "Name" codes like Blue
	RRGGBBAA = false;        -- #RRGGBBAA hex codes
	rgb_fn   = false;        -- CSS rgb() and rgba() functions
	hsl_fn   = false;        -- CSS hsl() and hsla() functions
	css      = false;        -- Enable all CSS features: rgb_fn, hsl_fn, names, RGB, RRGGBB
	css_fn   = false;        -- Enable all CSS *functions*: rgb_fn, hsl_fn
	-- Available modes: foreground, background
	mode     = 'background'; -- Set the display mode.
  }

MODES:

  • foreground: sets the foreground text color.
  • background: sets the background text color.

For basic setup, you can use a command like the following.

-- Attaches to every FileType mode
require 'colorizer'.setup()

-- Attach to certain Filetypes, add special configuration for `html`
-- Use `background` for everything else.
require 'colorizer'.setup {
  'css';
  'javascript';
  html = {
    mode = 'foreground';
  }
}

-- Use the `default_options` as the second parameter, which uses
-- `foreground` for every mode. This is the inverse of the previous
-- setup configuration.
require 'colorizer'.setup({
  'css';
  'javascript';
  html = { mode = 'background' };
}, { mode = 'foreground' })

-- Use the `default_options` as the second parameter, which uses
-- `foreground` for every mode. This is the inverse of the previous
-- setup configuration.
require 'colorizer'.setup {
  '*'; -- Highlight all files, but customize some others.
  css = { rgb_fn = true; }; -- Enable parsing rgb(...) functions in css.
  html = { names = false; } -- Disable parsing "names" like Blue or Gray
}

-- Exclude some filetypes from highlighting by using `!`
require 'colorizer'.setup {
  '*'; -- Highlight all files, but customize some others.
  '!vim'; -- Exclude vim from highlighting.
  -- Exclusion Only makes sense if '*' is specified!
}

For lower level interface, see the LuaDocs for API details or use :h colorizer.lua once installed.

Commands

|:ColorizerAttachToBuffer|

Attach to the current buffer and start highlighting with the settings as
specified in setup (or the defaults).

If the buffer was already attached (i.e. being highlighted), the settings will
be reloaded with the ones from setup. This is useful for reloading settings
for just one buffer.

|:ColorizerDetachFromBuffer|

Stop highlighting the current buffer (detach).

|:ColorizerReloadAllBuffers|

Reload all buffers that are being highlighted with new settings from the setup
settings (or the defaults). Shortcut for ColorizerAttachToBuffer on every
buffer.

|:ColorizerToggle|

Toggle highlighting of the current buffer.

Caveats

If the file you are editing has no filetype, the plugin won't be attached, as it relies on AutoCmd to do so. You can still make it work by running the following command: :ColorizerAttachToBuffer

See this comment for more information.

TODO

  • Add more display modes?
  • Use a more space efficient trie implementation.
  • Create a COMMON_SETUP which does obvious things like enable rgb_fn for css

More Repositories

1

snippets.nvim

Lua
277
star
2

nvim-terminal.lua

A high performance filetype mode for Neovim which leverages conceal and highlights your buffer with the correct color codes.
Lua
208
star
3

nvim_utils

Lua
108
star
4

nvim-base16.lua

Programmatic lua library for setting base16 themes in Neovim.
Lua
72
star
5

nvim.lua

nvim.lua is a lua module which provides an object which contains shortcut/magic methods that are very useful for mappings.
Lua
51
star
6

profiler.nvim

Lua
39
star
7

neovim-plugin

Lua
35
star
8

twitch-scraper

Program to poll twitch via its API and download streams from channels as they come live.
Rust
32
star
9

typeracer.nvim

Rust
30
star
10

ui.nvim

Lua
14
star
11

ksway

This library provides a convenient interface for quickly making scripts for i3 and sway (since they share an IPC interface API). It will mainly be focused on sway if that compatibility changes.
Rust
13
star
12

lua-sway

A Lua module for interfacing with sway via IPC.
Lua
12
star
13

nvim-snippets.lua

Lua
10
star
14

ractiveify

Browserify transform for ractive components (and by extension templates) which allows for compilation of embedded scripts and styles!
LiveScript
9
star
15

spiceplot

A program written in Go and using plotinum that interprets raw spice files and produces pretty plots in svg, png, pdf, or jpg formats.
Go
7
star
16

enpass-cli

Enpass CLI agent written written in rust!
Rust
6
star
17

scripts

Some scripts. That's it.
Shell
6
star
18

nvim-popterm.lua

Lua
4
star
19

lua-stream

A Lua module inspired by Monix for processing elements in a Stream using reactive style and coroutines.
Lua
4
star
20

quadprog

Rust
4
star
21

qfpga

Quantum FPGA simulator
Python
3
star
22

undead-us-keyboard

Shell
2
star
23

kpostgres_fixture

Postgres fixtures for making temporary databases and temporary services.
Rust
2
star
24

capacitor

Simple capacitor code calculator on the command line written in Go and Python.
Go
2
star
25

raw_tty.rs

Rust crate for modifying tty modes, esp. raw tty mode.
Rust
2
star
26

kmacros

Rust
1
star
27

newtabwindow

JavaScript
1
star
28

number-parse

A fast templated number parsing library in C++.
C
1
star
29

norcalli

1
star
30

rawspice

A Go library for reading and interpreting raw spice files.
Go
1
star
31

matlab.vim

Vim Script
1
star