From 97e41735ba0c4c0343ee8eff99b817a5e49a646e Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Tue, 23 Apr 2013 16:41:02 +0200 Subject: [PATCH] init --- .gitignore | 10 ++++++ README.md | 18 ++++++++++ autoload/startify.vim | 34 ++++++++++++++++++ plugin/startify.vim | 81 +++++++++++++++++++++++++++++++++++++++++++ syntax/startify.vim | 21 +++++++++++ 5 files changed, 164 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 autoload/startify.vim create mode 100644 plugin/startify.vim create mode 100644 syntax/startify.vim diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a785777 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +* +!*/ + +!.gitignore +!autoload/startify.vim +!doc/startify.txt +!plugin/startify.vim +!README.md +!syntax/startify.vim +!startify.png diff --git a/README.md b/README.md new file mode 100644 index 0000000..f7943ef --- /dev/null +++ b/README.md @@ -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 `` + +License +------- + +Copyright © Marco Hinz. Distributed under the same terms as Vim itself. See +`:help license`. diff --git a/autoload/startify.vim b/autoload/startify.vim new file mode 100644 index 0000000..19e23fd --- /dev/null +++ b/autoload/startify.vim @@ -0,0 +1,34 @@ +" Plugin: https://github.com/mhinz/vim-startify +" Description: Start screen displaying recently used stuff. +" Maintainer: Marco Hinz +" 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 diff --git a/plugin/startify.vim b/plugin/startify.vim new file mode 100644 index 0000000..7caaba7 --- /dev/null +++ b/plugin/startify.vim @@ -0,0 +1,81 @@ +" Plugin: https://github.com/mhinz/vim-startify +" Description: Start screen displaying recently used stuff. +" Maintainer: Marco Hinz +" 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 rr :Lload +nnoremap rs :Lsave + +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] ']) + + 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 '. cnt .' :edit '. fname .'' + 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 '. idx .' :source '. sfiles[i] .'' + endfor + endif + + call append('$', ['', pad .'[q] quit']) + + setlocal nomodifiable + + nnoremap q :quit + nnoremap e :enew + nnoremap :execute 'normal '. + + autocmd! startify * + autocmd startify CursorMoved call cursor(line('.') < 4 ? 4 : 0, s:padlen+2) + autocmd startify BufLeave autocmd! startify * +endfunction + +" vim: et sw=2 sts=2 diff --git a/syntax/startify.vim b/syntax/startify.vim new file mode 100644 index 0000000..523a643 --- /dev/null +++ b/syntax/startify.vim @@ -0,0 +1,21 @@ +" Plugin: https://github.com/mhinz/vim-startify +" Description: Start screen displaying recently used stuff. +" Maintainer: Marco Hinz +" 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