vimtricks.wiki Concise Vim tricks, one at a time.

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 / ]o variants are useful in mappings or scripts where you want to force a specific state rather than toggle.
  • yob toggles between background=light and background=dark, which is handy for switching color scheme variants.
  • vim-unimpaired also adds [q/]q for quickfix navigation, [b/]b for buffer cycling, [l/]l for location list, and many more bracket pairs — see :help unimpaired.

Next

How do I open the directory containing the current file in netrw from within Vim?