A Neovim plugin to toggle words under the cursor to their counterpart (e.g., true → false, public → protected → private).
use({ 'leblocks/toggle.nvim', })
require('toggle').setup({
-- Include built-in toggle pairs (default: true)
defaults = true,
-- Restore cursor position after toggling a word (default: true)
keep_cursor_position = true,
-- Additional toggle pairs (merged with defaults)
mappings = {
{ 'yes', 'no' },
{ 'foo', 'bar', 'baz' }, -- cycles: foo → bar → baz → foo
},
})
| Option | Type | Default | Description |
|---|---|---|---|
defaults |
boolean | true |
Include built-in toggle pairs |
keep_cursor_position |
boolean | true |
Restore cursor position after toggling a word |
mappings |
table | {} |
Additional toggle pairs to register |
vim.keymap.set({ 'n', 'v' }, '<leader>t', require('toggle').toggle, { desc = 'Toggle word' })
vim.keymap.set({ 'n', 'v' }, '<leader>T', function() require('toggle').toggle(true) end, { desc = 'Toggle word (backward)' })
toggle.toggle() checks replacers in this order (first match wins):
cWORD (ciW)cword (ciw)ce) for cases like goto_prev → goto_nextr)Pass true to toggle backwards in the mapping cycle:
require('toggle').toggle(true)
Mappings are circular: for a group like { 'public', 'protected', 'private' }, each value cycles to the next, and the last wraps to the first.
See lua/toggle/defaults.lua for the full list of built-in toggle pairs.