I have a deep appreciation for using different themes, and my initial method for switching themes involved modifying the plugin configuration directly. In the best-case scenario, I utilized the :Telescope colorscheme
command.
To improve this process, I developed a custom function that allowed me to manually input the theme name and apply the corresponding configuration.
Ultimately, I decided to create a plugin that can list themes within a buffer, enabling me to select and apply a theme from that interface directly.
That's how colors.nvim idea was born.
- A nerd font in order to display icons.
- Persistent theme configuration
- Hard-coded theme list
- Append list
- Blacklist
- Fallback default theme
- Enable transparent background (See transparent-backgrounds)
- Callback to run after configuring a theme (useful for reconfiguring plugins like lualine)
Lazy.nvim
Example configuration with Lazy.nvim
{
'kutiny/colors.nvim',
opts = {
enable_transparent_bg = true,
fallback_theme_name = 'evergarden',
hide_builtins = true,
icon = '',
},
cmd = { 'ShowThemes', 'ToggleThemes' },
init = function()
vim.keymap.set('n', '<leader>t', '<cmd>ShowThemes<CR>', { silent = true })
-- or
vim.keymap.set('n', '<leader>t', '<cmd>ToggleThemes<CR>', { silent = true })
end
}
{
append_themes = {},
border = 'single',
callback_fn = function () end,
enable_transparent_bg = false,
height = 8,
hide_builtins = true,
ignore_themes = {},
theme_list = nil,
icon = '',
title = ' My Themes ',
title_pos = 'center',
width = 70,
}
configuration | explanation | default |
---|---|---|
append_themes | If you want to manually append themes to the list | {} |
border | Window border, See window configuration | rounded |
callback_fn | Function to execute after configuring a theme | empty function |
enable_transparent_bg | See transparent backgrounds | false |
height | Window height | 8 |
hide_buildtins | Hide builtin themes from the list | true |
ignore_themes | Remove items from list | {} |
theme_list | Hard-coded theme list | nil |
icon | Icon to show before theme names | |
title_pos | Window title position, See window configuration | 'center' |
title | Window title, See window configuration | ' Themes ' |
width | Window width | 70 |
If you want to remove the icon set the property icon
to an empty string.
This plugin uses the following configuration in order to enable transparent backgrounds.
vim.api.nvim_set_hl(0, "Normal", { bg = "none" })
vim.api.nvim_set_hl(0, "NormalFloat", { bg = "none" })
I use lualine in my config and I noticed that lualine colors are missing or wrong after configuring a new theme. The solution was to re-configure lualine in the callback_fn configuration
{
'kutiny/colors.nvim',
opts = {
callback_fn = function()
require('lualine').setup()
end
},
}