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 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 currently.
           Shortcut for ColorizerAttachToBuffer on every buffer.
    
       *:ColorizerToggle*
           Toggle highlighting of the current buffer.
    
    USE WITH LUA
    
           All options that can be passed to user_default_options in `setup`
           can be passed here. Can be empty too.
           `0` is the buffer number here
    
           Attach to current buffer <pre>
               require("colorizer").attach_to_buffer(0, {
                 mode = "background",
                 css = false,
               })
    </pre>
           Detach from buffer <pre>
               require("colorizer").detach_from_buffer(0, {
                 mode = "background",
                 css = false,
               })
    </pre>
    

Info:

Functions

highlight_buffer () Highlight the buffer region
is_buffer_attached (buf) Check if attached to a buffer.
detach_from_buffer (buf, ns) Stop highlighting the current buffer.
attach_to_buffer (buf, options, typ) Attach to a buffer and continuously highlight changes.
setup (config) Easy to use function if you want the full setup without fine grained control.
get_buffer_options (buf) Return the currently active buffer options.
reload_all_buffers () Reload all of the currently active highlighted buffers.
clear_highlight_cache () Clear the highlight cache and reload all buffers.

Tables

user_default_options defaults options.

Fields

DEFAULT_NAMESPACE Default namespace used in colorizer.buffer.highlight and attach_to_buffer.


Functions

highlight_buffer ()
Highlight the buffer region

See also:

is_buffer_attached (buf)
Check if attached to a buffer.

Parameters:

  • buf number|nil: A value of 0 implies the current buffer.

Returns:

    number|nil: if attached to the buffer, false otherwise.

See also:

detach_from_buffer (buf, ns)
Stop highlighting the current buffer.

Parameters:

  • buf number|nil: buf A value of 0 or nil implies the current buffer.
  • ns number|nil: ns the namespace id, if not given DEFAULT_NAMESPACE is used
attach_to_buffer (buf, options, typ)
Attach to a buffer and continuously highlight changes.

Parameters:

  • buf integer: A value of 0 implies the current buffer.
  • options table|nil: Configuration options as described in setup
  • typ string|nil: "buf" or "file" - The type of buffer option
setup (config)
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 {
      filetypes = { "*" },
      user_default_options,
      -- all the sub-options of filetypes apply to buftypes
      buftypes = {},
    }

For all userdefaultoptions, see |userdefaultoptions|

Parameters:

  • config table: Config containing above parameters.

Usage:

    require'colorizer'.setup()
get_buffer_options (buf)
Return the currently active buffer options.

Parameters:

  • buf number|nil: Buffer number

Returns:

    table|nil
reload_all_buffers ()
Reload all of the currently active highlighted buffers.
clear_highlight_cache ()
Clear the highlight cache and reload all buffers.

Tables

user_default_options

defaults options. In user_default_options, there are 2 types of options

  1. Individual options - names, RGB, RRGGBB, RRGGBBAA, hsl_fn, rgb_fn , RRGGBBAA, AARRGGBB, tailwind, sass

  2. Alias options - css, css_fn

If css_fn is true, then hsl_fn, rgb_fn becomes true

If css is true, then names, RGB, RRGGBB, RRGGBBAA, hsl_fn, rgb_fn becomes true

These options have a priority, Individual options have the highest priority, then alias options

For alias, css_fn has more priority over css

e.g: Here RGB, RRGGBB, RRGGBBAA, hsl_fn, rgb_fn is enabled but not names

  require 'colorizer'.setup { user_default_options = { names = false, css = true } }

e.g: Here names, RGB, RRGGBB, RRGGBBAA is enabled but not rgb_fn and hsl_fn

  require 'colorizer'.setup { user_default_options = { css_fn = false, css = true } }
  user_default_options = {
      RGB = true, -- #RGB hex codes
      RRGGBB = true, -- #RRGGBB hex codes
      names = true, -- "Name" codes like Blue or blue
      RRGGBBAA = false, -- #RRGGBBAA hex codes
      AARRGGBB = false, -- 0xAARRGGBB 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 for mode: foreground, background,  virtualtext
      mode = "background", -- Set the display mode.
      -- Available methods are false / true / "normal" / "lsp" / "both"
      -- True is same as normal
      tailwind = false, -- Enable tailwind colors
      -- parsers can contain values used in |user_default_options|
      sass = { enable = false, parsers = { css }, }, -- Enable sass colors
      virtualtext = "■",
      -- update color values even if buffer is not focused
      always_update = false
  }

Fields:

  • RGB boolean
  • RRGGBB boolean
  • names boolean
  • RRGGBBAA boolean
  • AARRGGBB boolean
  • rgb_fn boolean
  • hsl_fn boolean
  • css boolean
  • css_fn boolean
  • mode string
  • tailwind boolean|string
  • sass table
  • virtualtext string
  • always_update boolean

Fields

DEFAULT_NAMESPACE
Default namespace used in colorizer.buffer.highlight and attach_to_buffer.

See also:

generated by LDoc 1.4.6 Last updated - February