Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

use search in "browse oldfiles" list?

Tags:

vim

Is there a way to search the list of recently used file in Vim? The list can be displayed using

browse old

but / does not work. I am aware of some plugins (e.g. MRU) but would prefer to not use a plugin.

like image 537
Xu Wang Avatar asked Feb 21 '14 14:02

Xu Wang


2 Answers

Here's a short scriptlet that opens the file list in a scratch buffer. As a bonus, it defines a local <Enter> mapping to :edit the current file. With this, you can search with all built-in commands like /:

:new +setl\ buftype=nofile | 0put =v:oldfiles | nnoremap <buffer> <CR> :e <C-r>=getline('.')<CR><CR>
like image 170
Ingo Karkat Avatar answered Oct 06 '22 00:10

Ingo Karkat


If you really want to avoid a plugin:

  1. :new The old files will be printed into this buffer
  2. :redir @X where X is a temporary register`
  3. :silent echo(v:oldfiles) 'Silent' is there to not actually print onto your screen
  4. :redir END
  5. "Xp paste the temporary register
  6. (optional) Do some regex-fu to put each file on its own line.

Put the above into a function and voila. Also :help redir

like image 27
DBedrenko Avatar answered Oct 06 '22 01:10

DBedrenko