16

g- is Return to older text state, and u is Undo change. I don't get it.

18

Check out vim's documentation on undo branches. u is essentially going to take you back to the parent of the current node, whereas g- allows you to traverse the current node's siblings before traversing to the root of the branch. Each node represents a change in the file. The documentation's description is a bit obscure but that is how I understand it. You might find this explanation of undo branches to be easier to understand.

Example Scenario
I will use the following notation to explain the current structure of the undo tree:

[{parent} --> ({child}, {sibling})]

  1. Open a text file. [root]
  2. Make a change A. [root --> A]
  3. Leave insert mode and make another change B. [root --> A --> B]
  4. Undo B with the u key. [root --> A --> B]
  5. Make a new change C. [root --> A --> (B, C)]

Pressing u at this point would take you back to change A. Pressing g-, on the other hand, would take you to change B.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.