How do I quickly toggle options and navigate lists using bracket mappings in Vim?
Answer
[on / ]on / yon
Explanation
The vim-unimpaired plugin by Tim Pope provides a consistent set of bracket-based mappings for toggling Vim options, navigating paired lists, and performing common line operations. Instead of memorizing verbose :set commands, you get intuitive [ and ] shortcuts that follow a memorable pattern.
Option toggling
Unimpaired uses the pattern [o, ]o, and yo followed by a letter to enable, disable, and toggle Vim options:
[os " enable spell check (:set spell)
]os " disable spell check (:set nospell)
yos " toggle spell check (:set spell!)
[on " enable line numbers
]on " disable line numbers
yon " toggle line numbers
[or " enable relative numbers
]or " disable relative numbers
yor " toggle relative numbers
[ow " enable line wrapping
]ow " disable line wrapping
yow " toggle line wrapping
[oh " enable search highlighting
]oh " disable search highlighting
yoh " toggle search highlighting
[oc " enable cursorline
]oc " disable cursorline
yoc " toggle cursorline
[ox " enable cursorline AND cursorcolumn (crosshairs)
]ox " disable crosshairs
yox " toggle crosshairs
[ol " enable list mode (show invisible characters)
]ol " disable list mode
yol " toggle list mode
The mnemonic is: [ turns on (opening bracket = start), ] turns off (closing bracket = end), and y toggles (flip).
Navigation pairs
Unimpaired provides [ and ] mappings for navigating paired lists:
[q / ]q " previous/next quickfix entry (:cprev / :cnext)
[Q / ]Q " first/last quickfix entry (:cfirst / :clast)
[l / ]l " previous/next location list entry
[L / ]L " first/last location list entry
[b / ]b " previous/next buffer
[B / ]B " first/last buffer
[a / ]a " previous/next file in the argument list
[A / ]A " first/last file in the argument list
[t / ]t " previous/next tag
[T / ]T " first/last tag
Line manipulation
Unimpaired also adds commands for inserting blank lines and moving lines:
[<Space> " add a blank line above the current line
]<Space> " add a blank line below the current line
[e " move the current line up (exchange with line above)
]e " move the current line down (exchange with line below)
These accept counts: 3[e moves the current line up 3 positions.
Tips
- All unimpaired mappings accept counts:
3]qjumps forward 3 quickfix entries,5]<Space>inserts 5 blank lines below - The
[eand]eline-move mappings work in visual mode too, letting you move selected blocks up and down - Unimpaired is a lightweight plugin with zero configuration — install and it works immediately
- Many Neovim distributions (like LazyVim) include unimpaired-style mappings by default because they are so universally useful