-
Notifications
You must be signed in to change notification settings - Fork 187
Example configurations
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
- Use NERDTree bookmarks
- Display NERDTree bookmarks as a separate list
- Auto-load and auto-save a session named from Git branch
- Create a custom header using figlet
- Read custom header from a file
- Show random quote and cow
" 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.
let g:startify_bookmarks = systemlist("cut -sd' ' -f 2- ~/.NERDTreeBookmarks")
" 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']}
\]
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()
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'))
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 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'))