This commit is contained in:
Marco Hinz 2013-04-23 16:41:02 +02:00
commit 97e41735ba
5 changed files with 164 additions and 0 deletions

10
.gitignore vendored Normal file
View file

@ -0,0 +1,10 @@
*
!*/
!.gitignore
!autoload/startify.vim
!doc/startify.txt
!plugin/startify.vim
!README.md
!syntax/startify.vim
!startify.png

18
README.md Normal file
View file

@ -0,0 +1,18 @@
_NOTE_: This plugin is still in development
vim-startify
------------
If Vim is called without filenames, vim-startify will bring up a "start screen"
which shows recently used files and also sessions.
Author
------
Marco Hinz `<mh.codebro@gmail.com>`
License
-------
Copyright © Marco Hinz. Distributed under the same terms as Vim itself. See
`:help license`.

34
autoload/startify.vim Normal file
View file

@ -0,0 +1,34 @@
" Plugin: https://github.com/mhinz/vim-startify
" Description: Start screen displaying recently used stuff.
" Maintainer: Marco Hinz <http://github.com/mhinz>
" Version: 0.5
if exists('g:autoloaded_startify') || &cp
finish
endif
let g:autoloaded_startify = 1
function! startify#save_session() abort
let spath = g:startify_session_dir .'/'. input('Save under this session name: ') | redraw
if filereadable(spath)
echo 'Session already exists. Overwrite? [y/n]' | redraw
if nr2char(getchar()) == 'y'
execute 'mksession! '. spath | echo 'Session saved under: '. spath
else
echo 'Did NOT save the session!'
endif
else
execute 'mksession '. spath | echo 'Session saved under: '. spath
endif
endfunction
function! startify#load_session() abort
let spath = g:startify_session_dir .'/'. input('Load this session: ') | redraw
if filereadable(spath)
execute 'source '. spath
else
echo 'No such file!'
endif
endfunction
" vim: et sw=2 sts=2

81
plugin/startify.vim Normal file
View file

@ -0,0 +1,81 @@
" Plugin: https://github.com/mhinz/vim-startify
" Description: Start screen displaying recently used stuff.
" Maintainer: Marco Hinz <http://github.com/mhinz>
" Version: 0.5
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')))
let s:padlen = 3
command! -nargs=0 -bar Lsave call startify#save_session()
command! -nargs=0 -bar Lload call startify#load_session()
nnoremap <silent> <leader>rr :Lload<cr>
nnoremap <silent> <leader>rs :Lsave<cr>
augroup startify
autocmd!
autocmd VimEnter *
\ if !argc() && (line2byte('$') == -1) |
\ call s:start() |
\ call cursor(6, s:padlen+2) |
\endif
augroup END
" Function: s:start {{{1
function! s:start() abort
setfiletype startify
setlocal nonumber norelativenumber nobuflisted buftype=nofile
let numfiles = get(g:, 'startify_show_files_number', 10)
let pad = repeat(' ', s:padlen)
let cnt = 0
call append('$', [pad . 'startify>', '', pad . '[e] <empty buffer>'])
if get(g:, 'startify_show_files', 1) && !empty(v:oldfiles)
call append('$', '')
for fname in v:oldfiles
if !filereadable(expand(fname)) || (fname =~# $VIMRUNTIME .'/doc') || (fname =~# 'bundle/.*/doc')
continue
endif
call append('$', pad .'['. cnt .']'. repeat(' ', s:padlen - strlen(string(cnt))) . fname)
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
call append('$', pad .'['. idx .']'. repeat(' ', s:padlen - strlen(string(idx))) . fnamemodify(sfiles[i], ':t:r'))
execute 'nnoremap <buffer> '. idx .' :source '. sfiles[i] .'<cr>'
endfor
endif
call append('$', ['', pad .'[q] quit'])
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 *
autocmd startify CursorMoved <buffer> call cursor(line('.') < 4 ? 4 : 0, s:padlen+2)
autocmd startify BufLeave <buffer> autocmd! startify *
endfunction
" vim: et sw=2 sts=2

21
syntax/startify.vim Normal file
View file

@ -0,0 +1,21 @@
" Plugin: https://github.com/mhinz/vim-startify
" Description: Start screen displaying recently used stuff.
" Maintainer: Marco Hinz <http://github.com/mhinz>
" Version: 0.5
if exists("b:current_syntax")
finish
endif
syntax match startifyStartify /startify>/
highlight link startifyStartify Function
syntax match startifyDelimiter /\[\|\]/
highlight link startifyDelimiter Delimiter
syntax match startifyNumber /\v\[[eq[:digit:]]+\]/hs=s+1,he=e-1 contains=startifyDelimiter
highlight link startifyNumber Number
let b:current_syntax = 'startify'
" vim: et sw=2 sts=2