Skip to content

Instantly share code, notes, and snippets.

@claytron
Created January 23, 2016 22:22
Show Gist options
  • Save claytron/6d3fd25104729f04cbc8 to your computer and use it in GitHub Desktop.
Save claytron/6d3fd25104729f04cbc8 to your computer and use it in GitHub Desktop.
Most Recently Used Buffer search using FZF in Vim
" Use 'ffr' in normal mode to start it
nmap ffr :MRUFilesCWD<CR>
" MRU handling, limited to current directory
command! MRUFilesCWD call fzf#run({
\ 'source': s:mru_files_for_cwd(),
\ 'sink': 'edit',
\ 'options': '-m -x +s --prompt=MRU:'.shellescape(pathshorten(getcwd())).'/',
\ 'down': '40%' })
" This relies on the yegappan/mru plugin for live MRU updating. Also relies on
" the fact that you don't change the location of the file it uses as its cache.
function! s:mru_files_for_cwd()
return map(filter(
\ systemlist("sed -n '2,$p' ~/.vim_mru_files"),
\ "v:val =~ '^" . getcwd() . "' && v:val !~ '__Tagbar__\\|\\[YankRing]\\|fugitive:\\|NERD_tree\\|^/tmp/\\|.git/'"
\ ), 'fnamemodify(v:val, ":p:.")')
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment