Update recently used files on the fly

Startify depends on v:oldfiles which lists recently used files (taken from the
viminfo file). But viminfo only gets updated once in a session: at exiting
Vim. Thus when you worked in a Vim instance for some time and opened multiple
new buffers, v:oldfiles (and therefore :Startify) wouldn't show the most
recently used files anymore.

Luckily v:oldfiles is editable, so now, each new buffer simply prepends its
associated filename to it, making :Startify always up-to-date.

References #148.
This commit is contained in:
Marco Hinz 2015-02-11 14:58:10 +01:00
parent d3d5ea68c4
commit 5a60580711
2 changed files with 32 additions and 33 deletions

View file

@ -12,25 +12,32 @@ let g:loaded_startify = 1
augroup startify
if !get(g:, 'startify_disable_at_vimenter')
autocmd VimEnter * nested
\ if !argc() && (line2byte('$') == -1) && (v:progname =~? '^[-gmnq]\=vim\=x\=\%[\.exe]$')
\ | if get(g:, 'startify_session_autoload') && filereadable('Session.vim')
\ | source Session.vim
\ | else
\ | call startify#insane_in_the_membrane()
\ | endif
\ | endif
\ | autocmd! startify VimEnter
autocmd VimEnter * nested call s:genesis()
endif
if get(g:, 'startify_session_persistence')
autocmd startify VimLeave *
\ if exists('v:this_session') && filewritable(v:this_session)
\ | call startify#session_write(fnameescape(v:this_session))
\ | endif
autocmd VimLeave * call s:extinction()
endif
augroup END
function! s:genesis()
if !argc() && (line2byte('$') == -1) && (v:progname =~? '^[-gmnq]\=vim\=x\=\%[\.exe]$')
if get(g:, 'startify_session_autoload') && filereadable('Session.vim')
source Session.vim
else
call startify#insane_in_the_membrane()
endif
endif
autocmd startify BufRead * if exists('v:oldfiles') | call insert(v:oldfiles, expand('<afile>'), 0) | endif
autocmd! startify VimEnter
endfunction
function! s:extinction()
if exists('v:this_session') && filewritable(v:this_session)
call startify#session_write(fnameescape(v:this_session))
endif
endfunction
command! -nargs=? -bar -complete=customlist,startify#session_list SSave call startify#session_save(<f-args>)
command! -nargs=? -bar -complete=customlist,startify#session_list SLoad call startify#session_load(<f-args>)
command! -nargs=? -bar -complete=customlist,startify#session_list SDelete call startify#session_delete(<f-args>)