A simple and elegant Neovim plugin that provides a UI for toggling various options using the nui.nvim library.
use {
'markgandolfo/lightswitch.nvim',
requires = { 'MunifTanjim/nui.nvim' }
}
{
'markgandolfo/lightswitch.nvim',
dependencies = { 'MunifTanjim/nui.nvim' },
config = function()
require('lightswitch').setup()
end
}
require('lightswitch').setup({
toggles = {
{
name = "Copilot",
enable_cmd = "Copilot enable",
disable_cmd = "Copilot disable",
state = true -- Initially enabled
},
{
name = "LSP",
enable_cmd = ":LspStart<CR>",
disable_cmd = ":LspStop<CR>",
state = false -- Initially disabled
},
{
name = "Treesitter",
enable_cmd = ":TSEnable<CR>",
disable_cmd = ":TSDisable<CR>",
state = true -- Initially enabled
},
{
name = "Diagnostics",
enable_cmd = "lua vim.diagnostic.enable()",
disable_cmd = "lua vim.diagnostic.disable()",
state = true
},
{
name = "Formatting",
enable_cmd = "lua vim.g.format_on_save = true",
disable_cmd = "lua vim.g.format_on_save = false",
state = false
}
}
})
:LightSwitchShow
j/k: Navigate up and down through toggle options<Space> or <Enter>: Toggle the currently selected option/: Start searching to filter options (updates in real-time as you type)<Esc>: Clear search and return to main window (when in search mode) or close UIq: Close the LightSwitch UI[───⦿ ] (filled circle on right)[⦾───] (empty circle on left)You can add your own toggles using the setup function:
require('lightswitch').setup({
toggles = {
{
name = "My Custom Option",
enable_cmd = ":MyEnableCommand<CR>",
disable_cmd = ":MyDisableCommand<CR>",
state = false
},
-- Add more toggles here
}
})
You can customize the colors used for toggle states:
require('lightswitch').setup({
colors = {
off = "#4a4a4a", -- Dark grey for OFF state (default)
on = "#00ff00" -- Green for ON state (optional, defaults to normal text color)
},
toggles = {
-- your toggles here
}
})
You can also add toggles programmatically:
local lightswitch = require('lightswitch')
lightswitch.add_toggle("Diagnostics", "lua vim.diagnostic.enable()", "lua vim.diagnostic.disable()", true)
LightSwitch supports multiple command formats for enable/disable commands:
Regular Ex commands (default):
enable_cmd = "Copilot enable"
disable_cmd = "Copilot disable"
Commands with key notation (including <CR>):
enable_cmd = ":HighlightColors on<CR>"
disable_cmd = ":HighlightColors off<CR>"
Lua expressions:
enable_cmd = "require('nvim-highlight-colors').turnOn()"
disable_cmd = "require('nvim-highlight-colors').turnOff()"
-- For Telescope
lightswitch.add_toggle("Telescope Preview", "lua vim.g.telescope_preview = true", "lua vim.g.telescope_preview = false", true)
-- For NvimTree
lightswitch.add_toggle("NvimTree Auto", "lua require('nvim-tree.view').View.float.enable()", "lua require('nvim-tree.view').View.float.disable()", false)
-- For Git Signs
lightswitch.add_toggle("Git Signs", "Gitsigns toggle_signs", "Gitsigns toggle_signs", true)
Contributions are welcome! Feel free to open issues or submit pull requests.
MIT