vim - 防止 Vim 记住更改

标签 vim

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

相关文章:

vim - 如何在 vim 中保存带有 UTC 时间的文件名?

linux - 如何使 xterm 命令行像 vim 一样工作

sorting - Vim 按虚拟列排序

vim - 使用 Ctrl-I 跳转在我的 MacVim 中不起作用,但 Ctrl-O 有效?

vim : bounce to the nearest enclosing paren

regex - 关于 Vim 中正则表达式的问题

python - 我如何使用 pony.vim

php - 我需要调试 PHP。我最好的选择是什么?

vim - .vimrc 配置文件在使用 'sudo' 编辑时不加载

regex - 范围内的多行 vim 正则表达式替换