2023-06-27 09:52:49 +00:00
|
|
|
" from https://vi.stackexchange.com/a/26055
|
|
|
|
augroup KeepCentered
|
|
|
|
autocmd!
|
|
|
|
autocmd CursorMoved * normal! zz
|
|
|
|
autocmd TextChangedI * call InsertRecenter()
|
|
|
|
augroup END
|
2016-12-02 14:43:47 +00:00
|
|
|
|
2023-06-27 09:52:49 +00:00
|
|
|
function InsertRecenter() abort
|
|
|
|
let at_end = getcursorcharpos()[2] > len(getline('.'))
|
|
|
|
normal! zz
|
|
|
|
|
|
|
|
" Fix position of cursor at end of line
|
|
|
|
if at_end
|
|
|
|
let cursor_pos = getcursorcharpos()
|
|
|
|
let cursor_pos[2] = cursor_pos[2] + 1
|
|
|
|
call setcursorcharpos(cursor_pos[1:])
|
|
|
|
endif
|
|
|
|
endfunction
|