Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear vim `oldfiles`?

Tags:

file

vim

Vim's :oldfiles command shows the last 100 open files. I want to clear this list. How do I do that?

I tried googling for "vim oldfiles clear" but that doesnt return useful results. I also tried googling "vim oldfiles location" but also nothing.

like image 600
bodacydo Avatar asked Nov 14 '15 01:11

bodacydo


People also ask

How do I open a previous file in Vim?

If you use :help oldfiles , you will find the command :browse oldfiles which should do what you want.

What is Viminfo file?

The viminfo file is designed to store status information: Command-line and Search pattern history Text in registers Marks for various files The buffer list Global variables Each time you exit Vim it will store this information in a file, the viminfo file.


1 Answers

This command basically lists the contents of the v:oldfiles variable. However, emptying the variable is not what you want, because it is by itself generated from the contents of the .viminfo file.

Please read the help for viminfo. Vim won't store a list of "recent files". Those files come from the saved marks. And .viminfo stores a lot of things. I'm not sure you want to remove all of them, so you need to edit that portion of file. Editing it, however, can be a difficult maneuver — if you don't disable auto saving it will overwrite when quitting.

The best solution to your case, in my opinion, is to change the Vim setting that stores recent file marks to store nothing; and then tell Vim to rewrite the file. This can be achieved by the following commands. Please do this in a newly opened Vim session, ideally, one that you haven't edited a file yet.

:set vi+='0  " save no marks, in other words save 0 recent marks
:wv!         " write viminfo file without merging with old information

Reload Vim and your list should be clean. Please read the help for 'vi' to known more. If you want the recent files list to be always empty, you may want to configure that option to your will in your .vimrc. It is also useful to see your current configuration with :set vi.

like image 140
sidyll Avatar answered Oct 10 '22 19:10

sidyll