Skip to content

Instantly share code, notes, and snippets.

@mhinz
Last active May 28, 2020 23:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mhinz/a830cd1014c1ecaa3d53cf463616af5c to your computer and use it in GitHub Desktop.
Save mhinz/a830cd1014c1ecaa3d53cf463616af5c to your computer and use it in GitHub Desktop.

Either in init.vim:

lua require 'colorizer'.setup()
lua << EOF
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
}
EOF

Or in a separate lua file:

" init.vim

lua require 'foo'
-- ~/.config/nvim/lua/foo.lua

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
}

Since the plugin currently requires set termguicolors, you could do this, if you usually do not use that option:

function! s:colorizer_setup() abort
  lua << EOF
    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
    }
EOF
endfunction

if has('nvim')
  if &termguicolors
    call s:colorizer_setup()
  else
    autocmd OptionSet termguicolors ++once
          \ if v:option_new == 1 |
          \   call s:colorizer_setup() |
          \   execute 'ColorizerAttachToBuffer' |
          \ endif
  endif
endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment