1
0
mirror of https://github.com/jdhao/nvim-config.git synced 2025-06-08 14:14:33 +02:00

fix bug in go to last edit position

If a go-to-line command is given, do not go to last edit position for
the file.
This commit is contained in:
jdhao 2021-12-20 22:15:34 +08:00
parent ed52ca5914
commit 08d3d7ec08

View File

@ -22,10 +22,25 @@ augroup END
" Return to last edit position when opening a file
augroup resume_edit_position
autocmd!
autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") && &ft !~# 'commit' | execute "normal! g`\"zvzz" | endif
autocmd BufReadPost * call s:resume_edit_pos()
augroup END
" Only resume last edit position when there is no go-to-line command (something like '+23').
function s:resume_edit_pos() abort
if line("'\"") > 1 && line("'\"") <= line("$") && &ft !~# 'commit'
let l:args = v:argv " command line arguments
for l:cur_arg in l:args
" Check if a go-to-line command is given.
let idx = match(l:cur_arg, '\v^\+(\d){1,}$')
if idx != -1
return
endif
endfor
execute "normal! g`\"zvzz"
endif
endfunction
" Display a message when the current file is not in utf-8 format.
" Note that we need to use `unsilent` command here because of this issue:
" https://github.com/vim/vim/issues/4379