Embark on a journey of knowledge! Take the quiz and earn valuable credits.
Take A QuizChallenge yourself and boost your learning! Start the quiz now to earn credits.
Take A QuizUnlock your potential! Begin the quiz, answer questions, and accumulate credits along the way.
Take A QuizKindly log in to use this feature. We’ll take you to the login page automatically.
LoginGeneral Tech Learning Aids/Tools 3 years ago
User submissions are the sole responsibility of contributors, with TuteeHUB disclaiming liability for accuracy, copyrights, or consequences of use; content is for informational purposes only and not professional advice.
No matter what stage you're at in your education or career, TuteeHUB will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.
Kindly log in to use this feature. We’ll take you to the login page automatically.
LoginReady to take your education and career to the next level? Register today and join our growing community of learners and professionals.
Your experience on this site will be improved by allowing cookies. Read Cookie Policy
Your experience on this site will be improved by allowing cookies. Read Cookie Policy
manpreet
Best Answer
3 years ago
I'm trying to understand how to move in the undo tree with the following default mappings:
u,,g-andg+Here's my understanding of things, which is probably wrong or incomplete. Each time we make a new edit, a new leaf is created in the undo tree. The more we make edits, the more leafs are added along a branch.
To move along the branch, we can use
uto go back to the original version of the buffer, andto go forward to the newest version.This can be confirmed with the simple following test:
1,to increment it to2, again to3and again to4Using
uand, we can go back to each state of the buffer: empty,1,2,3and4.If at one point, we go backward and make a new edit from a past leaf, we create a new branch. The leafs which are not between the root of the tree (the original buffer) and the beginning of the new branch (the last edit we just made) can't be accessed with
uand.Going back to the example, this can be confirmed:
4, hituto go back to3r5to replace3with5uto undo the last editThe last
udoesn't bring us back to4but to3.We can't go back anymore to
4withuandbecause they only move along the shortest path between the root of the tree and the most recent version of the buffer which we've visited.4is not on the shortest path between the original empty buffer and5, because5was created from3.To go back to any leaf of the undo tree, we can use
g-andg+. Contrary touand, they move along a time axis on which every leaf is placed in the order it was created.To confirm this:
uup to the original empty bufferg+5 times to reach1,2,3,4and5g-5 times to get back to4,3,2,1and the empty bufferHowever, there's one case I don't understand. If from
5, we hituto get back to3, theng+, we get5. But on the time axis, the nearest leaf from3is not5, it's4.So why does Vim bring us to
5instead of4?