Skip to main content

Questions tagged [undo-redo]

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

Filter by
Sorted by
Tagged with
57 votes
1 answer
23k views

How can I use the undofile?

The last news item on vim.org talks about using the 'undofile' to save your history and undo changes even after a reboot: A feature I enjoy using myself is not known to many users, as I found out ...
user avatar
33 votes
3 answers
15k 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 ...
mrzool's user avatar
  • 1,022
20 votes
1 answer
2k 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?
Nathan Long's user avatar
19 votes
1 answer
774 views

Difference between g- and u

g- is Return to older text state, and u is Undo change. I don't get it.
hgiesel's user avatar
  • 1,944
18 votes
5 answers
912 views

Can I be notified when I'm undoing changes from the undofile?

I've been using the undofile feature in Vim for a while now. It's a very nice feature. However, one annoyance is that it's very easy to accidentally undo changes that I did the last time I opened the ...
Martin Tournoij's user avatar
15 votes
3 answers
625 views

How do you use changes tree in vim?

Is it possible to retrieve changes branch that I "abandoned"? For example, I am undoing several operations using u, then I am making a change in insert mode. But then I realize I don't want ...
Nebril's user avatar
  • 3,497
15 votes
3 answers
10k views

Can I undo multiple times in nvi and/or the original vi?

Sometimes I'm on a system without Vim, and use the default nvi (BSD systems) or the original vi (Arch Linux). There are quite a few differences, but the largest annoyance is that I can undo only my ...
Martin Tournoij's user avatar
14 votes
4 answers
2k views

How can I safely undo changes that I may or may not have made?

Too often do I make the mistake of typing with the wrong window focused (and have done so a few times with a USB authenticator). In programs with lots of hotkeys enabled (Gmail, VLC, Vim), this often ...
JohnB's user avatar
  • 245
13 votes
1 answer
2k views

How to change undo granularity in Vim?

At some point my Vim would undo an entire word when I hit u. [i]typing some words[C-c][u] Would result in typing some However, the undo granularity seems to have changed to deleting one letter at ...
Dan Prince's user avatar
13 votes
3 answers
1k 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 ...
tjbrn's user avatar
  • 563
12 votes
2 answers
478 views

Search all versions of a file in the undo tree

Is there an easier way to find a particular change in Vim's undo tree than just looking at random old versions of the file one at a time (either using vanilla VIM commands, Gundo, or another plugin)? ...
Kyle Strand's user avatar
11 votes
3 answers
1k 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 | ...
user avatar
9 votes
2 answers
3k 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 :...
cauthon14's user avatar
  • 193
9 votes
2 answers
657 views

Break the undo sequence in normal mode

Question: Is there something which is works same as i_CTRL-G_u, but for normal mode? This would be useful in mappings (like nnoremap), because (I think, but fixme) in normal mode, if you are just ...
Attilio's user avatar
  • 369
8 votes
1 answer
5k views

How to cache file editing history in Vim, that it would not disappear after switching the file?

When I open another file in a Vim session all editing history for the other files disappears. Is it possible to configure Vim that it would automatically save and restore file editing history when ...
niekas's user avatar
  • 1,655
8 votes
2 answers
229 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. ...
Dmiters's user avatar
  • 181
