-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Mark Gandolfo edited this page Jun 9, 2025
·
3 revisions
A simple and elegant Neovim plugin that provides a UI for toggling various options using the nui.nvim library.
lightswitch.nvim.webm
- Toggle various Neovim commands/options through a sleek slider UI interface
- Navigate through options and toggle them on/off with intuitive slider controls
- Search functionality to filter visible options
- Fully customisable with your own toggles
- Neovim >= 0.7.0
- nui.nvim
Using packer.nvim
use {
'markgandolfo/lightswitch.nvim',
requires = { 'MunifTanjim/nui.nvim' }
}Using lazy.nvim
{
'markgandolfo/lightswitch.nvim',
dependencies = { 'MunifTanjim/nui.nvim' },
config = function()
require('lightswitch').setup()
end
}- Set up the plugin with your desired toggles:
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
}
}
})- Open the LightSwitch UI:
: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 UI -
q: Close the LightSwitch UI
- Slider representation for toggle state:
- ON:
[───⦿ ](filled circle on right) - OFF:
[⦾───](empty circle on left)
- ON:
- Search filtering for quick access to specific toggles
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 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