Clear certain criteria from .viminfo file

前端 未结 5 581
深忆病人
深忆病人 2021-01-31 08:25

How can I clear certain criteria from my .viminfo file?

I want to clear the command line history, file marks, jumplist, etc.

However,

相关标签:
5条回答
  • 2021-01-31 09:01

    Copy useful part out and delete .viminfo, then open/close Vim. It will regenerate .viminfo. Then copy useful part back.

    0 讨论(0)
  • 2021-01-31 09:06

    You can use vim itself to modify the file, and your changes will stay put if you invoke it like this:

    $ vim -i NONE ~/.viminfo
    

    Starting vim with the -i option sets which viminfo file to use for that session. The special value NONE means that nothing is saved at all. This can be handy for editing other auto-generating files or sensitive data.

    From man vim:

    -i {viminfo}
    When using the viminfo file is enabled, this option sets the filename
    to use, instead of the default ~/.viminfo. This can also be used to
    skip the use of the viminfo file, by giving the name NONE.

    0 讨论(0)
  • 2021-01-31 09:15

    VIM seems not having a built-in command for this job. But you can do it in a shell with "grep". 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 "-".

    0 讨论(0)
  • 2021-01-31 09:17

    Open the .viminfo file.

    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.

    0 讨论(0)
  • 2021-01-31 09:19

    I can think of 3 ways to do this.

    1. Automatically

    1. Run Vim,

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

      • '0 means that marks will not be saved
      • :0 means that command-line history will not be saved
      • <0 means that registers will not be saved
      • @0 means that input-line history will not be saved
      • f0 means that marks will not be saved
      • no % means that the buffer list will not be saved
      • no / means that the search history will be saved

      These options are correct in Vim 7.2, but might be different in other versions. For more details on the format of the viminfo string, run :h 'viminfo'

    3. Quit Vim. It will save a new version of the .viminfo file, containing only the information you want to keep.

    2. Manually

    1. Open the .viminfo file in vim,

    2. :set viminfo= to turn off the auto-saving of info to the .viminfo file. If you don't do this, Vim will overwrite all your changes when you quit,

    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,

    3. In a different editor

    Edit the .viminfo file in a different text editor and simply delete everything you don't want,

    0 讨论(0)
提交回复
热议问题