3

: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?

Vivian De Smedt
  • 16,336
  • 3
  • 18
  • 37
Greg Nisbet
  • 1,839
  • 14
  • 27
  • 2
    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.

    – Greg Nisbet Nov 23 '17 at 17:12
  • maybe you can use :rviminfo! (with explanationm ark) to force a re-read of the .viminfo.

    see `:h oldfiles` for more info.
    – tron5 Nov 24 '17 at 07: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
  • I am not certain viminfo can be properly shared across vim instances. To allow merging of information, neovim uses shada files instead of viminfo files. I imagine you need to look into using MRU plugin or roll your own solution. – Peter Rincker Nov 27 '17 at 17:05

1 Answers1

0

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)

mroavi
  • 77
  • 5