Questions tagged [undo-redo]

Question about navigation in the undo history, undoing, and redoing changes

Filter by
Sorted by
Tagged with
1
vote
1answer
23 views

Undo <count> macro instances

Often I would record a macro and run it till end of file like 200@q. However, there may be a few lines/instances at the bottom I don't want to run the macro on (like 5 lines). Pressing u would undo ...
4
votes
1answer
338 views

Why does Vim say “Already at newest change” despite a full “changes” history list?

I seem to be unable to undo something in a file I saved, despite that the history of changes shows up with I press :changes. So the change history is known to vim but I cannot access it? I thought it ...
0
votes
1answer
28 views

how do you undo a few operations in the vi editor

i have just tried something of which i don't know how it worked out but thanks it did. i have been trying to undo a few operations of dl which deleted a few letters. it didn't work as it kept on ...
7
votes
2answers
41 views

Possible to rename file and maintain undo?

Is there a way to rename/copy/move a file and maintain the vim persistent undo information? If I do :w new-file-name and then :e new-file-name I can't hit u to undo. Already at oldest change :-(
2
votes
2answers
50 views

Plugin to edit whole datasets/projects

I'm using vim all the time for text editing these days, and have a particular use case: editing a dataset using successive commands. The main problem, as often, is fixing things, ideally rather ...
8
votes
1answer
591 views

How can I undo `zg`?

I'm checking spelling in a document. I find a misspelled word and intend to press z= to get suggestions, but I accidentally press zg, marking this as a "good" spelling. How can I undo that?
2
votes
1answer
77 views

Persistent undo erases my file

I have been trying to get persistent undo to work for over a day now. I keep having a quite unusual bug. I tried the following: " Let's save undo info! if !isdirectory($HOME."/.vim") call mkdir($...
0
votes
1answer
34 views

How do I receive an alert message indicating that persistent undo will be ignored?

I am using Vim 7.4. According to vim's help on persistent undo: An undo file is also ignored if its owner differs from the owner of the edited file. Set 'verbose' to get a message about that when ...
1
vote
0answers
29 views

partial redo/undo [duplicate]

when writing the following line a word by word: word1 word2 word3 I want to be able to undo like this: word1 word2 word word1 word2 wor word1 word2 w ... If I use u, it will remove the entire line....
0
votes
0answers
42 views

How to undo all changes in current session when undofile is on? [duplicate]

Without 'undofile', one can hold u or execute undo 0. With 'undofile', everything changed, hold u will undo changes made in older sessions, undo 0 will undo the entire undo history, they became ...
0
votes
0answers
44 views

“earlier 1f” broke if I save twice?

To reproduce it : make first change. save make second change. save save (I have a bad habit to save twice sometimes.) execute :earlier 1f , both changes lost. What's even weird is that you need to ...
2
votes
0answers
38 views

make u (undo) also reset . (repeat last command)?

Sometimes I make a change, then in my scramble to move to somewhere else that I want to repeat the change, I accidentally make some edit (e.g. ill). I would normally undo the accidental edit with u, ...
2
votes
1answer
183 views

Reduce size of undo file

I had a very large (14 digit) decimal number in my (Windows) clipboard. I had vim open in normal mode on the command line at the time. Accidentally, I pressed some key/mouse combination that caused ...
2
votes
2answers
49 views

Automate breaking of history in insert mode

I started to learn ViM one month ago, so I'm not a ViM expert. My question is: if I make some changes in insert mode (let's say I type some text, then I delete the last two words and finally type ...
5
votes
2answers
183 views

How to make insert mode mapping count as multiple undos?

I have the following mappings: nnoremap # /___<CR>ciw imap # <Esc>:w<CR><Esc># And the following file that I am editing: foo ___ goo ___ hoo ___ The idea is that I start at ...
1
vote
1answer
195 views

Automatic <C-g>u to break undo block? [closed]

What possible downsides are there to using <C-g>u on a regular basis to break the undo chain in small chunks, e.g. after every line-break or after every sentence? Has someone experiences with ...
0
votes
1answer
36 views

