tags:

views:

266

answers:

3

Hi. how can I clear the .viminfo file.

I want to clear the Command Line History,File marks, Jumplist etc., other then Search String History

Is there any way to do this.

+1  A: 

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 "-".

Zhaojun
eeeeeeeeeeeeee... bad answer.why you are creating unnecessary file and your answer is wrong.
ungalnanban
+2  A: 

I can think of 3 ways to do this.

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

  2. Or:

    1. Open the .viminfo file in vim,

    2. :set viminfo= to turn off the auto-saving of info to the .viminfo file,

    3. Remove everything you don't want (perhaps by using Johnsyweb's answer, or just by deleting the lines manually), save the file, and quit vim,

  3. Or:

    1. Run Vim,

    2. :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 registsers 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.

Rich
N.B. If you use method 3, you do NOT need to use @Johnsyweb 's :v command to remove the lines. "Will not be saved" in this context implies that existing ones will be removed.
Rich
+3  A: 

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.

Johnsyweb
@Johnsyweb Note that there's three different methods in my answer, and the third one does actually removes the lines for you. Your command is helpful if you use method 2, though.
Rich