如何让 Vim 带您回到上次编辑文件时的位置?
如何使 Vim 带您回到上次编辑文件时的位置?
我的工作电脑有这个功能,但我的家用电脑没有!如何设置 Vim 记住上次编辑文件时位于文件的哪个部分?
编辑:更准确地说,我希望在打开新文件或启动时出现这种行为。
Possible Duplicate:
In vim, how do I get a file to open at the same line number I closed it at last time?
How do you make Vim take you back where you were when you last edited a file?
My work computer has this feature, but not my home computer! How do you set Vim to remember in which part of a file you were when you last edited it?
EDIT: just to be more precise, I want this behavior when opening a new file, or on startup.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我的 .vimrc 中有这个并且它有效:
I have this in my .vimrc and it works:
这是通过
viminfo
文件完成的。只需启用此功能(并确保文件可写)就足够了。我使用:...它将 viminfo 数据存储到
~/.viminfo
中。您可以在此处阅读有关其他自定义选项。This is done with the
viminfo
file. It should be sufficient simply to enable this feature (and ensure that the file is writable). I use:...which stores viminfo data into
~/.viminfo
. You can read about the other customization options here.首先,检查您的 .vimrc 文件是否可写。
如果这还不够,请将其添加到您的 .vimrc 中:
First, check that your .vimrc file is writable.
If that isn't sufficient, add this to your .vimrc:
'0 //(单引号后跟零)带您到上次编辑的位置
'0 // (single quote followed by zero) take you to place you last edited
这是一个肮脏的解决方案。
每当您编辑完文件并准备退出时,只需使用
m
标记该位置即可。现在,您使用mks!
为此创建一个会话文件。下次打开此文件时,只需执行“``即可到达该位置。您可以使用不同的字母来到达文件中的不同位置。例如,
e
代表您上次编辑的位置,或者f
代表您上次处理的函数定义,等等。这取决于你的口味。此解决方案的一个缺点是
mks!
将在当前目录中创建一个Session.vim
文件。This is a dirty solution.
Whenever you are done editing a file and you are going to quit, just mark that place using
m<letter>
. Now you create a session file for this usingmks!
. Next time you open this file, just do ``` to reach that place.You can have different letters to reach different places in the file. e.g.
e
for the place you were last editing orf
function definition you were last working on etcetera. It depends upon your taste.One thing bad about this solution is that
mks!
will create aSession.vim
file in the current directory.另请参阅 Vim Wikia 文章 将光标恢复到上一个编辑会话中的文件位置。 它看起来像它列出了此处已列出的几个解决方案,以及一个专门存储您编辑的最后 10 个文件的最后位置的较大脚本;您可以更改该值以满足您的需求。
See also the Vim Wikia article on Restore Cursor to File Position in Previous Editing Session. It looks like it lists a couple of the solutions already listed here, in addition to one larger script that specifically stores the last position for the last 10 files you've edited; you can change that value to suit your needs.