Taichi
Taichi

Reputation: 2587

How to revert changes in Vim?

I'm editing code in a server using Vim. I pressed J instead of j many times, because CapsLock was enabled. How can I revert the changes made by Js? Pressing u says it is the oldest change.

Upvotes: 4

Views: 9785

Answers (1)

Venkataraman R
Venkataraman R

Reputation: 12959

See the undolevel settings in your session. Type below command to see current undolevels setting.

:set undolevels ?

You can change the setting either in the session or in .vimrc

:set undolevels=1001  # In vi/vim session

set undolevels=1001  # In .vimrc

In vi/vim, you can keep pressing u to undo the changes, based on the undolevels.

In vi/vim, if you want to undo all the changes, since you had last saved, you can do below things.

You can go to command mode by pressing Esc and then give below command

:e! or :edit!

It will clear all the changes in buffer. The file will return to last saved version.

Upvotes: 14

Related Questions