diff --git a/autoload/gitgutter.vim b/autoload/gitgutter.vim index e543159..0a05a6a 100644 --- a/autoload/gitgutter.vim +++ b/autoload/gitgutter.vim @@ -209,10 +209,16 @@ function! gitgutter#undo_hunk() abort call gitgutter#utility#system(gitgutter#utility#command_in_directory_of_file(g:gitgutter_git_executable.' apply --reverse --unidiff-zero - '), diff_for_hunk) " reload file preserving screen line position - let wl = winline() + " CTRL-Y and CTRL-E treat negative counts as positive counts. + let x = line('w0') silent edit - let offset = wl - winline() - execute "normal! ".offset."\" + let y = line('w0') + let z = x - y + if z > 0 + execute "normal! ".z."\" + else + execute "normal! ".z."\" + endif endif silent! call repeat#set("\GitGutterUndoHunk", -1)