Persistent undo and swapfile

28 views
Skip to first unread message

Manfred Lotz

unread,
Dec 31, 2021, 4:57:31 PM12/31/21
to vim...@googlegroups.com
I have persistent undo configured and it helped me a lot in various situations
over the last 5 or so years.

I also have swapfile configured but I am actually not sure if it is really
required if persistent undo is active.

Any thoughts?


--
Manfred

Bram Moolenaar

unread,
Dec 31, 2021, 6:33:23 PM12/31/21
to vim...@googlegroups.com, Manfred Lotz
You do need both.

The persistent undo is great to be able to back in time, even when you
unload the buffer, quit Vim and come back another day. I especially use
it to add debugging commands, try lots of things, and finally just undo
the changes. No version control system needed.

The swapfile is a safety net for the unexpected. Vim might crash. I
know, for normal users this hardly ever happens, still I keep fixing
crashes all the time (fuzzers try just about any random input to look
for these problems). Or your computer might die. Hopefully that
doesn't happen either. But still, it happens when you least expect it.

--
Living in Hollywood is like living in a bowl of granola. What ain't
fruits and nuts is flakes.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Manfred Lotz

unread,
Jan 1, 2022, 10:31:05 AMJan 1
to vim...@googlegroups.com
First, thanks a lot for you very clear explanations.


On 1/1/22 12:33 AM, Bram Moolenaar wrote:
>
> Manfred Lotz wrote:
>
>> I have persistent undo configured and it helped me a lot in various situations
>> over the last 5 or so years.
>>
>> I also have swapfile configured but I am actually not sure if it is really
>> required if persistent undo is active.
>>
>> Any thoughts?
>
> You do need both.
>
> The persistent undo is great to be able to back in time, even when you
> unload the buffer, quit Vim and come back another day. I especially use
> it to add debugging commands, try lots of things, and finally just undo
> the changes. No version control system needed.
>

Yes, persistent undo is absolutely great.

> The swapfile is a safety net for the unexpected. Vim might crash. I
> know, for normal users this hardly ever happens, still I keep fixing
> crashes all the time (fuzzers try just about any random input to look
> for these problems). Or your computer might die. Hopefully that
> doesn't happen either. But still, it happens when you least expect it.
>

Very unlikely, but bad things can happen. Agree.


So, my setting using both is just fine.


--
Manfred

Walter Cazzola

unread,
Jan 3, 2022, 11:53:34 AMJan 3
to vim...@googlegroups.com, Manfred Lotz
Out of curiosity: which plugin are you using for the persistent undo.

I have tried (few years ago) a few but they were quite unsatisfactory and
being something I feel necessary I would like to get advice.

Walter

Lifepillar

unread,
Jan 3, 2022, 1:03:40 PMJan 3
to vim...@googlegroups.com
On 2022-01-03, Walter Cazzola <caz...@di.unimi.it> wrote:
> Out of curiosity: which plugin are you using for the persistent undo.

