Post

Show recently changed files with vim-startify

Introduction

vim-startify offers a fancy start screen for vim. Since I use vimwiki which gets synchronized via various devices, I wanted vim-startify to always show me the files that I recently changed in the synched folder. vim-startify does by default show only the local files that you have recently opened in the MRU section, but not the files that have recently been changed in a synched folder. This becomes specifically important if you synchronize your files across multiple devices.

Solution

The solution is quite simple: Under the wiki on github you can find some example configurations that I used as a baseline. Specifically the example of “Show modified and untracked git files” can be slightly changed to the following function in your startify.vim file:

1
2
3
4
function! s:gotModified()
    let files = systemlist('find ~/vimwiki/ -type f -exec ls -t1 {} + | head -5 2>/dev/null')     
    return map(files, "{'line': v:val, 'path': v:val}")
endfunction

With the following structure you will see the recently changed files at the top of the startify page:

1
2
3
4
5
6
7
8
let g:startify_lists = [
        \ { 'type': function('s:gotModified'),  'header': ['   recently modified']},
        \ { 'type': 'files',     'header': ['   MRU']            },
        \ { 'type': 'dir',       'header': ['   MRU '. getcwd()] },
        \ { 'type': 'sessions',  'header': ['   Sessions']       },
        \ { 'type': 'bookmarks', 'header': ['   Bookmarks']      },
        \ { 'type': 'commands',  'header': ['   Commands']       },
        \ ]
This post is licensed under CC BY 4.0 by the author.