Questions tagged [undo-redo]

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

Filter by
Sorted by
Tagged with
2
votes
2answers
17 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 ...
4
votes
2answers
157 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
63 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
30 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
61 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
122 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
21 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 ...
1
vote
0answers
39 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 ...
1
vote
1answer
130 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
138 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
40 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
68 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
75 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
88 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 ...
2
votes
1answer
133 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
77 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
43 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
108 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
726 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
213 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
563 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 ...
11
votes
1answer
319 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
404 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
64 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 ...
9
votes
2answers
446 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
179 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
41 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?
1
vote
2answers
127 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
167 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
90 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
128 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
702 views

How to 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-...
2
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
6k 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
612 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
169 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 ...
10
votes
1answer
888 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
1answer
990 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 ...
10
votes
2answers
229 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)? ...
12
votes
5answers
505 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 ...
13
votes
3answers
6k 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 ...
7
votes
1answer
1k 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 ...
14
votes
3answers
380 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 to have ...
1
vote
1answer
205 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 ...
11
votes
4answers
392 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
1answer
131 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 ...
33
votes
1answer
5k 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 ...