Questions tagged [undo-redo]
Question about navigation in the undo history, undoing, and redoing changes
84
questions
5
votes
1
answer
3k
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
0
answers
39
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
1
answer
139
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
1
answer
80
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
2
answers
200
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.
...
8
votes
2
answers
2k
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
1
answer
396
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, ...
5
votes
1
answer
2k
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 ...
18
votes
1
answer
664
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
1
answer
861
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
1
answer
123
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 ...
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 | ...
6
votes
3
answers
397
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
1
answer
55
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
2
answers
282
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
2
answers
309
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
1
answer
145
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
1
answer
177
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 ...
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-...
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 ...
31
votes
3
answers
12k
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 ...
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 ...
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 ...
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 ...
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 ...
12
votes
2
answers
418
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)?
...
18
votes
5
answers
844
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 ...
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 ...
8
votes
1
answer
4k
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 ...
15
votes
3
answers
542
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 ...
1
vote
1
answer
260
views
What can happen if I accidentally paste into command mode? What should I do if I do this? [duplicate]
If I have vim in a windowed terminal, sometimes I paste (using the terminal's paste functionality, e.g. middle click) from another window that isn't vim. Most of the time, when I do this, I wanted to ...
13
votes
4
answers
1k
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 ...
-3
votes
1
answer
156
views
Are there any precautionary measures I can take for a beginner? [closed]
When first starting out using vim, I was nervous that I'd get lost in some foreign mode that could potentially wreak havoc. I felt like there was never really any "safety net" preventing me from a ...
54
votes
1
answer
19k
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 ...