summaryrefslogtreecommitdiffstats
path: root/runtime/defaults.vim
diff options
context:
space:
mode:
authorDragan Simic' via vim_dev <vim_dev@googlegroups.com>2023-08-09 17:23:58 +0200
committerChristian Brabandt <cb@256bit.org>2023-08-10 06:43:14 +0200
commit81b8bf5b4a33552c610dc2ea743ac2698a16aef7 (patch)
tree053183a76d2b00f7be0de1713866691bf8135ce4 /runtime/defaults.vim
parent6a500661a9cb7b57093cf1095aa67e9c4aabc709 (diff)
Update the vimscript code for restoring cursor position
Using xxd(1) to filter and edit binary files causes the input files to have dual nature, so to speak, which effectively makes restoring the cursor position broken. Fix that by ignoring the "xxd" file type in the code that restores the cursor position. Interactive rebasing in git causes files to be edited in vim, which, similarly to commit messages, are rarely the same as the last one edited. Thus, also add "gitrebase" to the list of file types for which the cursor position isn't restored. While there, refactor the code a bit to possibly save a few CPU cycles and to keep the line lengths in check, and use the long form of the commands and variables, to make the code slightly more consistent and more understandable to newcomers. Update the relevant comments in the code and the associated parts of the documentation, to keep them in sync with the updated code. Remove some redundant trailing whitespace as well, as spotted.
Diffstat (limited to 'runtime/defaults.vim')
-rw-r--r--runtime/defaults.vim16
1 files changed, 10 insertions, 6 deletions
diff --git a/runtime/defaults.vim b/runtime/defaults.vim
index 67659895f2..6f8deb06ba 100644
--- a/runtime/defaults.vim
+++ b/runtime/defaults.vim
@@ -99,15 +99,19 @@ if 1
" Put these in an autocmd group, so that you can revert them with:
" ":autocmd! vimStartup"
augroup vimStartup
- au!
+ autocmd!
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid, when inside an event handler
- " (happens when dropping a file on gvim) and for a commit message (it's
- " likely a different one than last time).
+ " (happens when dropping a file on gvim), for a commit or rebase message
+ " (likely a different one than last time), and when using xxd(1) to filter
+ " and edit binary files (it transforms input files back and forth, causing
+ " them to have dual nature, so to speak)
autocmd BufReadPost *
- \ if line("'\"") >= 1 && line("'\"") <= line("$") && &ft !~# 'commit'
- \ | exe "normal! g`\""
+ \ let line = line("'\"")
+ \ | if line >= 1 && line <= line("$") && &filetype !~# 'commit'
+ \ && index(['xxd', 'gitrebase'], &filetype) == -1
+ \ | execute "normal! g`\""
\ | endif
augroup END
@@ -119,7 +123,7 @@ if 1
augroup vimHints
au!
autocmd CmdwinEnter *
- \ echohl Todo |
+ \ echohl Todo |
\ echo gettext('You discovered the command-line window! You can close it with ":q".') |
\ echohl None
augroup END