I know that the :oldfiles command will show you a history of the files you last had open; but how do I open the last n files in one command...for instance, say I want to open files 0-n in the :oldfiles list, is there a way to do that?

  • Note: Using :browse oldfiles will allow you to pick one from the list, but it doesn't open say the last n files.
    – leeand00
    Commented Jun 7, 2017 at 3:09

1 Answer 1


The files listed by :oldfiles are also available as a list in v:oldfiles, so something like:

for f in v:oldfiles[:10]
    exec "badd" f

Using an appropriate value instead of 10, of course.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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