num1
num1

Reputation: 4965

How do you undo setting an option in vim?

I often call

:set spell

only to immediately call

:set nospell

once I've corrected the word I was unsure of.

I can make this faster by mapping both commands, but I'm looking for a more general way to speed this up. Is it possible to undo the last option :set?

Upvotes: 15

Views: 9653

Answers (2)

glts
glts

Reputation: 22684

Strictly speaking, no, you cannot undo setting a setting in Vim.

But boolean options like 'spell' can be toggled with either one of

:set spell!
:set invspell

In interactive use there is generally no need to specifically :set spell or :set nospell. Toggling is more convenient and can be immediately "undone" with the @: command.

Non-boolean options can be undone by resetting them to their factory values – say, if you have messed up some setting and wish to revert. Example:

:set formatoptions&

A & appended to the option name resets it to its default value.


The solution explained in this answer is also documented in vim-help, in case you forget and need to find it again in the future:

:help set-default

Upvotes: 19

Ben Klein
Ben Klein

Reputation: 1949

I don’t know that you can undo the setting of an option, but in the case of an on / off option such as spell, you can toggle it with a ! at the end of the option name:

:set spell!

Upvotes: 16

Related Questions