我喜欢'.vim中的命令.来自:help '.:
'. `.
Run Code Online (Sandbox Code Playgroud)
[跳转到]进行最后一次更改的位置.该位置处于或接近变更开始的位置.
好.但这是我的问题:我使用一个autocmd函数在我的文件头中添加"最后修改"行.因此,在每次写入之后,'.不会让我的"真正的"最后一次更改,而是我的文件标题.我目前的解决方案是我试着记住用我的当前编辑点来标记ma,所以我可以'a回到它.我有时会忘记,即使我记得,也是另外几次按键.
我理想的解决方案是某种命令,告诉vim不要记住动作.我可以在autocmd函数跳转之前发送此命令,写入最后修改的行,然后在autocmd函数完成后取消它.这样,与之关联的位置'.就不会改变.但是,我对任何其他更高效的选项持开放态度.
如果你想看到它,这就是autocmd它的作用: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
Run Code Online (Sandbox Code Playgroud)