vim-sussify/plugin/startify.vim

124 lines
3.8 KiB
VimL
Raw Normal View History

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-26 10:53:19 +00:00
" Version: 1.2
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',
\ has('win32') ? '$HOME\vimfiles\session' : '~/.vim/session')))
2013-04-23 14:41:02 +00:00
augroup startify
autocmd!
2013-04-26 07:57:49 +00:00
autocmd VimEnter * if !argc() && (line2byte('$') == -1) | call s:insane_in_the_membrane() | 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-26 07:57:49 +00:00
command! -nargs=0 -bar Startify enew | call s:insane_in_the_membrane()
2013-04-24 12:28:35 +00:00
2013-04-26 07:57:49 +00:00
" Function: s:insane_in_the_membrane {{{1
function! s:insane_in_the_membrane() abort
if !empty(v:servername) && exists('g:startify_skiplist_server')
for servname in g:startify_skiplist_server
if servname == v:servername
return
endif
endfor
endif
setlocal nonumber noswapfile bufhidden=wipe
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
setfiletype startify
2013-04-23 14:41:02 +00:00
call append('$', ' [e] <empty buffer>')
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
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 nomodified
2013-04-23 14:41:02 +00:00
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
if exists('g:startify_empty_buffer_key')
execute 'nnoremap <buffer><silent> '. g:startify_empty_buffer_key .' :enew<cr>'
endif
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-26 09:41:22 +00:00
autocmd startify BufWipeout <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('.')
2013-04-25 13:46:10 +00:00
if empty(getline(s:line_new))
2013-04-25 13:42:06 +00:00
if s:line_new > s:line_old
let s:line_new += 1
2013-04-25 13:46:10 +00:00
call cursor(s:line_new, 5) " going down
2013-04-25 13:42:06 +00:00
else
let s:line_new -= 1
2013-04-25 13:46:10 +00:00
call cursor((s:line_new < 4 ? 4 : s:line_new), 5) " going up
2013-04-25 13:42:06 +00:00
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