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-27 16:43:21 +00:00
|
|
|
" Version: 1.3
|
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!
|
2013-04-28 07:17:57 +00:00
|
|
|
autocmd VimEnter *
|
2013-04-28 23:34:53 +00:00
|
|
|
\ if !argc() && (line2byte('$') == -1) && (v:progname =~? '^[gm]\=vim\%[\.exe]$') |
|
2013-04-28 07:17:57 +00:00
|
|
|
\ 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
|
2013-04-26 08:18:31 +00:00
|
|
|
if !empty(v:servername) && exists('g:startify_skiplist_server')
|
|
|
|
for servname in g:startify_skiplist_server
|
|
|
|
if servname == v:servername
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
endif
|
2013-04-26 10:40:42 +00:00
|
|
|
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
|
2013-04-26 08:18:31 +00:00
|
|
|
setfiletype startify
|
2013-04-23 14:41:02 +00:00
|
|
|
|
2013-04-28 11:30:05 +00:00
|
|
|
call append('$', ' [i] <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-27 11:53:13 +00:00
|
|
|
execute 'nnoremap <buffer> '. cnt .' :edit '. startify#escape(fname) .' <bar> lcd %:h<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-27 11:53:13 +00:00
|
|
|
execute 'nnoremap <buffer> '. cnt .' :edit '. startify#escape(fname) .' <bar> lcd %:h<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
|
|
|
|
2013-04-26 10:40:42 +00:00
|
|
|
setlocal nomodifiable nomodified
|
2013-04-23 14:41:02 +00:00
|
|
|
|
2013-04-28 11:30:05 +00:00
|
|
|
nnoremap <buffer><silent> i :enew<cr>
|
2013-04-27 16:40:59 +00:00
|
|
|
nnoremap <buffer> <cr> :normal <c-r><c-w><cr>
|
|
|
|
nnoremap <buffer> <2-LeftMouse> :execute 'normal '. matchstr(getline('.'), '\w\+')<cr>
|
2013-04-27 12:58:23 +00:00
|
|
|
nnoremap <buffer> q
|
|
|
|
\ :if len(filter(range(0, bufnr('$')), 'buflisted(v:val)')) > 1 <bar>
|
|
|
|
\ bd <bar>
|
|
|
|
\ else <bar>
|
|
|
|
\ quit <bar>
|
|
|
|
\ endif<cr>
|
2013-04-23 14:41:02 +00:00
|
|
|
|
2013-04-27 07:57:11 +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
|
|
|
|
2013-04-27 08:17:29 +00:00
|
|
|
call cursor(4, 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-27 08:17:29 +00:00
|
|
|
call cursor((s:line_new < 2 ? 2 : s:line_new), 5) " going up
|
2013-04-25 13:42:06 +00:00
|
|
|
endif
|
|
|
|
else
|
2013-04-27 08:17:29 +00:00
|
|
|
call cursor((s:line_new < 2 ? 2 : 0), 5) " hold cursor in column
|
2013-04-25 13:42:06 +00:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2013-04-23 14:41:02 +00:00
|
|
|
" vim: et sw=2 sts=2
|