Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a block undo in VIM?

Tags:

undo

vim

block

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.

like image 381
justin Avatar asked Jan 09 '11 23:01

justin


People also ask

Is there undo in Vim?

Remember, yo undo a change in Vim / Vi use the command u , and to redo a change which was undone use Ctrl-R .

How many times can you use the Vim undo command?

2 Answers. Show activity on this post. You have only 1 level of undo if you are in Vi compatible mode. You are missing out on a number of features by being in 'compatible' mode.

What does Ctrl Z do in Vim?

Hit ctrl-z, and fire up vim with the new stuff you want. When you're done, quit the current vim session and come back to your old context with `fg`. The key observation is this stacks inductively, so you cant tumble down the dependency rabbit hole and always come back to the context you were at originally.

How do I undo changes in Linux?

Linux (like other unices) doesn't natively provide an undo feature. The philosophy is that if it's gone, it's gone. If it was important, it should have been backed up. There is a fuse filesystem that automatically keeps copies of old versions: copyfs.


1 Answers

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.

like image 148
Mark Amerine Turner Avatar answered Oct 06 '22 00:10

Mark Amerine Turner