18

In Vim, is there a way to select a block of text and use undo to only undo changes to that block of text?

Let's say I rewrite a function, then go and make some changes elsewhere in my file. Afterwards, I realize that my first function implementation was indeed better. I'd like to undo the changes I made in that function, but leave my subsequent additions intact.

I don't know if this is even possible, but I often find myself wanting this feature.

6
  • I'm sorry I can't help but nice question.
    – lucapette
    Jan 10, 2011 at 0:01
  • I'd love to know if there is a good way to do this. +1
    – gahooa
    Jan 10, 2011 at 0:07
  • 1
    Possibly same question here: stackoverflow.com/questions/2236099/… Jan 10, 2011 at 0:13
  • 3
    I think that's what Git/Mercurial for.
    – tungd
    Jan 10, 2011 at 2:25
  • 2
    Man, I can't even start to consider how Vim would handle this in the background. The undo stack is just that - a stack. If you start messing around with ripping pieces of it out, then it's not longer a stack and you end up with what amounts to a tree with multiple undo paths - very very very ugly.
    – Marc B
    Jan 10, 2011 at 3:55

2 Answers 2

3

Currently... No. Vim 7.3 has undo branches that you can traverse but as far as I know Vim does not pay attention to any selected text during an undo.

-2

Maybe this:

  1. http://sjl.bitbucket.org/gundo.vim/
  2. http://stevelosh.com/blog/2010/09/coming-home-to-vim/
  3. https://github.com/tpope/vim-pathogen

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.