Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you undo setting an option in vim?

Tags:

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?

like image 504
num1 Avatar asked Dec 13 '13 21:12

num1


People also ask

What does Ctrl d do in Vim?

VIM mode - Ctrl+D cursor then deletes the line.

How do I undo Ctrl Z in Vim?

You can use the u button to undo the last modification. (And Ctrl + R to redo it).


2 Answers

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!
like image 116
Ben Klein Avatar answered Oct 11 '22 02:10

Ben Klein


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.

like image 42
glts Avatar answered Oct 11 '22 02:10

glts