From 5a60580711c8c6f8be341b8206fb2b7528dedebf Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Wed, 11 Feb 2015 14:58:10 +0100 Subject: [PATCH] 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. --- doc/startify.txt | 32 ++++++++++++-------------------- plugin/startify.vim | 33 ++++++++++++++++++++------------- 2 files changed, 32 insertions(+), 33 deletions(-) diff --git a/doc/startify.txt b/doc/startify.txt index 6d935d0..1547513 100644 --- a/doc/startify.txt +++ b/doc/startify.txt @@ -385,7 +385,7 @@ A hardcoded example: \ ] < -Also have a look at |startify-faq-09|. +Also have a look at |startify-faq-08|. ------------------------------------------------------------------------------ *g:startify_custom_footer* @@ -520,15 +520,13 @@ FAQ *startify-faq* |startify-faq-01| I don't want the start screen to use cursorline! |startify-faq-02| Recent files aren't shown! - |startify-faq-03| Most recently used files don't seem to get updated - at :Startify! - |startify-faq-04| I have broken colors when using sessions! - |startify-faq-05| How to disable common but unimportant files? - |startify-faq-06| CtrlP or NERDTree open a split in Startify! - |startify-faq-07| How do I get both NERDTree and Startify working at + |startify-faq-03| I have broken colors when using sessions! + |startify-faq-04| How to disable common but unimportant files? + |startify-faq-05| CtrlP or NERDTree open a split in Startify! + |startify-faq-06| How do I get both NERDTree and Startify working at startup? - |startify-faq-08| The session autoload feature is not working! - |startify-faq-09| How do I center my header/footer? + |startify-faq-07| The session autoload feature is not working! + |startify-faq-08| How do I center my header/footer? ------------------------------------------------------------------------------ *startify-faq-01* @@ -565,12 +563,6 @@ exactly. ------------------------------------------------------------------------------ *startify-faq-03* -Most recently used files don't seem to get updated at :Startify!~ - -Vim loads the list from viminfo only once, at startup. - ------------------------------------------------------------------------------- - *startify-faq-04* I have broken colors when using sessions!~ Nothing this plugin could do about. Try playing around with 'sessionoptions'. @@ -583,7 +575,7 @@ Some people swear it works for them with these settings: set sessionoptions=blank,curdir,folds,help,tabpages,winpos < ------------------------------------------------------------------------------ - *startify-faq-05* + *startify-faq-04* How to disable common but unimportant files?~ Use the skiplist. Personally I use: @@ -596,7 +588,7 @@ Use the skiplist. Personally I use: \ ] < ------------------------------------------------------------------------------ - *startify-faq-06* + *startify-faq-05* CtrlP or NERDTree open a split in Startify!~ Put this in your vimrc: @@ -609,7 +601,7 @@ solution: let g:ctrlp_reuse_window = 'startify' < ------------------------------------------------------------------------------ - *startify-faq-07* + *startify-faq-06* How do I get both NERDTree and Startify working at startup?~ Put this in your vimrc: @@ -622,7 +614,7 @@ Put this in your vimrc: \ | endif < ------------------------------------------------------------------------------ - *startify-faq-08* + *startify-faq-07* The session autoload feature is not working!~ Do you have NERDTree installed by any chance? If so, try this: @@ -630,7 +622,7 @@ Do you have NERDTree installed by any chance? If so, try this: let NERDTreeHijackNetrw = 0 < ------------------------------------------------------------------------------ - *startify-faq-09* + *startify-faq-08* How do I center my header/footer?~ Try something along these lines: diff --git a/plugin/startify.vim b/plugin/startify.vim index 73af186..e7b206e 100644 --- a/plugin/startify.vim +++ b/plugin/startify.vim @@ -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(''), 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() command! -nargs=? -bar -complete=customlist,startify#session_list SLoad call startify#session_load() command! -nargs=? -bar -complete=customlist,startify#session_list SDelete call startify#session_delete()