Undo to a specific user defined point

I'm using U in normal mode to undo steps in vim, I wonder how to set a sort of a bookmark and create a undo command to undo steps/reverse to the bookmark moment in Vim. This would be nicer than just ...
3
votes
1answer
180 views

Exiting and entering insert mode again with key-binding

I'd like to experiment one of the tip by Drew Neil in his Vimcast, that is to "escape" regularly, so that it gives more granularity to the "undo" command. For example, I write one short sentence. ...
1
vote
2answers
394 views

Show changes since buffer was opened

Is it possible to show all changes made to a buffer since the buffer was opened? This question https://stackoverflow.com/questions/749297/can-i-see-changes-before-i-save-my-file-in-vim is related, ...
0
votes
0answers
28 views

How can I make Vim not remember a command?

I have set up an autocommand, that makes some changes to the file I'm working on, whenever I save. Everything works nice and dandy, except one thing. Whenever I save, and press . afterwards, or undo ...
2
votes
0answers
61 views

“diff”-ing current with “earlier” time

I have a file opened and I know I can do :diffsplit to open the file in a diff view. I also know that I can do something like :earlier 30m to see how the file was 30 minutes ago. My question is: how ...
2
votes
1answer
456 views

How to drop undo history?

Previously (as far as I remember), e! used to drop undo history. Now, I'm using vim 8.0, and e! doesn't drop it. How to drop undo history in vim 8.0?
1
vote
1answer
267 views

How to undo the deletion of characters in insert mode caused by Ctrl-U?

I changed my Caps Lock key to Ctrl, and as I'm still getting used to it I sometimes enter combinations I didn't intend to. While in insert mode typing, having already written most of a long sentence, ...
1
vote
2answers
44 views

Return to current state of file after issuing :earlier command?

Sometimes I want to get back and copy some old code that I deleted and use it. For example, I'll do: :earlier 12h and then yank the deleted code. To get back to where I was, I'll issue a command ...
1
vote
1answer
167 views

Saving .swp/.un~ files to subdirectories

Is there any way to save these files to automatically created subdirs? Google gave me no answers. The reason is simple- I work on several computers which I keep synced via git, so having these files ...
2
votes
0answers
114 views

Bash process substitution on vim command line?

I want to be able to show someone a particular file's undo history in vim, remotely. It's a little complicated, so let me explain one step at a time. For starters, I can set a custom undofile and ...
1
vote
1answer
119 views

Local persistent undo file modeline

I have undodir=~/.vim/undodir such that persistent-undo history files don't clutter my source code directories. However, for one particular source file, I'd like to have its persistent-undo history ...
3
votes
1answer
743 views

Using colon-commands inside ternary expression

I have the following lines in my .vimrc let g = 0 inoremap <silent> <C-g> <C-o>:let g = !g<CR> inoremap <expr> <C-_> <C-o>(g == 0 ? :undo : :redo)<CR> ...
1
vote
0answers
36 views

How to view the command that was just un(re)done

Is it possible to see the sequence of key presses that are undone/redone when using u and Ctrl-r commands?
1
vote
1answer
83 views

Vim - edit last action before using (.)

Related to but not duplicate¹ of Bundling command sequences together for repeat (.). The point (.) command is really useful to redo the last action (insertion, replacement, etc.). Sometimes I find ...
0
votes
1answer
54 views

Vim scp undo clears file

