vim-auto-save
vim-auto-save copied to clipboard
Duplicate entry is created in undo history
This duplicate entry is added after an InsertLeave and after the user moves the cursor.
To reproduce:
-
Enter insert-mode.
-
Type anything.
-
Exit insert mode.
- Autosave is triggered and undo history is updated, as expected.
-
Move the cursor using any motion.
- Undo list is updated again with no actual diff, which is not expected.
Here is an example below. I am using undotree to visualize the undo history.
FYI: This issue (as well #41) goes away when I trigger an auto-save on only CursorHold
events.
let g:auto_save_events = ["CursorHold"]
set updatetime=300
So far, things are working well for me using these settings!
I think OP has a valid point. Plugin creates some modification,( that comes up in undo history) in every event. @Asheq, I tried with your settings.
@Asheq @rjshrjndrn Hello! I have no time to investigate and fix this issue, sorry! But if you know how to fix that a PR is very welcome!
my solution:
let g:undo_skip_max_lines = 1000
function! Undo(it) abort "{{{
function! Lines() abort "{{{
return nvim_buf_get_lines(0, 0, g:undo_skip_max_lines, v:false)
endfunction "}}}
if nvim_buf_line_count(0) < g:undo_skip_max_lines && a:it < 10
let pre = Lines()
normal! u
let post = Lines()
if pre == post
return Undo(a:it + 1)
endif
else
normal! u
endif
endfunction "}}}
nnoremap u <cmd>call Undo(0)<cr>
skip empty changes in undo.