Often, I want to edit multiple different parts of the same file simultaneously. This is usually done with a number of splits. Is there a way such that the undo history in each split is separate? E.g., when editing the file:

a = 2
b = 8

Could I have two splits, alter the first line to a = 3 in the first split, then swap to the second split and set b = 9, then later go back to the first split and press u to undo the a = 3 change while keeping the b = 9 change?

Mentally, I associate each split's work with its own undo/redo buffer, and all of the cursor jumping is a bit of a pain. I understand why it's the way it is, but was hoping there was a mode I could toggle to get the more intuitive behavior. Thanks!

  • Welcome to Vi and Vim! Undo actually tracks the buffer states... While you have an undo tree, Vim doesn't really give you a way to apply (undo) changes out of order... So I don't think what you described actually exists...
    – filbranden
    Nov 19 '20 at 3:17
  • 1
    @filbranden Right, that's what I was afraid of - thanks for confirming! Will leave the question up though, maybe someone has an elaborate Vimscript workaround.
    – Walt W
    Nov 19 '20 at 15:20
  • 1
    More specifically, it seems that something like Mundo might be moddable to create patches to mix & match different undo branches, with each split keeping track of its edits in the undo tree.
    – Walt W
    Nov 19 '20 at 15:41
  • the undo tree is a buffer property, it is not possible to have different undo stacks for the same buffer Nov 20 '20 at 8:19
  • If you split the terminal window and open a separate instance in each window, they will each have their own buffer, but I wouldn't recommend it if you are planning to work on the same file. You would have to bypass the swap warning, and there is a very good reason for that warning. The buffer holds not only the undo history, but the changes that have been made to the file. Unless you are very careful (or you use / automate git creatively) then the result will be the equivalent of a git merge conflict.
    – Nate T
    Sep 11 at 22:57

Your Answer

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

Browse other questions tagged or ask your own question.