I have a problem with finding a proper solution for most recently used files with the FZF Vim plugin.
This plugin should have features like:
I tried two solutions
command! FZFMru call fzf#run({
\ 'source': reverse(s:all_files()),
\ 'sink': 'edit',
\ 'options': '-m --no-sort -x',
\ 'down': '40%' })
function! s:all_files()
return extend(
\ filter(copy(v:oldfiles),
\ "v:val !~ 'fugitive:\\|\\.svg|NERD_tree\\|^/tmp/\\|.git/'"),
\ map(filter(range(1, bufnr('$')), 'buflisted(v:val)'), 'bufname(v:val)'))
endfunction
This one works during open session but when I restart Vim I don't see all last opened files.
command! FZFMru call s:fzf_wrap({
\'source': 'bash -c "'.
\ 'echo -e \"'.s:old_files().'\";'.
\ 'ag -l -g \"\"'.
\ '"',
\})
function! s:fzf_wrap(dict)
let defaults = {
\'sink' : 'edit',
\'options' : '+s -e -m',
\'tmux_height': '40%',
\}
call extend(a:dict, defaults, 'keep')
call fzf#run(a:dict)
endfunction
function! s:old_files()
let oldfiles = copy(v:oldfiles)
call filter(oldfiles, 'v:val !~ "fugitive"')
call filter(oldfiles, 'v:val !~ "NERD_tree"')
call filter(oldfiles, 'v:val !~ "^/tmp/"')
call filter(oldfiles, 'v:val !~ ".git/"')
call filter(oldfiles, 'v:val !~ ".svg"')
return join(oldfiles, '\n')
endfunction
This solution filters files properly but works only for files opened in previous session. So I need to restart Vim to get the current buffer.
Did you find a working solution for FZFMru in Vim?
I found a latest Junegunn plugin.
Plug 'junegunn/fzf.vim'
It covers a case.
Just add
nmap <silent> <leader>m :History<CR>
Thanks Junegunn :)
One possible solution is to leverage the neomru plugin which will save your most recently visted files to a cache located at ~/.cache/neomru/file
.
After installing the neomru
plugin with your preferred plugin manager, you can define a mapping to search the cache file, for example:
nnoremap <silent> <Leader>m :call fzf#run({ \ 'source': 'sed "1d" $HOME/.cache/neomru/file', \ 'sink': 'e ' \ })<CR>
Check out https://github.com/junegunn/fzf/wiki/Examples-(vim). Lots of cool stuff there, including MRU, tags search, and much more. Junegunn implemented MRU simply as:
command! FZFMru call fzf#run({
\ 'source': v:oldfiles,
\ 'sink': 'e',
\ 'options': '-m -x +s',
\ 'down': '40%'})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With