我喜欢 '.
vim 中的命令。来自 :help '.
:
'. `.
[Jump to] the position where the last change was made. The position is at or near where the change started.
好的。但这是我的问题:我使用
autocmd
函数在我的文件头中添加“最后修改”行。因此,每次写入后,'.
带给我的不是“真正的”最后一次更改,而是我的文件标题。我目前的解决方案是我尽量记住用 ma
标记我当前的编辑点,所以我可以 'a
回到它。然而,我有时会忘记,即使我记得,也是另外几次击键。我的理想解决方案是使用某种命令告诉 vim 不要记住 Action 。我可以在
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
最佳答案
您可以使用 :keepjumps {command}
在您的 autocmd
.
见 :help :keepjumps
.
关于vim - 防止 Vim 记住更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17431246/