Highlight Tailwind CSS classes in neovim

  • By Prince Carlo Juguilon
  • Last update: Dec 28, 2022
  • Comments: 1

tailwind-highlight.nvim

License Version

Highlight Tailwind CSS classes in neovim

"The neovim plugin used by a Netflix Engineer"

tailwind-highlight-demo

Installation

  • Vim Plug

    " required dependency
    Plug 'neovim/nvim-lspconfig'
    " (optional) for installing tailwindcss language server
    Plug 'williamboman/nvim-lsp-installer'
    Plug 'princejoogie/tailwind-highlight.nvim'
  • Vundle

    " required dependency
    Plugin 'neovim/nvim-lspconfig'
    " (optional) for installing tailwindcss language server
    Plugin 'williamboman/nvim-lsp-installer'
    Plugin 'princejoogie/tailwind-highlight.nvim'
  • Dein

    " required dependency
    call dein#add('neovim/nvim-lspconfig')
    " (optional) for installing tailwindcss language server
    call dein#add('williamboman/nvim-lsp-installer')
    call dein#add('princejoogie/tailwind-highlight.nvim')

Usage

local tw_highlight = require('tailwind-highlight')

Methods

Method Args Returns
setup (client, bufnr, opts) void
ping N/A string

Setup Options

Option Description Default
single_column highlight only first character false
mode highlight mode foreground | background background
debounce delay on updating highlights (ms) 200

Without Lsp Installer

Manually install tailwindcss-language-server

require('lspconfig').tailwindcss.setup({
  on_attach = function(client, bufnr)
    -- rest of you config
    tw_highlight.setup(client, bufnr, {
      single_column = false,
      mode = 'background',
      debounce = 200,
    })
  end
})

With Lsp Installer

:LspInstall tailwindcss

require('nvim-lsp-installer').on_server_ready(function(server)
  local opts = {
    on_attach = function(client, bufnr)
      -- rest of you config
      tw_highlight.setup(client, bufnr, {
        single_column = false,
        mode = 'background',
        debounce = 200,
      })
    end
  }

  server:setup(opts)
end)

Like the project? would appreciate a coffee

Buy Me A Coffee

Contributor list

Contributors


Made with by Prince Carlo Juguilon

Github

https://github.com/princejoogie/tailwind-highlight.nvim

Comments(1)

  • 1

    Display color chip as virtual text?

    Thanks for this plugin!

    I'm wondering if it would be possible to provide an option to display the color as a chip next to the class name as virtual text? For example, this is what another nvim plugin (rrethy/vim-hexokinase) does for hex codes:

    Screenshot 2022-11-12 at 9 52 13 AM