diff --git a/core/autocommands.vim b/core/autocommands.vim index 88f1688..812aeda 100644 --- a/core/autocommands.vim +++ b/core/autocommands.vim @@ -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