我最近在vim中发现了全局标记的用法。它们似乎是一个非常强大的功能,但是当vim关闭时它们会被删除。有没有办法在vim启动时定义vim全局标记(例如在.vimrc文件中定义它们)?
答案 0 :(得分:5)
通常,全局标记在退出时保存在viminfo文件中。它由viminfo
选项控制。您可以像这样检查其值:
:set viminfo?
如果它为空,您可以在.vimrc
中设置一个公共值:
set viminfo='100,<50,s10,h
然后应在退出时保存全局标记。
f0
参数(因为它会禁用全局标记的保存)。自动保存通常是最好的解决方案,但如果您愿意,您还可以在vimrc中设置全局标记:
function! SetGMark(mark, filename, line_nr)
let l:mybuf = bufnr(a:filename, 1)
call setpos("'".a:mark, [l:mybuf, a:line_nr, 1, 0])
endf
call SetGMark('A', '~/file.txt', 10)
答案 1 :(得分:3)
您需要查看viminfo
:help viminfo
会为您提供一般信息,:help 'viminfo'
会告诉您需要设置的选项。 (引用在这方面很重要)
If you exit Vim and later start it again, you would normally lose a lot of
information. The viminfo file can be used to remember that information, which
enables you to continue where you left off.
This is introduced in section 21.3 of the user manual.
The viminfo file is used to store:
- The command line history.
- The search string history.
- The input-line history.
- Contents of non-empty registers.
- Marks for several files.
- File marks, pointing to locations in files.
- Last search/substitute pattern (for 'n' and '&').
- The buffer list.
- Global variables.
实际上,请确保viminfo不包含禁用跨会话保存文件标记的f0
。
我的viminfo设置包含
:set viminfo='100,<50,s10,h,%