6

I seem to be unable to undo something in a file I saved, despite that the history of changes shows up with I press :changes. So the change history is known to vim but I cannot access it?

I thought it was possible to go back to previous changes even after you save the file, but perhaps I am wrong. I also the get the "Already at" message with g- and g+.

filbranden
  • 28,785
  • 3
  • 26
  • 71
johnbakers
  • 161
  • 3
  • 2
    You should be able to navigate the undo history independently from saving or not. You could have a look at :h :undolist to make sure you have things to undo. You should also have a look at how to debug my vimrc in case the issue comes from your configuration. Finally you should give us a detailed list of the actions you are doing (e.g. open a new buffer, append text, save with :w, press u), the results you got and the results you expected. This would be easier to help you debug this. – statox Jul 02 '20 at 07:55

1 Answers1

11

The change list is a different thing from the undo list.

The change list is a list of locations of changes, and it can be viewed with :changes and navigated with e.g. g; and g,.

The g+ and g- commands that you’re using move instead through the undo list. This is a tree of different file states: it’s what you are navigating when you undo and redo changes. The undo list can be viewed with :undolist.

Vim only persists the undo list between sessions when you have undo persistance switched on: it is switched off by default.

Try adding set undofile to your .vimrc or read the documentation at :help undo-persistence for full details.

Rich
  • 31,891
  • 3
  • 72
  • 139