防止Vim记住改变

时间:2013-07-02 16:47:29

标签: vim

我喜欢vim中的'.命令。来自:help '.

'.   `.
  

[跳转到]进行最后一次更改的位置。该位置处于或接近变更开始的位置。

确定。但这是我的问题:我使用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

{{1}}

3 个答案:

答案 0 :(得分:4)

您可以在:keepjumps {command}中使用autocmd

请参阅:help :keepjumps

答案 1 :(得分:3)

:lockmarks <command>中尝试autocmd。对此的帮助表明'.是命令不会改变的事情之一。

答案 2 :(得分:1)

可能有更漂亮的方法可以做到这一点,但如何简单地保留另一个标记中的位置?例如:

" This is where I'd put the command to ignore future movements
" go to the mark and label it as z
`.mz

" This is where I'd put the command to start remembering movements again
" return to your mark and create a fake edit there to reset the most recent edit mark
`zi <Esc>x