我正在使用http://www.thegeekstuff.com/2008/12/vi-and-vim-autocommand-3-steps-to-add-custom-header-to- 中提出的解决方案的(修改版本)your-file/自动为我的源代码创建和更新标题。
如上述页面所述,在调用 中的write命令时vim,将执行以下命令序列:
这很好,但有一个有点烦人的问题:假设我们正在编辑靠近窗口底部的一行。如果此时我们保存文件,由于光标移动(用于更新标题),我们正在编辑的行会跳转,因此它位于窗口的中间。
据我了解,'a将光标移动到标记标记的位置a并调整窗口内容,使当前行出现在窗口中间。我想知道是否有办法让“标记”也记住窗口中标记线的确切相对位置,并在跳回标记时保持这个位置?
它在文档中:恢复光标位置。
\n\n :map <F2> msHmt\xe2\x80\xa6\'tzt`s\nRun Code Online (Sandbox Code Playgroud)\n\n(我用省略号跳过了不相关的部分)。
\n\nms store cursor position in the \'s\' mark\nH go to the first line in the window\nmt store this position in the \'t\' mark\nRun Code Online (Sandbox Code Playgroud)\n\n打破恢复位置:
\n\n\'t go to the line previously at the top of the window\nzt scroll to move this line to the top of the window\n`s jump to the original position of the cursor\nRun Code Online (Sandbox Code Playgroud)\n