List and open most recently used files

2 Points

Cem Aksoylar Cem Aksoylar

5 years ago

Display most recently used (MRU) files with a keymap (<F3> here), click Enter to open the file under the cursor, while making sure alternate buffer is not affected.

function! MRU() abort
    enew
    setlocal nobuflisted buftype=nofile bufhidden=wipe noswapfile
    call setline(1, v:oldfiles)
    nnoremap <silent> <buffer> <CR> :keepalt edit <C-r><C-l><CR>
endfunction

nnoremap <silent> <F3> :call MRU()<CR>
MRU