vimtricks.wiki Concise Vim tricks, one at a time.

How do I see a list of recently opened files and quickly jump back to one?

Answer

:oldfiles

Explanation

:oldfiles displays a numbered list of every file Vim has recorded in its viminfo (or shada in Neovim) file. It is the built-in equivalent of a "recent files" menu, letting you navigate back to any file from past sessions without relying on a plugin.

How it works

  • Vim/Neovim stores file history in ~/.viminfo or ~/.local/share/nvim/shada/main.shada
  • :oldfiles reads that history and prints a numbered list
  • To open file number N from the list: :e #<N<CR> (e.g. :e #<3 opens item 3)
  • In Neovim you can also use :browse oldfiles for an interactive prompt

Example

:oldfiles

Output:

1: ~/.vimrc
2: ~/projects/app/main.go
3: ~/projects/app/handler.go
4: /tmp/notes.md

To reopen handler.go:

:e #<3

Tips

  • The number of files stored is controlled by 'viminfo' / 'shada' settings — look for the 'N<N> value (e.g. '100 stores 100 files)
  • In Neovim: :lua vim.print(vim.v.oldfiles) shows the list as a Lua table
  • Combine with <C-^> (alternate file) to toggle between the last two files you had open

Next

How do I match a pattern only when it is preceded or followed by another pattern, without including that context in the match?