2013-04-23 14:41:02 +00:00
|
|
|
" Plugin: https://github.com/mhinz/vim-startify
|
|
|
|
" Description: Start screen displaying recently used stuff.
|
|
|
|
" Maintainer: Marco Hinz <http://github.com/mhinz>
|
2013-04-24 09:31:53 +00:00
|
|
|
" Version: 1.0
|
2013-04-23 14:41:02 +00:00
|
|
|
|
|
|
|
if exists('g:loaded_startify') || &cp
|
|
|
|
finish
|
|
|
|
endif
|
|
|
|
let g:loaded_startify = 1
|
|
|
|
|
|
|
|
" Init {{{1
|
|
|
|
let g:startify_session_dir = resolve(expand(get(g:, 'startify_session_dir', '~/.vim/session')))
|
|
|
|
|
|
|
|
augroup startify
|
|
|
|
autocmd!
|
|
|
|
autocmd VimEnter *
|
|
|
|
\ if !argc() && (line2byte('$') == -1) |
|
|
|
|
\ call s:start() |
|
2013-04-23 15:03:38 +00:00
|
|
|
\ call cursor(6, 5) |
|
2013-04-23 14:41:02 +00:00
|
|
|
\endif
|
|
|
|
augroup END
|
|
|
|
|
2013-04-24 12:28:35 +00:00
|
|
|
command! -nargs=? -bar -complete=customlist,s:get_session_names SSave call startify#save_session(<f-args>)
|
|
|
|
command! -nargs=? -bar -complete=customlist,s:get_session_names SLoad call startify#load_session(<f-args>)
|
|
|
|
|
|
|
|
" Function: s:get_session_names {{{1
|
|
|
|
function! s:get_session_names(lead, ...) abort
|
|
|
|
return map(split(globpath(g:startify_session_dir, '*'.a:lead.'*', '\n')), 'fnamemodify(v:val, ":t")')
|
|
|
|
endfunction
|
|
|
|
|
2013-04-23 14:41:02 +00:00
|
|
|
" Function: s:start {{{1
|
|
|
|
function! s:start() abort
|
|
|
|
setfiletype startify
|
|
|
|
setlocal nonumber norelativenumber nobuflisted buftype=nofile
|
|
|
|
|
2013-04-23 15:03:38 +00:00
|
|
|
call append('$', [' startify>', '', ' [e] <empty buffer>'])
|
2013-04-24 07:28:14 +00:00
|
|
|
let cnt = 0
|
2013-04-23 14:41:02 +00:00
|
|
|
|
|
|
|
if get(g:, 'startify_show_files', 1) && !empty(v:oldfiles)
|
2013-04-24 05:53:33 +00:00
|
|
|
let numfiles = get(g:, 'startify_show_files_number', 10)
|
2013-04-23 14:41:02 +00:00
|
|
|
call append('$', '')
|
|
|
|
for fname in v:oldfiles
|
2013-04-24 07:28:14 +00:00
|
|
|
if !filereadable(expand(fname))
|
|
|
|
\ || (expand(fname) =~# $VIMRUNTIME .'/doc')
|
|
|
|
\ || (fname =~# 'bundle/.*/doc')
|
2013-04-23 14:41:02 +00:00
|
|
|
continue
|
|
|
|
endif
|
2013-04-23 15:03:38 +00:00
|
|
|
call append('$', ' ['. cnt .']'. repeat(' ', 3 - strlen(string(cnt))) . fname)
|
2013-04-23 14:41:02 +00:00
|
|
|
execute 'nnoremap <buffer> '. cnt .' :edit '. fname .'<cr>'
|
|
|
|
let cnt += 1
|
|
|
|
if cnt == numfiles
|
|
|
|
break
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
endif
|
|
|
|
|
|
|
|
let sfiles = split(globpath(g:startify_session_dir, '*'), '\n')
|
|
|
|
|
|
|
|
if get(g:, 'startify_show_sessions', 1) && !empty(sfiles)
|
|
|
|
call append('$', '')
|
|
|
|
for i in range(len(sfiles))
|
|
|
|
let idx = i + cnt
|
2013-04-23 15:03:38 +00:00
|
|
|
call append('$', ' ['. idx .']'. repeat(' ', 3 - strlen(string(idx))) . fnamemodify(sfiles[i], ':t:r'))
|
2013-04-23 14:41:02 +00:00
|
|
|
execute 'nnoremap <buffer> '. idx .' :source '. sfiles[i] .'<cr>'
|
|
|
|
endfor
|
2013-04-24 08:42:35 +00:00
|
|
|
let cnt = idx
|
|
|
|
endif
|
|
|
|
|
|
|
|
if exists('g:startify_bookmarks')
|
|
|
|
call append('$', '')
|
|
|
|
for fname in g:startify_bookmarks
|
|
|
|
if !filereadable(expand(fname))
|
|
|
|
continue
|
|
|
|
endif
|
|
|
|
let cnt += 1
|
|
|
|
call append('$', ' ['. cnt .']'. repeat(' ', 3 - strlen(string(cnt))) . fname)
|
|
|
|
execute 'nnoremap <buffer> '. cnt .' :edit '. fname .'<cr>'
|
|
|
|
endfor
|
2013-04-23 14:41:02 +00:00
|
|
|
endif
|
|
|
|
|
2013-04-23 15:03:38 +00:00
|
|
|
call append('$', ['', ' [q] quit'])
|
2013-04-23 14:41:02 +00:00
|
|
|
|
|
|
|
setlocal nomodifiable
|
|
|
|
|
|
|
|
nnoremap <buffer> q :quit<cr>
|
|
|
|
nnoremap <buffer><silent> e :enew<cr>
|
|
|
|
nnoremap <buffer><silent> <cr> :execute 'normal '. <c-r><c-w><cr>
|
|
|
|
|
|
|
|
autocmd! startify *
|
2013-04-23 15:03:38 +00:00
|
|
|
autocmd startify CursorMoved <buffer> call cursor(line('.') < 4 ? 4 : 0, 5)
|
2013-04-23 14:41:02 +00:00
|
|
|
autocmd startify BufLeave <buffer> autocmd! startify *
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" vim: et sw=2 sts=2
|