diff runtime/doc/usr_05.txt @ 32724:83111104fb89

Update the vimscript code for restoring cursor position Commit: https://github.com/vim/vim/commit/81b8bf5b4a33552c610dc2ea743ac2698a16aef7 Author: Dragan Simic' via vim_dev <vim_dev@googlegroups.com> Date: Wed Aug 9 17:23:58 2023 +0200 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.
author Christian Brabandt <cb@256bit.org>
date Thu, 10 Aug 2023 07:00:04 +0200
parents a9b5ffbc0428
children 3bc84e3fd05c
line wrap: on
line diff
--- a/runtime/doc/usr_05.txt
+++ b/runtime/doc/usr_05.txt
@@ -308,17 +308,27 @@ 3. Using indent files
 
 
 				*restore-cursor* *last-position-jump*  >
-    autocmd BufReadPost *
-      \ if line("'\"") >= 1 && line("'\"") <= line("$") && &ft !~# 'commit'
-      \ |   exe "normal! g`\""
-      \ | endif
+    augroup RestoreCursor
+      autocmd!
+      autocmd BufReadPost *
+        \ let line = line("'\"")
+        \ | if line >= 1 && line <= line("$") && &filetype !~# 'commit'
+        \      && index(['xxd', 'gitrebase'], &filetype) == -1
+        \ |   execute "normal! g`\""
+        \ | endif
+    augroup END
 
 Another autocommand.  This time it is used after reading any file.  The
 complicated stuff after it checks if the '" mark is defined, and jumps to it
-if so.  The backslash at the start of a line is used to continue the command
-from the previous line.  That avoids a line getting very long.
-See |line-continuation|.  This only works in a Vim script file, not when
-typing commands at the command-line.
+if so.  It doesn't do that for a commit or rebase message, which are likely
+a different one than last time, and when using xxd(1) to filter and edit
+binary files, which transforms input files back and forth, causing them to
+have dual nature, so to speak.  See also |using-xxd|.
+
+The backslash at the start of a line is used to continue the command from the
+previous line.  That avoids a line getting very long.  See |line-continuation|.
+This only works in a Vim script file, not when typing commands at the
+command line.
 
 >
 	command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis