:browse oldfiles<cr> is useful for quickly navigating to a file I've worked on recently.

Sometimes though, I want to suspend vim and do some grep or ack search and find a new file that I'm interested in (let's call it sneaky.h). If I open a fresh vim using vim sneaky.h and then close it immediately, sneaky.h will appear in the oldfiles list the next time I launch vim.

However, my original vim instance, the one I started before searching for sneaky.h, does not have the file in the oldfiles list.

Is there a way to direct vim to refresh the oldfiles list and populate it again without restarting vim?

Also, is there a more efficient way to get a file like sneaky.h into the oldfiles pool without opening it and closing it immediately?

  • 1
    Does :rviminfo do the trick? :h :rviminfo.
    – statox
    Nov 23 '17 at 16:47
  • Also what you want is to learn how to find a file from within vim. There are a lot of options to do that like the built-in :find, grep, the file explorer netrw or fuzzy finding plugins like ctrl-p or fzf
    – statox
    Nov 23 '17 at 16:49
  • @statox: I guess that's true. If it isn't a file in the same directory and isn't ctags-able, I tend to search in the shell and use a fresh vim instance. Is there a way to get a file into .viminfo without opening and closing it? The format of a bare bones .viminfo entry > filename.txt, next line \t*\t<timestamp>\t0 seems simple enough to write a script for, but a "supported" way would be a bit nicer. Nov 23 '17 at 17:12
  • maybe you can use :rviminfo! (with explanationm ark) to force a re-read of the .viminfo.<br/> <br/> see :h oldfiles for more info.
    – tron5
    Nov 24 '17 at 7:38
  • 2
    @GregoryNisbet Im not sure if it is possible to easily add files to viminfo but it is because it is not actually meant to be used this way. See the XY problem What you actually need is a way to search for a file (you can do this in a lot of different ways) and then manipulate your arglist Take a look at these vimcast arglist, vimgrep, file explorer
    – statox
    Nov 24 '17 at 12:02

Although it doesn't use the oldfiles list, the MRU plugin implements the functionality you are looking for:

This plugin automatically stores the file names as you open/edit them in Vim.

You can configure the path of the file that stores the entries and the maximum number of entries it can hold. It supports FZF to filter the list.

(This answer was already mentioned by Peter Rincker in the comments above)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.