7 votes
1 answer
205 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 ...
silviubogan's user avatar
7 votes
2 answers
628 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 :-(
Alec Jacobson's user avatar
6 votes
1 answer
2k 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 ...
johnbakers's user avatar
6 votes
3 answers
468 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 ...
Wildcard's user avatar
  • 4,429
6 votes
1 answer
385 views

What does undo undo?

The undo command feels a bit random. Sometimes it undoes massive chunks, sometimes tiny changes. How is the cut-off point determined?
samuelnihoul's user avatar
5 votes
2 answers
278 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 ...
GreenSaguaro's user avatar
5 votes
1 answer
4k 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> ...
god's user avatar
  • 53
5 votes
1 answer
3k 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 ...
Octaviour's user avatar
  • 982
5 votes
1 answer
60 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?
Yossi Gil's user avatar
  • 755
5 votes
2 answers
332 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 ...
Martin Tournoij's user avatar
4 votes
2 answers
185 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 ...
Paul92's user avatar
  • 197
4 votes
1 answer
1k views

Undo multiple changes in Cygwin's vim

I have two installations of vim: 7.4 in cygwin and 7.2 in a Linux virtual machine. The vim in the virtual machine can undo multiple edits by repeatedly pressing the u key. The vim in cygwin can only ...
Rusty Lemur's user avatar
4 votes
1 answer
204 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 ...
ChatterOne's user avatar
4 votes
0 answers
2k 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-...
Giorgio Robino's user avatar
3 votes
2 answers
2k 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?
geza's user avatar
  • 133
3 votes
1 answer
448 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, ...
yo''s user avatar
  • 1,151
3 votes
2 answers
91 views

Undo-joining a mapping that uses the expression register

I'm trying to make semi-automatic parentheses work using vim-arpeggio and ultisnips. Everything works fine except the undo story. What I have now is this: Arpeggioinoremap () ()<c-r>=UltiSnips#...
user3240588's user avatar
3 votes
2 answers
258 views

visualize Vim undo history

Is there for Vim what Gource is for Git, to visualize Vim undo history? I'm familiar with Gundo, which display diffs of undo history, but it's not really a visualizer like Gource for Git repos.
Geremia's user avatar
  • 966
3 votes
1 answer
378 views

How to undo in ctrl-x mode?

Let's say I just completed following path using Ctrl-x, Ctrl-f (twice) and I haven't exited the Ctrl-x mode yet and I got /home/john.doe/ Let's say I chose john.doe accidentally and actually want to ...
flawr's user avatar
  • 185
3 votes
1 answer
708 views

Vim undofile does not work when file is too long

I use a vim persistent undo setup as follows, which have worked all that way here. set undofile set undodir=~/.vim/undodir However now I'm facing a problem when the undofile became too long, notice ...
intmarinoreturn0's user avatar
3 votes
1 answer
598 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. ...
Yoric's user avatar
  • 133
3 votes
1 answer
2k 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 ...
bagrat's user avatar
  • 133
2 votes
2 answers
170 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 ...
LuxGiammi's user avatar
  • 207
2 votes
1 answer
109 views

U (undo line) doesn't work on single line buffer

I am working through the user manual, doing the examples on a Mac using Vim (comes bundled with MacVim) on the terminal and was doing fine with undo (Chapter 2). Then with undo line or U, when doing ...
Miguel Cortes's user avatar
2 votes
1 answer
314 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 ...
ChocolateOverflow's user avatar
2 votes
2 answers
106 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 ...
Jérémie Wenger's user avatar
2 votes
1 answer
147 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 ...
Circonflexe's user avatar
2 votes
1 answer
89 views

Disabling undodir and backupdir for specific paths

My email client creates files in /tmp and my password manager under /dev/shm when editing. The first is just unnecessary to store the undos for longer than the lifetime of the file, the latter is ...
fbence's user avatar
  • 697
2 votes
2 answers
74 views

What does this output means (in vim) when I do/undo and redo?

Whenever I do undo and redo in vim, I saw this output, the #number changes.. but what is it ? Where to see the #number .. ? Also, I find it hard to know what. I have accidentally changed or undo ...
andrew_ysk's user avatar
2 votes
1 answer
60 views

Alternative to Gundo tree that avoid messing up my window layout

There are several plugins which open a window on the left or right side, nerdtree and tagbar being just to examles. And then there's gundo, the functionality of which is invaluable, but lord... it ...
Enlico's user avatar
  • 2,224
2 votes
1 answer
908 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 ...
rranjik's user avatar
  • 135
2 votes
2 answers
347 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 ...
nobe4's user avatar
  • 16.1k
2 votes
1 answer
530 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($...
Jim Hessin's user avatar
2 votes
0 answers
37 views

Method for each split to have its own undo buffer?

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., ...
Walt W's user avatar
  • 121