Skip to content

Example configurations

karamellpelle edited this page Aug 17, 2023 · 16 revisions

If you came up with any cool configuration worth sharing, add it here. Don't forget to add a link at the top as well.

Show modified and untracked git files

" returns all modified files of the current git repo
" `2>/dev/null` makes the command fail quietly, so that when we are not
" in a git repo, the list will be empty
function! s:gitModified()
    let files = systemlist('git ls-files -m 2>/dev/null')
    return map(files, "{'line': v:val, 'path': v:val}")
endfunction

" same as above, but show untracked files, honouring .gitignore
function! s:gitUntracked()
    let files = systemlist('git ls-files -o --exclude-standard 2>/dev/null')
    return map(files, "{'line': v:val, 'path': v:val}")
endfunction

let g:startify_lists = [
        \ { 'type': 'files',     'header': ['   MRU']            },
        \ { 'type': 'dir',       'header': ['   MRU '. getcwd()] },
        \ { 'type': 'sessions',  'header': ['   Sessions']       },
        \ { 'type': 'bookmarks', 'header': ['   Bookmarks']      },
        \ { 'type': function('s:gitModified'),  'header': ['   git modified']},
        \ { 'type': function('s:gitUntracked'), 'header': ['   git untracked']},
        \ { 'type': 'commands',  'header': ['   Commands']       },
        \ ]

See :h g:startify_lists for more information.


Use NERDTree bookmarks

let g:startify_bookmarks = systemlist("cut -sd' ' -f 2- ~/.NERDTreeBookmarks")

Display NERDTree bookmarks as a separate list

" Read ~/.NERDTreeBookmarks file and takes its second column
function! s:nerdtreeBookmarks()
    let bookmarks = systemlist("cut -d' ' -f 2- ~/.NERDTreeBookmarks")
    let bookmarks = bookmarks[0:-2] " Slices an empty last line
    return map(bookmarks, "{'line': v:val, 'path': v:val}")
endfunction

let g:startify_lists = [
        \ { 'type': function('s:nerdtreeBookmarks'), 'header': ['   NERDTree Bookmarks']}
        \]

Auto-load and auto-save a session named from Git branch

This will save a unique session with the Git branch name, overwriting the session if the branch already exists. If not in a Git project, the session will be saved as "no-project".

This requires vim-gitbranch.

function! GetUniqueSessionName()
  let path = fnamemodify(getcwd(), ':~:t')
  let path = empty(path) ? 'no-project' : path
  let branch = gitbranch#name()
  let branch = empty(branch) ? '' : '-' . branch
  return substitute(path . branch, '/', '-', 'g')
endfunction

autocmd User        StartifyReady silent execute 'SLoad '  . GetUniqueSessionName()
autocmd VimLeavePre *             silent execute 'SSave! ' . GetUniqueSessionName()

Create a custom header using figlet

This will generate an ASCII art header using Figlet rather then having to create it by hand.

 let g:startify_custom_header =
       \ startify#pad(split(system('figlet -w 100 VIM2020'), '\n'))

Read custom header from a file

It is possible to have startify read a custom header from a file instead of generating it on startup. For example we can save the output of figlet -f Roman Vim | boxes -d parchment to a file called vim-ascii.txt and simply read from it. Remember to provide the correct path to your custom header file.

let g:startify_custom_header =
             \ startify#pad(readfile('/path/to/vim-ascii.txt'))

Show random quote and cow

Show a random quote and random cow centered and with a wider speech balloon (adapted to also work with the current version of the new cowsay-apj project):

    let s:header_cmd = 
      \ 'fortune | cowsay -W 80 -f $(cowsay -l | sed "/[A-Z].*$/d" | shuf -n 1)'
    let g:startify_custom_header =
      \ startify#center(split(system(s:header_cmd), '\n'))