Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear certain criteria from .viminfo file

Tags:

vim

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

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?

like image 654
ungalnanban Avatar asked May 12 '10 07:05

ungalnanban


People also ask

How to remove Vim history?

viminfo file directly (when Vim is closed, and either with another editor, or with vim -i NONE ). :call histdel(":") deletes the entire command history. Use :call histdel(":", "expr") to delete entries matching an expression.

What is viminfo?

The viminfo file is used to store: The command line history. The search string history. The input-line history. Contents of non-empty registers.


2 Answers

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,

like image 51
Rich Avatar answered Oct 02 '22 04:10

Rich


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.

like image 28
Johnsyweb Avatar answered Oct 02 '22 04:10

Johnsyweb