持久的vim全球标记

ber*_*kie 4 vim macvim

我最近在vim中发现了全局标记的用法.它们似乎是一个非常强大的功能,但是当vim关闭时它们会被删除.有没有办法在vim启动时定义vim全局标记(例如通过在.vimrc文件中定义它们)?

Dav*_*ave 6

你需要调查一下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.
Run Code Online (Sandbox Code Playgroud)

本质上,确保 viminfo 不包含f0禁用跨会话保存文件标记的内容。

我的 viminfo 设置包含

:set viminfo='100,<50,s10,h,%
Run Code Online (Sandbox Code Playgroud)


yol*_*yer 5

通常,全局标记在退出时保存在viminfo文件中.它由viminfo选项决定.您可以像这样检查其值:

:set viminfo?
Run Code Online (Sandbox Code Playgroud)
  • 如果它为空,您可以在以下位置设置一个公共值.vimrc:

    set viminfo='100,<50,s10,h
    
    Run Code Online (Sandbox Code Playgroud)

    然后应在退出时保存全局标记.

  • 如果它不为空,则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)
Run Code Online (Sandbox Code Playgroud)