Issue
Even without any config, termguicolors is automatically enabled by detecting terminal cpabilities since neovim v0.10.
However, it seems to be enabled after the UI is initialized (e.g., after UIEnter or something like that) and might not be set yet at the time BufReadPre autocmds are executed for the first buffer.
So, with this plugin being lazy-loaded, auto-detection of termguicolor and auto-enabled colorization of the first buffer conflicts.
How to reproduce
Pattern 1: for BufReadPre (with neovim 0.12)
-- init.lua
vim.api.nvim_create_autocmd('BufReadPre', { once = true, callback = function()
vim.pack.add({ 'https://github.com/catgoose/nvim-colorizer.lua' })
require('colorizer').setup({
user_commands = true,
})
end })
Result: Colorizer: Error: &termguicolors must be set
Pattern 2: for UIEnter (with neovim 0.12):
-- init.lua
vim.api.nvim_create_autocmd('UIEnter', { once = true, callback = function()
vim.pack.add({ 'https://github.com/catgoose/nvim-colorizer.lua' })
require('colorizer').setup({
user_commands = true,
})
end })
Result: the first buffer loaded before the UI init is not colorized.
$ echo 'body { background: red; }' >test.css
$ nvim test.css
Note that starting neovim by just nvim and opening the file later by :e test.css makes the file colorized, since the buffer is created after the UI and the plugin are initialized.
Request
I'm not sure how this should be solved, but some candidates are:
- Not aborting when
termguicolors is false, wait for the UI to be initialized and termguicolors is finalized, and then initialize the part that require termguicolors to be true.
- Current:
BufReadPre with termguicolors=false => colorizer plugin loaded => (failed!)
- New:
BufReadPre with termguicolors=false => colorizer plugin loaded => neovim automatically sets termguicolors=true => UIEnter => colorizer initialization and auto-attach resumes!
- Provide a function to "attach to the buffer if the plugin should have attached automatically".
- Note that
require('colorizer').is_buffer_attached(0)) is false at the timing of UIEnter (see below).
require('colorizer').attach_to_buffer() may attach to the buffer anyway, even if the buffer is not in filetypes or even if excluded.
- With this function, user can retry auto-attach manually at after
require('colorizer').setup().
- Doing this automatically in
require('colorizer').setup() is also good?
-- init.lua
vim.api.nvim_create_autocmd('UIEnter', { once = true, callback = function()
vim.pack.add({ 'https://github.com/catgoose/nvim-colorizer.lua' })
require('colorizer').setup({
user_commands = true,
})
vim.print(require('colorizer').is_buffer_attached(0))
end })
With this config, nvim test.css may print false, and require('colorizer').reload_all_buffers() don't enable the highlight for test.css.
Issue
Even without any config,
termguicolorsis automatically enabled by detecting terminal cpabilities since neovim v0.10.However, it seems to be enabled after the UI is initialized (e.g., after
UIEnteror something like that) and might not be set yet at the timeBufReadPreautocmds are executed for the first buffer.So, with this plugin being lazy-loaded, auto-detection of
termguicolorand auto-enabled colorization of the first buffer conflicts.How to reproduce
Pattern 1: for
BufReadPre(with neovim 0.12)Result:
Colorizer: Error: &termguicolors must be setPattern 2: for
UIEnter(with neovim 0.12):Result: the first buffer loaded before the UI init is not colorized.
Note that starting neovim by just
nvimand opening the file later by:e test.cssmakes the file colorized, since the buffer is created after the UI and the plugin are initialized.Request
I'm not sure how this should be solved, but some candidates are:
termguicolorsisfalse, wait for the UI to be initialized andtermguicolorsis finalized, and then initialize the part that requiretermguicolorsto betrue.BufReadPrewithtermguicolors=false=> colorizer plugin loaded => (failed!)BufReadPrewithtermguicolors=false=> colorizer plugin loaded => neovim automatically setstermguicolors=true=>UIEnter=> colorizer initialization and auto-attach resumes!require('colorizer').is_buffer_attached(0))is false at the timing ofUIEnter(see below).require('colorizer').attach_to_buffer()may attach to the buffer anyway, even if the buffer is not infiletypesor even if excluded.require('colorizer').setup().require('colorizer').setup()is also good?With this config,
nvim test.cssmay printfalse, andrequire('colorizer').reload_all_buffers()don't enable the highlight for test.css.