Do you mean, to navigate the (not necessarily persistent) undo history?
I use undotree (https://github.com/mbbill/undotree). I prefer it over
other choices mainly because it is pure Vim script and it require no or
little configuration.

Hope this helps,
Life.

Manfred Lotz

unread,
Jan 3, 2022, 3:53:05 PMJan 3
to vim...@googlegroups.com


On 1/3/22 5:53 PM, Walter Cazzola wrote:
> Out of curiosity: which plugin are you using for the persistent undo.
>
> I have tried (few years ago) a few but they were quite unsatisfactory and
> being something I feel necessary I would like to get advice.
>
Same as Lifepillar I use undotree. However, I have to admit that I haven't used
it much.


--
Manfred

Walter Cazzola

unread,
Jan 3, 2022, 4:05:18 PMJan 3
to vim...@googlegroups.com
On Mon, 3 Jan 2022, Lifepillar wrote:

> On 2022-01-03, Walter Cazzola <caz...@di.unimi.it> wrote:
>> Out of curiosity: which plugin are you using for the persistent undo.
>
> Do you mean, to navigate the (not necessarily persistent) undo history?

Yes but also to have the undoes stored somewhere.

> I use undotree (https://github.com/mbbill/undotree). I prefer it over
> other choices mainly because it is pure Vim script and it require no or
> little configuration.

I'll give it a look.

Walter

--

Walter Cazzola

unread,
Jan 3, 2022, 4:07:32 PMJan 3
to vim...@googlegroups.com
I see, my worry is that the stored undoes can grow too much on long living
(ie., files that I uses since a lot and updates quite frequently as the
.vimrc) files.

Walter

--

Manfred Lotz

unread,
Jan 3, 2022, 4:38:51 PMJan 3
to vim...@googlegroups.com
Hm, yes. Stored undos could grow but this should not cause problems, IMHO.

I have configured it like follows:

set undofile
set undolevels=5000
set undodir=~/.vim/undodir/


Another point might be interesting. In the undo directory there are undo files
where the real files don't exist any longer. Not sure if there is some cleanup
procedure avalaible.

--
Manfred

Lifepillar

unread,
Jan 3, 2022, 4:55:47 PMJan 3
to vim...@googlegroups.com
On 2022-01-03, Manfred Lotz <ml_...@posteo.de> wrote:
> Another point might be interesting. In the undo directory there are
> undo files where the real files don't exist any longer. Not sure if
> there is some cleanup procedure avalaible.

I use this command to remove undo files that haven't changed in a long
time:

command! -nargs=0 CleanUpUndoFiles !find ~/.vim/tmp/undo -type f -mtime +100d -delete

This goes with this setting:

set undodir=~/.vim/tmp/undo

Life.

Lifepillar

unread,
Jan 3, 2022, 5:00:08 PMJan 3
to vim...@googlegroups.com
On 2022-01-03, Walter Cazzola <caz...@di.unimi.it> wrote:
> On Mon, 3 Jan 2022, Lifepillar wrote:
>
>> On 2022-01-03, Walter Cazzola <caz...@di.unimi.it> wrote:
>>> Out of curiosity: which plugin are you using for the persistent undo.
>>
>> Do you mean, to navigate the (not necessarily persistent) undo history?
>
> Yes but also to have the undoes stored somewhere.

Not sure I understand: persistent undo is a built-in Vim feature (see
Manfred's post). Are you looking for something that Vim does not
provide?

Life.

Walter Cazzola

unread,
Jan 3, 2022, 5:18:56 PMJan 3
to vim...@googlegroups.com
On Mon, 3 Jan 2022, Lifepillar wrote:

>>> Do you mean, to navigate the (not necessarily persistent) undo history?

>> Yes but also to have the undoes stored somewhere.

> Not sure I understand: persistent undo is a built-in Vim feature (see
> Manfred's post). Are you looking for something that Vim does not
> provide?

Uh! I didn't know that. I looked for an external plugin without realizing they
all rely on a vim feature.

Walter

--

Brian L. Matthews

unread,
Jan 3, 2022, 6:19:14 PMJan 3
to vim...@googlegroups.com
You can include undodir in the command:

command! -nargs=0 CleanUpUndoFiles execute '!find "' ..
fnameescape(&undodir) .. '" -type f -mtime +100d -delete'

(using fnameescape and enclosing it in double quotes probably won't be
necessary 99.9...% of the time, but just in case...)

There may be better ways to do that, I'm a vim novice, but that works
for me.

Brian

Gary Johnson

unread,
Jan 3, 2022, 7:08:29 PMJan 3
to vim...@googlegroups.com
On 2022-01-03, Brian L. Matthews wrote:
> On 1/3/22 1:55 PM, Lifepillar wrote:
> >On 2022-01-03, Manfred Lotz wrote:
> >>Another point might be interesting. In the undo directory there are
> >>undo files where the real files don't exist any longer. Not sure if
> >>there is some cleanup procedure avalaible.
> >I use this command to remove undo files that haven't changed in a long
> >time:
> >
> > command! -nargs=0 CleanUpUndoFiles !find ~/.vim/tmp/undo -type f -mtime +100d -delete
> >
> >This goes with this setting:
> >
> > set undodir=~/.vim/tmp/undo
>
> You can include undodir in the command:
>
> command! -nargs=0 CleanUpUndoFiles execute '!find "' ..
> fnameescape(&undodir) .. '" -type f -mtime +100d -delete'
>
> (using fnameescape and enclosing it in double quotes probably won't
> be necessary 99.9...% of the time, but just in case...)
>
> There may be better ways to do that, I'm a vim novice, but that works
> for me.

Just remember that &undodir can be a comma-separated list of files,
so while this will work in the common case of 'undodir' containing
only one undo directory, it won't work if 'undodir' contains a list.

Regards,
Gary

Reply all
Reply to author
Forward
0 new messages