How do I toggle common Vim options like spell, wrap, and number with single keystrokes using vim-unimpaired?
Answer
yos, yow, yol, yon, yoh
Explanation
The vim-unimpaired plugin adds a set of paired bracket mappings, including a powerful family of option toggles. Every toggle follows the pattern yo{letter}, where [o{letter} enables the option and ]o{letter} disables it. These make frequently-toggled settings one-keystroke operations instead of :set commands.
How it works
The yo family (toggle), [o family (enable), and ]o family (disable) cover the most common boolean options:
| Keys | Option toggled |
|---|---|
yon / [on / ]on |
'number' |
yor / [or / ]or |
'relativenumber' |
yow / [ow / ]ow |
'wrap' |
yos / [os / ]os |
'spell' |
yol / [ol / ]ol |
'list' |
yoh / [oh / ]oh |
'hlsearch' |
yoc / [oc / ]oc |
'cursorline' |
yob / [ob / ]ob |
'background' (light/dark) |
Example
yon " toggle line numbers on/off
yow " toggle soft wrapping
yos " toggle spell checking
yoh " toggle search highlighting
Tips
- The
[o/]ovariants are useful in mappings or scripts where you want to force a specific state rather than toggle. yobtoggles betweenbackground=lightandbackground=dark, which is handy for switching color scheme variants.- vim-unimpaired also adds
[q/]qfor quickfix navigation,[b/]bfor buffer cycling,[l/]lfor location list, and many more bracket pairs — see:help unimpaired.