我喜欢vim中的'.
命令。从:help '.
:防止Vim记住更改
'. `.
[跳转到]其中最后做出更改的位置。该位置在变化开始的位置或附近。
好的。但这是我的问题:我使用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
完美。谢谢。 – ravron
任何想要实现这个解决方案的人都会注意到:*文本*实际修改发生时需要'keepjumps'命令* - 即':g'命令运行的':s'命令:'execute'沉默!1,“。 6。 “g /文件名:。*/keepjumps s //文件名:”。扩展( “%”)'。 – ravron
还有一点需要注意:在前面的注释中写入的命令确实会阻止设置“。”。但是,它仍然增加了跳转列表。为了防止那*,在'silent!'之后再次添加'keepjumps'。 – ravron