Module colorizer
Requires Neovim >= 0.7.0 and `set termguicolors`
Highlights terminal CSI ANSI color codes.
See also:
Usage:
Establish the autocmd to highlight all filetypes. `lua require("colorizer").setup()` Highlight using all css highlight modes in every filetype `lua require("colorizer").setup(user_default_options = { css = true })` ============================================================================== USE WITH COMMANDS *colorizer-commands* *:ColorizerAttachToBuffer* Attach to the current buffer and start continuously highlighting matched color names and codes. If the buffer was already attached(i.e. being highlighted), the settings will be reloaded. 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 currently. Calls ColorizerAttachToBuffer on every buffer. *:ColorizerToggle* Toggle highlighting of the current buffer. USE WITH LUA ATTACH Accepts buffer number (0 or nil for current) and an option table of user_default_options from `setup`. Option table can be nil which defaults to setup options. Attach to current buffer with local options: require("colorizer").attach_to_buffer(0, { mode = "background", css = false, }) Attach to current buffer with setup options: require("colorizer").attach_to_buffer() Accepts an optional buffer number (0 or nil for current). Defaults to current buffer. DETACH Detach to buffer with id 22: require("colorizer").attach_to_buffer(22) Detach from current buffer: require("colorizer").detach_from_buffer(0) require("colorizer").detach_from_buffer() Detach from buffer with id 22: require("colorizer").detach_from_buffer(22)
Functions
highlight_buffer () | Highlight the buffer region. |
rehighlight (bufnr, ud_opts, buf_local_opts, hl_opts) | Rehighlight the buffer if colorizer is active |
get_attached_bufnr (bufnr) | Get attached bufnr |
is_buffer_attached (bufnr) | Check if buffer is attached to colorizer |
reload_all_buffers () | Reload all of the currently active highlighted buffers. |
reload_on_save (pattern) | Reload file on save; used for dev, to edit expect.txt and apply highlights from returned setup table |
attach_to_buffer (bufnr, ud_opts, bo_type) | Attach to a buffer and continuously highlight changes. |
detach_from_buffer (bufnr) | Stop highlighting the current buffer. |
setup (opts) | Easy to use function if you want the full setup without fine grained control. |
clear_highlight_cache () | Clears the highlight cache and reloads all buffers. |
Functions
- highlight_buffer ()
-
Highlight the buffer region.
See also:
- rehighlight (bufnr, ud_opts, buf_local_opts, hl_opts)
-
Rehighlight the buffer if colorizer is active
Parameters:
- bufnr number: Buffer number (0 for current)
- ud_opts table: `user_default_options`
- buf_local_opts table|nil: Buffer local options
- hl_opts table|nil: Highlighting options - use_local_lines: boolean: Use `buf_local_opts` __startline and __endline for lines
Returns:
-
table: Detach settings table to use when cleaning up buffer state in `colorizer.detach_from_buffer`
- ns_id number: Table of namespace ids to clear
- functions function: Table of detach functions to call
- get_attached_bufnr (bufnr)
-
Get attached bufnr
Parameters:
- bufnr number|nil: buffer number (0 for current)
Returns:
-
number: Returns attached bufnr. Returns -1 if buffer is not attached to colorizer.
See also:
- is_buffer_attached (bufnr)
-
Check if buffer is attached to colorizer
Parameters:
- bufnr number|nil: buffer number (0 for current)
Returns:
-
boolean: Returns `true` if buffer is attached to colorizer.
- reload_all_buffers ()
- Reload all of the currently active highlighted buffers.
- reload_on_save (pattern)
-
Reload file on save; used for dev, to edit expect.txt and apply highlights from returned setup table
Parameters:
- pattern string: pattern to match file name
- attach_to_buffer (bufnr, ud_opts, bo_type)
-
Attach to a buffer and continuously highlight changes.
Parameters:
- bufnr number|nil: buffer number (0 for current)
- ud_opts table|nil: `user_default_options`
- bo_type 'buftype'|'filetype'|nil: The type of buffer option
- detach_from_buffer (bufnr)
-
Stop highlighting the current buffer.
Parameters:
- bufnr number|nil: buffer number (0 for current)
Returns:
-
number: returns -1 if buffer is not attached, otherwise returns bufnr
- setup (opts)
-
Easy to use function if you want the full setup without fine grained control.
Setup an autocmd which enables colorizing for the filetypes and options specified.
By default highlights all FileTypes.
Example config:~
{ filetypes = { "css", "html" }, user_default_options = { names = true } }
Setup with all the default options:~require("colorizer").setup { user_commands, filetypes = { "*" }, user_default_options, -- all the sub-options of filetypes apply to buftypes buftypes = {}, }
Setup colorizer with user optionsParameters:
- opts table|nil: User provided options
See also:
Usage:
`require("colorizer").setup()`
- clear_highlight_cache ()
- Clears the highlight cache and reloads all buffers.