5

我喜欢'.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
4

3 回答 3

4

你可以:keepjumps {command}在你的autocmd.

:help :keepjumps

于 2013-07-02T19:57:26.823 回答
3

试试:lockmarks <command>你的autocmd. 对此的帮助说这'.是命令不会改变的事情之一。

于 2013-07-02T19:42:44.783 回答
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
于 2013-07-02T18:30:00.827 回答