nvim-colorizer.lua icon indicating copy to clipboard operation
nvim-colorizer.lua copied to clipboard

Bug: Does not work with autocmd

Open chrisgrieser opened this issue 3 years ago • 5 comments

plugin installed, and using this to automatically activate it in css files. with this config, the plugin does not work at all. :ColorizerAttachToBuffer also has no effect.

vim.opt.termguicolors = true
require("colorizer").setup {}

vim.api.nvim_create_autocmd("FileType", {
	pattern = {"css"},
	callback = function ()
		require("colorizer").attach_to_buffer(0, {
			mode = "background",
			css = true,
		})
	end
})

leaving out the autocmd:

vim.opt.termguicolors = true
require("colorizer").setup {}

the plugin works, but of course this requires me to manually activate it in every css file with attach_to_buffer

I dunno, maybe I am missing something, but I went through the docs twice and cannot find what I might be missing here.

Operating System:

macOS 12.5.1 (M1)
neovim 0.8.0 (homebrew install)
colorizer: 36c610a9717cc9ec426a07c8e6bf3b3abcb139d6

chrisgrieser avatar Oct 06 '22 23:10 chrisgrieser

i think this commit is the reason.

AlixShahid avatar Oct 07 '22 03:10 AlixShahid

Hmm the current HEAD (9dd7ecde55b06b5114e1fa67c522433e7e59db8b) is working fine for me. Here's my setup script. These are in my init.lua

colorizer.setup()

vim.api.nvim_create_autocmd("FileType", {
  pattern = {"javascript"},
  callback = function ()
    require("colorizer").attach_to_buffer(0, {
      mode = "background",
      css = true,
    })
  end
})

But I'm facing with other problem. I was trying to make lsp doc window highlighted, so I tried the similar things. The only difference is that filetype is cmp_docs (from nvim-cmp plugin).

Here's the mentioned issue https://github.com/NvChad/nvim-colorizer.lua/issues/28. I'm not sure if it's intentional to not highlight colors in floating buffer window, but the original repo does that, so it's probably be a bug.

karunsiri avatar Oct 07 '22 17:10 karunsiri

Does this issue still exist ?

Akianonymus avatar Oct 14 '22 05:10 Akianonymus

I think I'm having the same problem (I initialize colorizer slightly differently, but my configuration stopped working because of the same commit). I just cloned it and checked the changes one-by-one. The issue is being caused by this line, I think because running COLORIZER_SETUP_HOOK there does something to the way the plugin can be later initialized in autocmds. Removing it causes my setup to work again.

oncomouse avatar Oct 24 '22 21:10 oncomouse

Pull and check again.

Akianonymus avatar Oct 29 '22 04:10 Akianonymus