- Lua 100%
project-color-nvim #
A Neovim plugin that persists your current theme using nvim-project-config, allowing you to maintain consistent color schemes across different projects and sessions.
Features #
- Automatically loads theme from project config on startup
- Tracks and persists theme changes using nvim-project-config
- Stores theme in
color-persistkey in project JSON - Works with any Neovim colorscheme
Installation #
Using lazy.nvim:
{
'rektide/project-color',
dependencies = { 'rektide/project-settings-nvim' },
}
Using packer.nvim:
use {
'rektide/project-color',
requires = { 'rektide/project-settings-nvim' },
}
Auto-setup: Plugin automatically runs setup() with defaults on startup. If you want to configure options, disable auto-setup first:
vim.g.project_color_nvim_autosetup = false
require('project-color-nvim').setup({
enabled = true,
autoload = true,
persist = true,
})
Configuration #
Plugin automatically runs setup() with defaults on startup. To customize options, disable auto-setup first:
vim.g.project_color_nvim_autosetup = false
require('project-color-nvim').setup({
enabled = true,
autoload = true,
persist = true,
key = 'color-persist',
})
Options:
| Option | Type | Default | Description |
|---|---|---|---|
enabled |
boolean | true |
Enable/disable plugin. When false, plugin does nothing. |
autoload |
boolean | true |
Automatically load theme from project config on startup. When false, plugin watches changes but doesn't load a theme. |
persist |
boolean | true |
Persist theme changes to project config. When false, plugin loads theme but doesn't write changes. |
key |
string | 'color-persist' |
JSON key name to store theme in project config. |
How It Works #
Load Flow #
The plugin checks for theme in project config when Neovim starts:
Theme Change Flow #
When you change your theme, the plugin updates the project config:
Architecture #
The plugin uses nvim-project-config for all configuration persistence:
Module Structure #
lua/project-color-nvim/
├── init.lua - Main plugin entry point and orchestration
├── config.lua - Plugin configuration management
├── theme.lua - Theme retrieval and colorscheme loading
└── autocmds.lua - Autocmd setup and event handling
Module Responsibilities #
config.lua
- Defines default plugin configuration
- Handles
setup(opts)- merges user options with defaults - Provides configuration validation
theme.lua
- Retrieves current theme name from Neovim
- Loads a specified colorscheme
- Handles theme loading errors gracefully
- Provides wrapper around
vim.g.colors_nameandvim.cmd.colorscheme
autocmds.lua
- Sets up
ColorSchemeautocmd listener - Manages plugin lifecycle events
- Coordinates theme persistence on theme changes using nvim-project-config
init.lua
- Main entry point for the plugin
- Orchestrates the initialization sequence
- Coordinates loading theme from project config on startup
- Exports public API (
setup()) - Connects all modules together
Usage #
- Ensure you have nvim-project-config installed and configured
- Start Neovim in your project directory
- The plugin will automatically load the theme stored in the
color-persistkey of your project config - When you change your theme with
:colorscheme <name>, the plugin updates thecolor-persistkey in your project config
For detailed technical specification of how project-color-nvim integrates with nvim-project-config, see doc/projectconfig.md.
License #
MIT