简体   繁体   English

从.viminfo文件中清除某些条件

[英]Clear certain criteria from .viminfo file

How can I clear certain criteria from my .viminfo file? 如何清除.viminfo文件中的某些条件?

I want to clear the command line history, file marks, jumplist, etc. 我想清除命令行历史记录,文件标记,跳转列表等。

However , I want to keep the search string history. 但是 ,我想保留搜索字符串的历史记录。

Is there any way to do this? 有什么办法吗?

I can think of 3 ways to do this. 我可以想到3种方法。

1. Automatically 1.自动

  1. Run Vim, 运行Vim

  2. Type: :set viminfo='0,:0,<0,@0,f0 类型:: :set viminfo='0,:0,<0,@0,f0

    • '0 means that marks will not be saved '0表示不会保存标记
    • :0 means that command-line history will not be saved :0表示将不保存命令行历史记录
    • <0 means that registers will not be saved <0表示将不保存寄存器
    • @0 means that input-line history will not be saved @0表示将不保存输入行历史记录
    • f0 means that marks will not be saved f0表示不会保存标记
    • no % means that the buffer list will not be saved no %表示将不保存缓冲区列表
    • no / means that the search history will be saved /表示保存搜索记录

    These options are correct in Vim 7.2, but might be different in other versions. 这些选项在Vim 7.2中是正确的,但在其他版本中可能有所不同。 For more details on the format of the viminfo string, run :h 'viminfo' 有关viminfo字符串格式的更多详细信息,请运行:h 'viminfo'

  3. Quit Vim. 退出Vim。 It will save a new version of the .viminfo file, containing only the information you want to keep. 它将保存.viminfo文件的新版本,其中仅包含您要保留的信息。

2. Manually 2.手动

  1. Open the .viminfo file in vim, 在vim中打开.viminfo文件,

  2. :set viminfo= to turn off the auto-saving of info to the .viminfo file. :set viminfo=关闭自动将信息保存到.viminfo文件的功能。 If you don't do this, Vim will overwrite all your changes when you quit, 如果您不这样做,Vim会在您退出时覆盖所有更改,

  3. Remove everything you don't want (perhaps by using Johnsyweb's answer , or just by deleting the lines with manual edit commands), save the file, and quit vim, 删除所有不需要的内容(也许使用Johnsyweb的答案 ,或者仅通过使用手动编辑命令删除行),保存文件并退出vim,

3. In a different editor 3.在其他编辑器中

Edit the .viminfo file in a different text editor and simply delete everything you don't want, 其他文本编辑器中编辑.viminfo文件,只需删除不需要的所有内容,

Open the .viminfo file. 打开.viminfo文件。

The following command will remove all lines that are neither blank, comment nor search history: 以下命令将删除所有不为空,注释或搜索历史的行:

:v/^\([#/?]\|$\)/d

@Rich's answer will help you prevent these lines being repopulated. @Rich的答案将帮助您防止重新填充这些行。

You can use vim itself to modify the file, and your changes will stay put if you invoke it like this: 您可以使用vim本身来修改文件,并且如果像这样调用它, vim的更改将保持不变:

$ vim -i NONE ~/.viminfo

Starting vim with the -i option sets which viminfo file to use for that session. 使用-i选项启动vim可以设置用于该会话的viminfo文件。 The special value NONE means that nothing is saved at all. 特殊值NONE表示什么都不保存。 This can be handy for editing other auto-generating files or sensitive data. 这对于编辑其他自动生成的文件或敏感数据非常方便。

From man vim : 来自man vim

-i {viminfo}
When using the viminfo file is enabled, this option sets the filename 启用使用viminfo文件时,此选项设置文件名
to use, instead of the default ~/.viminfo . 使用,而不是默认的~/.viminfo This can also be used to 这也可以用来
skip the use of the viminfo file, by giving the name NONE . 通过命名为NONE ,跳过viminfo文件的使用。

VIM seems not having a built-in command for this job. VIM似乎没有用于此作业的内置命令。 But you can do it in a shell with "grep". 但是您可以使用“ grep”在shell中进行操作。 For example, the following command will clear the Command Line History,File marks, Jumplist: 例如,以下命令将清除命令行历史记录,文件标记,跳转列表:

bash $ grep -v "^[:'-]" .viminfo > .viminfo_clear
bash $ cp .viminfo_clear .viminfo

If you open the .viminfo, you will find that the command line history is started with ":", the file mark is started with "'", and the jumplist is started with "-". 如果打开.viminfo,您将发现命令行历史记录以“:”开头,文件标记以“'”开头,跳转列表以“-”开头。

Copy useful part out and delete .viminfo, then open/close Vim. 复制有用的部分并删除.viminfo,然后打开/关闭Vim。 It will regenerate .viminfo. 它将重新生成.viminfo。 Then copy useful part back. 然后将有用的部分复制回去。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM