echasnovski / mini.nvim

Library of 40+ independent Lua modules improving overall Neovim (version 0.8 and higher) experience with minimal effort
MIT License
5.02k stars 185 forks source link

mini.cursorword: Could not change the color of MiniCursorword and MiniCursorwordCurrent #862

Closed liangkarl closed 5 months ago

liangkarl commented 5 months ago

Contributing guidelines

Module(s)

mini.cursorword

Description

Following the mini.cursorword manual, :hi! MiniCursorwordCurrent guifg=NONE guibg=NONE gui=NONE cterm=NONE

I have append below highlight command converted into lua in my init.lua file.

m.highlight("MiniCursorword", { fg = 'tomato', ctermfg = 'Red' })
m.highlight("MiniCursorwordCurrent", { fg = 'tomato', ctermfg = 'Red' })

-- m.highlight is a helper function of api.nvim_set_hl()
--
-- M.highlight = function(name, opts)
--  opts = opts or {}
--  return api.nvim_set_hl(opts.buffer or 0, name, opts)
-- end

However, it doesn't work. it seems like the default mini.cursorword configuration that is written in autocmd event colorscheme always overrides my configs, even I place them in the last line of my init.lua. I could not find a better way to fix this except modify plugin itself. Could anyone give me a hand? Thanks!

Neovim version

0.9.5

Steps to reproduce

  1. Append :highlight to change color in init.lua
  2. nvim
  3. (The color didn't change)

Expected behavior

The cursorword color should be changed after I write the setting into the init.lua

Actual behavior

The cursorword color didn't change

echasnovski commented 5 months ago

I can not reproduce with just the information from the issue.

Having equivalent of m.highlight("MiniCursorword", { fg = 'tomato', ctermfg = 'Red' }) and m.highlight("MiniCursorwordCurrent", { fg = 'tomato', ctermfg = 'Red' }) is enough for me to show cursorwords in red color.

My first guess is that those highlight groups are changed by the color scheme, which is later loaded.

This is how you can verify where the highlight group was defined:


Side note: vim.api.nvim_set_hl() takes not a buffer id as first argument, but a namespace id (created with vim.api.nvim_create_namespace()) or 0 for a "global namespace".