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
~/.viminfoor~/.local/share/nvim/shada/main.shada :oldfilesreads that history and prints a numbered list- To open file number
Nfrom the list::e #<N<CR>(e.g.:e #<3opens item 3) - In Neovim you can also use
:browse oldfilesfor 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.'100stores 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