I like the '.
command in vim. From :help '.
:
'. `.
[Jump to] the position where the last change was made. The position is at or near where the change started.
Ok. But here's my problem: I use an autocmd
function to add a "last modified" line in my file header. So, after every write, '.
brings me not to my "real" last change, but to my file header. My current solution is I try to remember to mark my current editing point with ma
, so I can 'a
to return to it. I sometimes forget, though, and even when I remember, it's another couple keystrokes.
My ideal solution would be some sort of command that tells vim not to remember movements. I could send this command before the autocmd
function jumps around, writing the last modified line, and then cancel it after the autocmd
function has finished. That way, the location associated with '.
would not be changed. However, I'm open to any other options that are more efficient.
In case you want to see it, here's what the autocmd
does on :w
.
function! UpdateHeader()
let b:winview = winsaveview()
" This is where I'd put the command to ignore future movements
"The periods concatenate all the arguments into one command.
"Silent! suppresses errors, usually 'pattern not found'
"The 1,6g means search only lines 1 thru 6
"Search for File Name: followed by anything
"'s'ubstitute
"Substitute in 'File Name: ' and the results of the expand command, on the
"current filename
execute "silent! 1," . 6 . "g/File Name:.*/s//File Name: " . expand("%")
execute "silent! 1," . 6 . "g/Last Modified:.*/s//Last Modified: " . strftime("%d-%m-%Y")
" This is where I'd put the command to start remembering movements again
call winrestview(b:winview)
endfunction
You could use :keepjumps {command}
in your autocmd
.
See :help :keepjumps
.
Try :lockmarks <command>
in your autocmd
. The help for this says that '.
is one of the things will not be changed by the command.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With