vim-header icon indicating copy to clipboard operation
vim-header copied to clipboard

Pollution of undo history

Open DerWeh opened this issue 7 years ago • 5 comments

First thanks for the great plug-in.

Just one thing is really annoying, every time I save the file, I get a new entry in my undo history for the change of the header. And even worse g; no brings me back to the header, and I am confused for a moment, as I expected to get to the line I changed last.

I don't really know, how to fix this in a sane way, but I would like to propose to changes:

  1. Check &mod. If I didn't modify anything, I don't want my header to show a new modified date (seems saner as the current version anyway right?). This at least gets rid of accidental multiple saves and similar.

  2. Only update the header, if it really changed. If the last changed date is already today, there is no need to update the header. With this the undo history/ last modified position would only be polluted once a day. I could easily bear with that.

DerWeh avatar Aug 02 '18 11:08 DerWeh

You are right about pollution. It may take time to resolve this. By the time, you may disable auto add / update header using let g:header_auto_add_header = 0 in your .vimrc. In this case you should call :AddHeader or a shortcut when you want to add / update header.

alpertuna avatar Aug 02 '18 12:08 alpertuna

Yes, disabling it is an alternative, sadly I always forget to add the headers then.

Another quick and unsatisfying fix, instead of checking whether the header changed, would be updating the header only once after opening the file.

This can be easily done the following way: opening the buffer set a variable per auto-command, saving the file sets the header and removes the variable only if it was set.

This is by no means optimal, but should be easy enough to implement and would be in my opinion an improvement to the current situation.

DerWeh avatar Aug 21 '18 08:08 DerWeh

Using keepjumps on all call append calls should solve this:

keepjumps call append(...)

See :help :keepjumps

mg979 avatar Sep 17 '18 20:09 mg979

any progress on this? i hate to be forced to disable the auto-headers :(

sQu1rr avatar Apr 29 '20 15:04 sQu1rr

It seems like undojoin might be a reasonable fix.

Replace the autocommand with

autocmd BufWritePre * silent! undojoin | :call header#update_header() " Update date when saving buffer

DerWeh avatar Oct 16 '21 13:10 DerWeh