Skip to main content
27 votes
Accepted

How can I undo `zg`?

From the help zuw *zug* *zuw* zug Undo |zw| and |zg|, remove the word from the entry in 'spellfile'. Count used as with |zg|. zuW ...
D. Ben Knoble's user avatar
  • 26.6k
21 votes
Accepted

Difference between g- and u

Check out vim's documentation on undo branches. u is essentially going to take you back to the parent of the current node, whereas g- allows you to traverse the current node's siblings before ...
Bryan Bugyi's user avatar
12 votes

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

You can set a persistent undo with the following settings: set undodir=~/.vim/undodir set undofile This is avaible in Vim 7.3 an above
B.G.'s user avatar
  • 1,156
11 votes

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

The change list is a different thing from the undo list. The change list is a list of locations of changes, and it can be viewed with :changes and navigated with e.g. g; and g,. The g+ and g- commands ...
Rich's user avatar
  • 32.2k
8 votes
Accepted

How to drop undo history?

I don't recall anything like that with e!. At least not since 'persistent undo' was added back in 2010 as part of v7.3(b?). (I confirmed that the command sequence discussed below was in the ...
B Layer's user avatar
  • 20k
8 votes
Accepted

How to make insert mode mapping count as multiple undos?

You can use <c-g>u in insert mode to break undo sequence and start new change. Like this: imap # <c-g>u<Esc>:w<CR># (removed the second <esc>, as it is not needed.) ...
Ralf's user avatar
  • 9,287
7 votes
Accepted

Using colon-commands inside ternary expression

inoremap (g == 0 ? :undo : :redo) You are using an expression mapping, so you must return an expression, e.g. in your case a string describing the command you want Vim to perform. That means your ...
Christian Brabandt's user avatar
7 votes
Accepted

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

it works for me: set mouse=a map <ScrollWheelUp> u map <ScrollWheelDown> <C-R> But i hope this is just for fun. Must be horrible =)
B.G.'s user avatar
  • 1,156
7 votes

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

For those who have this problem and wonder how to work around it without silencing all the errors, here is how I did it in my .vimrc: au BufWritePre * try | undojoin | Neoformat | catch /^Vim\%((\a\+)...
Kjir's user avatar
  • 171
6 votes

Turn Vim's multiple undo history into git commits?

Here's a quick and dirty function that does what you request: function! UndoCommits(steps) for i in range(a:steps) undo endfor for i in range(a:steps) write ...
Rich's user avatar
  • 32.2k
6 votes

Break the undo sequence in normal mode

Doing :let &ul=&ul breaks the undo sequence. This is documented under :h :undojoin: Setting the value of 'undolevels' also breaks undo. Even when the new value is equal to the old value. ...
Jake Grossman's user avatar
6 votes
Accepted

What does undo undo?

It undo the last command (e.g. i, c, d). The insert (i) command can indeed be either: rather large if you type a long text without leaving the insert mode or rather short if you just make a small ...
Vivian De Smedt's user avatar
5 votes
Accepted

undo last change on current line

This will probably do what you want: function! Undoline() let pos = getpos(".") let current = getline(pos[1]) let chg = changenr() while changenr() > 0 && current ==# getline(pos[1]...
laktak's user avatar
  • 2,953
5 votes
Accepted

Redo earlier edit operation

Unfortunately, this feature is not possible in vim right now. Although it's apparently a popular request, as many people have asked the same thing. I did find this discussion from two years ago on ...
DJMcMayhem's user avatar
  • 17.7k
5 votes
Accepted

Possible to rename file and maintain undo?

Using :saveas keeps the undo history intact. :saveas is equivalent to the combination of :w newname followed by :e #. I usually find it more handy than the :w + :e, especially since with :saveas it's ...
filbranden's user avatar
  • 29k
5 votes

how do you undo a few operations in the vi editor

Original vi only supports single-level undo: the first time you press u it performs an undo, and the second time you press it it undoes the undo, going back to the state before the undo. Nvi (and ...
Rich's user avatar
  • 32.2k
4 votes

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

You're slightly misunderstanding what Vim is doing here. When you do d4b, there is only a single action, which deletes from the current position to the position where 4b would jump to. The behaviour ...
Rich's user avatar
  • 32.2k
3 votes
Accepted

Local persistent undo file modeline

No, the 'undodir' option cannot be set from a modeline, because it has the 'SECURE' flag set. Since this is a global option, it does not make sense to set this option differently for a specific file, ...
Christian Brabandt's user avatar
3 votes
Accepted

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

You can't recover the words you've already lost, but we can make <c-u> an undo-able motion by remapping it: inoremap <c-u> <c-g>u<c-u> This is from vim-sensible. See :h ...
flemingfleming's user avatar
3 votes

Persistent undo not working

OK, I'm a dummy. I needed to create .VIM_UNDO_FILES as a dir not a file.
StevieD's user avatar
  • 1,492
3 votes
Accepted

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

What is most likely happening in your case is that the buffer is automatically unloaded because you don't have the option 'hidden' enabled. This option not only resolves the issue you reported, but ...
Vitor's user avatar
  • 1,752
3 votes

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

For removing :!goimports from the history, use systemlist: call setline(1, systemlist('goimports', getline(0, line('$')))) The problem here is that if there are fewer lines after goimports, some ...
muru's user avatar
  • 25k
3 votes

Turn Vim's multiple undo history into git commits?

I would recommend one of the undo tree visualizer plugins: undotree Gundo With them, you can easily revisit previous editing states. You can them (temporarily) restore them (one by one, starting ...
Ingo Karkat's user avatar
  • 17.9k
3 votes

How to make insert mode mapping count as multiple undos?

From :h undojoin: One undo command normally undoes a typed command, no matter how many changes that command makes. This sequence of undo-able changes forms an undo block. [...] To do the opposite, ...
muru's user avatar
  • 25k
3 votes
Accepted

Automate breaking of history in insert mode

You can define insert mode mappings for those keys by prepending <c-g>u: :inoremap <space> <c-g>u<space> :inoremap <bs> <c-g>u<bs> :inoremap <c-w> &...
Jürgen Krämer's user avatar
3 votes

Undo <count> macro instances

Typically, Vim considers a mapping or a recorded macro as a single change, so if you press u to undo it, it will undo all of it. There exists the possibility to break an undo-sequence into smaller ...
Christian Brabandt's user avatar
3 votes
Accepted

Why does cw followed by ctrl-r register consist of two edits?

It turns out, it's vim-peekaboo which is causing this behavior, and it is a known bug, filed in #30.
Enlico's user avatar
  • 2,224
3 votes

Undo-joining a mapping that uses the expression register

Besides UltiSnips#ExpandSnippet(), there is also UltiSnips#Anon(). The latter expands a snippet that is defined on-the-fly. Importantly, unlike UltiSnips#ExpandSnippet(), UltiSnips#Anon() does not ...
husB's user avatar
  • 2,123
3 votes
Accepted

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

The undo line is a strange beast. It gathers all the consecutive changes (insertion, deletion, modification) you did on the undo branch: On the last line you have edited Since the last undo line ...
Vivian De Smedt's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible