View a list of recent documents in Vim

Viewed 37539

Is there a way to view the list of recent documents you've opened in Vim?

I realize I could view the cursor jump list, :ju, and then go to a cursor position in the list but this is not ideal because there will be multiple listings of the same document in the list.

Is there another command which would do what I'm looking for?

10 Answers

Don't use a plugin, unless you want a nice menu. From Vim Documentation: Starting (or :help old):

:ol[dfiles]

Then to open one of the listed files, use: '0, '1, '2, ... '9


List the files that have marks stored in the viminfo file.

:bro[wse] ol[dfiles][!]

List file names as with :oldfiles, and then prompt for a number. When the number is valid that file from the list is edited. Use ! to abandon a modified buffer.

A good plugin is https://github.com/Shougo/denite.nvim

You can call :Denite file_old in order to have fuzzy search on the list of old files. In particular, just hitting Enter will re-open the last opened file. Assigning a shortcut to this is useful:

nnoremap <leader>o :Denite<space>file_old<CR>

This saves few keystrokes compared to :browse oldfiles, q, 1, Enter

The easiest way for me to access recent files is to add the following to one's .gvimrc file:

let g:netrw_sort_by           = 'time'

let g:netrw_sort_direction    = 'r'

These lines get netrw to sort files by those most recently modified. Then one simply calls :e. and selects the file one wants.

This solution presupposes files are saved in one main directory so specified in .gvimrc. E.g.

cd ~/vim

No directly the answer but related.

you can define aliases to open the last opened file(s) by vim:

alias vil='vim -c "normal! '\''0"' # open the last file
alias vil1='vim -c "normal! '\''1"'  # open the second last file ...
alias vil2='vim -c "normal! '\''2"'

:ol works, but why not use fuzzy search to get the exact match quickly from a long list of file?

There's a very handy plugin, ctrlp which allows you to use :CtrlPMRU, and you can quickly get what you looking for.

For many many years, ctrlp is one of the first thing I would install for vim!

https://github.com/ctrlpvim/ctrlp.vim

Related