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', '<leader>t', require('toggle').toggle, { desc = 'Toggle word' })- Gets the word under the cursor and checks for a mapping → replaces with
ciw - Falls back to the single character under the cursor → replaces with
r
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.
