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 14:27:09 +00:00
|
|
|
" Version: 1.1
|
2013-04-23 14:41:02 +00:00
|
|
|
|
|
|
|
if exists('g:loaded_startify') || &cp
|
|
|
|
finish
|
|
|
|
endif
|
|
|
|
let g:loaded_startify = 1
|
|
|
|
|
|
|
|
" Init {{{1
|
2013-04-25 11:04:04 +00:00
|
|
|
let g:startify_session_dir = resolve(expand(get(g:, 'startify_session_dir',
|
|
|
|
\ has('win32') ? '$HOME\vimfiles\session' : '~/.vim/session')))
|
2013-04-23 14:41:02 +00:00
|
|
|
|
|
|
|
augroup startify
|
|
|
|
autocmd!
|
|
|
|
autocmd VimEnter *
|
|
|
|
\ if !argc() && (line2byte('$') == -1) |
|
|
|
|
\ call s:start() |
|
2013-04-25 07:33:07 +00:00
|
|
|
\ endif
|
2013-04-23 14:41:02 +00:00
|
|
|
augroup END
|
|
|
|
|
2013-04-24 13:01:43 +00:00
|
|
|
command! -nargs=? -bar -complete=customlist,startify#get_session_names SSave call startify#save_session(<f-args>)
|
|
|
|
command! -nargs=? -bar -complete=customlist,startify#get_session_names SLoad call startify#load_session(<f-args>)
|
2013-04-25 07:33:07 +00:00
|
|
|
command! -nargs=0 -bar Startify enew | call s:start()
|
2013-04-24 12:28:35 +00:00
|
|
|
|
2013-04-23 14:41:02 +00:00
|
|
|
" Function: s:start {{{1
|
|
|
|
function! s:start() abort
|
|
|
|
setfiletype startify
|
2013-04-24 22:46:22 +00:00
|
|
|
setlocal nonumber buftype=nofile
|
2013-04-24 15:14:18 +00:00
|
|
|
if v:version >= 703
|
|
|
|
setlocal norelativenumber
|
|
|
|
endif
|
2013-04-24 22:46:22 +00:00
|
|
|
if get(g:, 'startify_unlisted_buffer', 1)
|
|
|
|
setlocal nobuflisted
|
|
|
|
endif
|
2013-04-23 14:41:02 +00:00
|
|
|
|
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-25 10:38:07 +00:00
|
|
|
let sep = startify#get_sep()
|
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-25 12:10:26 +00:00
|
|
|
let expfname = expand(fname)
|
|
|
|
if !filereadable(expfname) || (exists('g:startify_skiplist') && startify#process_skiplist(expfname))
|
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-25 10:38:07 +00:00
|
|
|
execute 'nnoremap <buffer> '. cnt .' :edit '. startify#escape(fname) .'<cr>'
|
2013-04-23 14:41:02 +00:00
|
|
|
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-25 10:38:07 +00:00
|
|
|
execute 'nnoremap <buffer> '. idx .' :source '. startify#escape(sfiles[i]) .'<cr>'
|
2013-04-23 14:41:02 +00:00
|
|
|
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)
|
2013-04-25 10:38:07 +00:00
|
|
|
execute 'nnoremap <buffer> '. cnt .' :edit '. startify#escape(fname) .'<cr>'
|
2013-04-24 08:42:35 +00:00
|
|
|
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>
|
2013-04-25 10:43:37 +00:00
|
|
|
nnoremap <buffer><silent> <cr> :normal <c-r><c-w><cr>
|
2013-04-23 14:41:02 +00:00
|
|
|
|
|
|
|
autocmd! startify *
|
2013-04-25 13:42:06 +00:00
|
|
|
autocmd startify CursorMoved <buffer> call s:set_cursor()
|
2013-04-23 14:41:02 +00:00
|
|
|
autocmd startify BufLeave <buffer> autocmd! startify *
|
2013-04-25 07:33:07 +00:00
|
|
|
|
|
|
|
call cursor(6, 5)
|
2013-04-23 14:41:02 +00:00
|
|
|
endfunction
|
|
|
|
|
2013-04-25 13:42:06 +00:00
|
|
|
" Function: s:set_cursor {{{1
|
|
|
|
function! s:set_cursor() abort
|
|
|
|
let s:line_old = exists('s:line_new') ? s:line_new : 5
|
|
|
|
let s:line_new = line('.')
|
|
|
|
if empty(getline('.'))
|
|
|
|
if s:line_new > s:line_old
|
|
|
|
call cursor(s:line_new + 1, 5) " going down
|
|
|
|
let s:line_new += 1
|
|
|
|
else
|
|
|
|
call cursor((s:line_new < 4 ? 4 : s:line_new - 1), 5) " going up
|
|
|
|
let s:line_new -= 1
|
|
|
|
endif
|
|
|
|
else
|
|
|
|
call cursor((s:line_new < 4 ? 4 : 0), 5) " hold cursor in column
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2013-04-23 14:41:02 +00:00
|
|
|
" vim: et sw=2 sts=2
|