feat(Neovim): Correct defaults for restore-cursor

When restoring the cursor to last file's position, there was an
inconsistency between Neovim and Vim for commit files.  That was because
Neovim's defaults didn't properly detect the filetype in such cases.
The current patch corrects that with a recipe copied from Neovim's help
docs.
This commit is contained in:
Dionisio E Alonso 2024-01-20 11:57:55 -03:00
parent 19df5c58a7
commit 66c4be90c7
2 changed files with 12 additions and 9 deletions

View File

@ -1,15 +1,19 @@
" Some settings Vim has on its defaults.vim that NeoVim hasn't set by default
" Some settings Vim has on “defaults.vim” that Neovim hasn't set by default
set scrolloff=5
if has('mouse')
set mouse=a
set mouse=a
endif
augroup vimStartup
au!
autocmd BufReadPost *
\ if line("'\"") >= 1 && line("'\"") <= line("$") && &ft !~# 'commit'
\ | exe "normal! g`\""
\ | endif
augroup RestoreCursor
autocmd!
" This is slightly different than Vim's defaults.vim, but taken from
" “:h restore-cursor” for Neovim
autocmd BufRead * autocmd FileType <buffer> ++once
\ let s:line = line("'\"")
\ | if s:line >= 1 && s:line <= line("$") && &filetype !~# 'commit'
\ && index(['xxd', 'gitrebase'], &filetype) == -1
\ | execute "normal! g`\""
\ | endif
augroup END

View File

@ -32,7 +32,6 @@ if has('autocmd')
autocmd!
autocmd FileType gitcommit setlocal spell nonumber norelativenumber
autocmd FileType gitcommit startinsert
autocmd FileType gitcommit exe "normal! gg"
augroup END
endif