bodacydo
bodacydo

Reputation: 79299

How to clear vim `oldfiles`?

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.

Upvotes: 5

Views: 2286

Answers (1)

sidyll
sidyll

Reputation: 59277

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.

Upvotes: 10

Related Questions