When I open up a file remotely using scp (and possibly other protocols), running the undo command (right away, or repeatedly if I've made edits) clears the file. Why does this happen - is it a bug? ...
6
votes
2answers
150 views

How can I undo an entire command (e.g. d4b), including the motions?

Say I do d4b, then realize I only needed d3b. If I hit u, it'll only undo the d part, and I'll still be 4 words back as if I just did 4b. I'd like to end up exactly where I was before I executed d4b. ...
6
votes
2answers
1k views

Any way to retrieve lost undo tree after closing window (but buffer is still open)

A lot of times, I end up accidentally closing a file with :wq when I only want to do :w. Since I work with multiple tabs and windows, the buffer is still there and I can open it with :ls followed by :...
3
votes
1answer
249 views

Console vim(x): Can I map the scroll wheel to undo--redo?

It's sort-of a follow to a recent XKCD. I want to know whether it's possible to map the scroll wheel to undo and redo, possibly n undos/redos per scroll? I'm using mate-terminal in MATE 1.6.x, bash, ...
1
vote
1answer
1k views

undo last change on current line

I regularly find myself editing some code, encountering an error in a function and then changing the function call and the function itself to debug the problem. Once the problem in the function is ...
14
votes
1answer
485 views

Difference between g- and u

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

Persistent undo not working

I have the following in my .vimrc file: if has('persistent_undo') " Save all undo files in a single location (less messy, more risky)... set undodir=$HOME/.VIM_UNDO_FILES " Save a lot of ...
0
votes
1answer
73 views

How to prevent Vim from clearing history?

Is there way to prevent Vim from clearing history after exiting Vim? I want to be able to see the changes I made, while I am using Gundo (or UndoTree), even though I quit vim and the terminal and ...
10
votes
2answers
678 views

Is it possible to remove an entry from the undo history?

I have these lines in my .vimrc to help with indentation: autocmd BufReadPost * set noexpandtab | retab! 4 autocmd BufWritePre * set expandtab | retab! 4 autocmd BufWritePost * set noexpandtab | ...
5
votes
2answers
246 views

Turn Vim's multiple undo history into git commits?

When refactoring I sometimes do too much at once—all little steps, but I forget to commit after each little change. Of course in many cases a commit after each change would be too much, but if each ...
4
votes
1answer
43 views

Redo earlier edit operation

This is a newbie's question, so please be patient if I do not use the right terms. I know I can use "." to redo my last edit operation. But, is there a way to redo the one just before that?
2
votes
2answers
151 views

Linewise history

We can use the u, <C-R> to undo/redo in Vim and it provides a lot of features to manage the undo tree. But sometimes, I make a change (let say on line 1) and I go do some other changes on ...
5
votes
2answers
223 views

How can I filter a buffer to an external command on save without causing any side effects?

Since importing a package and not using it in Go is a compilation error, fixing the import manually can be a bit of a pain while debugging, so I'm currently using this to fix it up automatically ...
2
votes
1answer
111 views

changenr() + undo does not work as expected

Minimal (not-)working example: fun! Test() let save=changenr() call append(0, "THIS MUST BE UNDONE") exe "undo ".save endfun command! -nargs=0 T :call Test() Now open a file, insert some ...
6
votes
1answer
133 views

How to keep in the undo history just one change for this command?

I want to keep in the undo history just one change for a long command such as: d0kJx. (I took the command from this answer.) This command (d0kJx) does this (The ^ is the cursor position): Before: a ...
3
votes
0answers
1k views

How can I undo last command in command line?

In general, is there a way to UNDO the last "meta" command (I mean a command entered in command line to manage a window ), or some equivalent keystroke sequence ? Btw, I know the u (= undo) and CTRL-...
3
votes
1answer
1k views

Undo diffget in vimdiff

Say I have a merge conflict in Git, and try to resolve it with vimdiff using diff3 view. Here is a screenshot: Now while resolving, I want to diffget once from LO see how it looks like, undo, and ...
23
votes
3answers
8k views

Undo in insert mode

Is there a command to undo the last operation performed while in insert mode? I just pasted text from the wrong register using <C-r>, and I have two options: Delete by hand what I just pasted ...
12
votes
3answers
805 views

Highlighted undo in Vim

I'm trying to have a highlighted undo in Vim, like spacemacs default config. Sometimes when I want quick undo's, I can't realize what changed because it's instantaneous. So I am trying to have ...
4
votes
2answers
173 views

Undo certain modifications

Let's assume I work on a C program file which has 10 functions. During one review, I changed their return types, return values and I added some checks/documentation. After some time I realize that ...