Environment

  1. MacOS Tahoe on Macbook Air M3
  2. neovim: 0.11.4
  3. Color theme: Kanso
  4. Related plugins:

Problem

I tried to use vim.api.nvim_set_hl to config the appearance of telescope, especially the matching color of the text when I was trying to search files or live grep.

The code block I used was as following:

vim.api.nvim_set_hl(0, 'TelescopeTitle', { fg = '#5C6066' })
vim.api.nvim_set_hl(0, 'TelescopePromptNormal', { fg = '#5C6066' })
vim.api.nvim_set_hl(0, 'TelescopePromptBorder', { fg = '#5C6066' })
vim.api.nvim_set_hl(0, 'TelescopeResultsNormal', { fg = '#A4A7A4' })
vim.api.nvim_set_hl(0, 'TelescopeResultsBorder', { fg = '#5C6066' })
vim.api.nvim_set_hl(0, 'TelescopePreviewNormal', { fg = '#5C6066' })
vim.api.nvim_set_hl(0, 'TelescopePreviewBorder', { fg = '#5C6066' })
vim.api.nvim_set_hl(0, 'TelescopeMatching', { fg = '#C4746E', bold = true })

I tried to put the above code block in options.lua (main config files of my nvim), in telescope.lua (config file of telescope plugin). Unfortunately, nothing happened.

Then, I appended the code block into the kanso.lua (config file of kanso plugin), after use KansoCompile, it worked until I quit and started nvim again. In several weeks (I’m a little busy during that period), ran KansoCompile is the very first thing I did when I started using nvim.

Solution

This afternoon, I decided to solve this problem. After asking AIs, I got nothing but mess. So I reviewed the Kanso’s configuration document carefully, and found a suspicious part:

overrides = function(colors)
    return {}
end,

Finally, I got rid of the need to run KansoCompile every time I start nvim , and it started working just as I expected.

# kanso.lua

overrides = function(colors) -- add/modify highlights
  return {
    TelescopeTitle = { fg = '#5C6066' },
    TelescopePromptNormal = { fg = '#5C6066' },
    TelescopePromptBorder = { fg = '#5C6066' },
    TelescopeResultsNormal = { fg = '#A4A7A4' },
    TelescopeResultsBorder = { fg = '#5C6066' },
    TelescopePreviewNormal = { fg = '#5C6066' },
    TelescopePreviewBorder = { fg = '#5C6066' },
    TelescopeMatching = { fg = '#C4746E', bold = true },
  }
end,