color-chameleon.nvim lets you set conditional rules for when a colorscheme should be applied.
These rules are evaluated in order from top-to-bottom; the first matching rule wins.
Rules are triggered on VimEnter, DirChanged, BufReadPost, BufNewFile, BufEnter, and TermOpen events.
✨ Features
- Context-Aware Colorschemes: Automatically switch colorschemes based on:
- Working directory (local vs remote/mounted filesystems)
- Environment variables (colorterm, sudo, TMUX, custom vars)
- Buffer properties (filetype, buffer type)
- Custom functions/conditions (any logic you can write)
- Flexible Logic: Combine conditions with AND logic, use arrays for OR logic
- Smart Switching: Preserves your previous colorscheme when leaving special contexts
- Buffer-Aware: Considers both global working directory and individual buffer paths
- Simple Configuration: Express your workflow through intuitive conditional rules
- Lightweight: Minimal performance impact
👨⚖️ Rule Structure
Each rule can have the following fields:
colorscheme(required: string) – The colorscheme to apply when this rule matches.background(optional: string) – Background setting to apply ("light"or"dark"). Applied before the colorscheme.path(optional: string or array) – Directory path(s) to match (e.g.,"~/mnt/","~/work/client-a/",{"~/work/client-a, "~/work/client-b/"}. Use an array to match any of multiple paths.buftype(optional: string or array) – Buffer type(s) to match (e.g.,"terminal","help", or{"quickfix", "nofile"}). Use an array to match any of multiple buffer types.filetype(optional: string or array) – Buffer filetype(s) to match (e.g.,"markdown","python", or{"lua", "vim"}). Use an array to match any of multiple filetypes.env(optional: table) – Environment variable conditions to check.- Key: environment variable name
- Value:
true= check if variable existsfalse= check if variable doesn’t exist- string = check if variable equals this exact value
condition(optional: function) – Custom function that receives the current working directory and returns a boolean.
rules = {
-- Match multiple filetypes with an array (recommended)
{ filetype = {"json", "yaml", "toml", "xml"}, colorscheme = "onedark" },
-- Or use individual rules
{ filetype = "json", colorscheme = "onedark" },
{ filetype = "yaml", colorscheme = "onedark" },
{ filetype = "toml", colorscheme = "onedark" },
{ filetype = "xml", colorscheme = "onedark" },
-- Or use a condition for complex logic
{
colorscheme = "onedark",
condition = function()
local ft = vim.bo.filetype
return ft == "json" or ft == "yaml" or ft == "toml" or ft == "conf"
end
},
}