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

Bug: Plugin does not attach on initial buffer if lazy loaded

Open gregorias opened this issue 2 years ago • 1 comments

Describe the bug Plugin does not attach on initial buffer if lazy loaded with Lazy.

To Reproduce

Using Lazy plugin manager, configure your nvim-colorizer like so:

  { 'NvChad/nvim-colorizer.lua',
    config = function() require'colorizer'.setup{} end,
    event = 'VeryLazy',
  },

Then, create a sample file:

echo "#111" > foo

Open it with Neovim:

nvim cos

You won't see #111 colorized.

Expected behavior

#111 is colorized.

Colorizer Version: dde3084106a70b9a79d48f426f6d6fec6fd203f7

Additional context I've added the following to my config to address this issue, but I think it'd be worthwhile to just do it upstream in setup.

	{ 'NvChad/nvim-colorizer.lua',
		config = function()
			local c = require'colorizer'
			c.setup{}

			-- nvim-colorizer doesn't work on the initial buffer if we lazy load, so force it to attach
			-- on load.
			local bufnr = vim.api.nvim_get_current_buf()
			if bufnr and not c.is_buffer_attached(bufnr) then
				c.attach_to_buffer(bufnr)
			end
		end,
		event = 'VeryLazy',},

gregorias avatar Apr 02 '23 11:04 gregorias

This is also the case when you do lazy = true instead of event = "VeryLazy".

Workaround: Use neither of those options or event = { "BufReadPost", "BufNewFile" },

sscherfke avatar May 23 '23 07:05 sscherfke