startify.vim 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. " Plugin: https://github.com/mhinz/vim-startify
  2. " Description: Start screen displaying recently used stuff.
  3. " Maintainer: Marco Hinz <http://github.com/mhinz>
  4. " Version: 1.0
  5. if exists('g:loaded_startify') || &cp
  6. finish
  7. endif
  8. let g:loaded_startify = 1
  9. " Init {{{1
  10. let g:startify_session_dir = resolve(expand(get(g:, 'startify_session_dir', '~/.vim/session')))
  11. augroup startify
  12. autocmd!
  13. autocmd VimEnter *
  14. \ if !argc() && (line2byte('$') == -1) |
  15. \ call s:start() |
  16. \ call cursor(6, 5) |
  17. \endif
  18. augroup END
  19. command! -nargs=? -bar -complete=customlist,s:get_session_names SSave call startify#save_session(<f-args>)
  20. command! -nargs=? -bar -complete=customlist,s:get_session_names SLoad call startify#load_session(<f-args>)
  21. " Function: s:get_session_names {{{1
  22. function! s:get_session_names(lead, ...) abort
  23. return map(split(globpath(g:startify_session_dir, '*'.a:lead.'*', '\n')), 'fnamemodify(v:val, ":t")')
  24. endfunction
  25. " Function: s:start {{{1
  26. function! s:start() abort
  27. setfiletype startify
  28. setlocal nonumber norelativenumber nobuflisted buftype=nofile
  29. call append('$', [' startify>', '', ' [e] <empty buffer>'])
  30. let cnt = 0
  31. if get(g:, 'startify_show_files', 1) && !empty(v:oldfiles)
  32. let numfiles = get(g:, 'startify_show_files_number', 10)
  33. call append('$', '')
  34. for fname in v:oldfiles
  35. if !filereadable(expand(fname))
  36. \ || (expand(fname) =~# $VIMRUNTIME .'/doc')
  37. \ || (fname =~# 'bundle/.*/doc')
  38. continue
  39. endif
  40. call append('$', ' ['. cnt .']'. repeat(' ', 3 - strlen(string(cnt))) . fname)
  41. execute 'nnoremap <buffer> '. cnt .' :edit '. fname .'<cr>'
  42. let cnt += 1
  43. if cnt == numfiles
  44. break
  45. endif
  46. endfor
  47. endif
  48. let sfiles = split(globpath(g:startify_session_dir, '*'), '\n')
  49. if get(g:, 'startify_show_sessions', 1) && !empty(sfiles)
  50. call append('$', '')
  51. for i in range(len(sfiles))
  52. let idx = i + cnt
  53. call append('$', ' ['. idx .']'. repeat(' ', 3 - strlen(string(idx))) . fnamemodify(sfiles[i], ':t:r'))
  54. execute 'nnoremap <buffer> '. idx .' :source '. sfiles[i] .'<cr>'
  55. endfor
  56. let cnt = idx
  57. endif
  58. if exists('g:startify_bookmarks')
  59. call append('$', '')
  60. for fname in g:startify_bookmarks
  61. if !filereadable(expand(fname))
  62. continue
  63. endif
  64. let cnt += 1
  65. call append('$', ' ['. cnt .']'. repeat(' ', 3 - strlen(string(cnt))) . fname)
  66. execute 'nnoremap <buffer> '. cnt .' :edit '. fname .'<cr>'
  67. endfor
  68. endif
  69. call append('$', ['', ' [q] quit'])
  70. setlocal nomodifiable
  71. nnoremap <buffer> q :quit<cr>
  72. nnoremap <buffer><silent> e :enew<cr>
  73. nnoremap <buffer><silent> <cr> :execute 'normal '. <c-r><c-w><cr>
  74. autocmd! startify *
  75. autocmd startify CursorMoved <buffer> call cursor(line('.') < 4 ? 4 : 0, 5)
  76. autocmd startify BufLeave <buffer> autocmd! startify *
  77. endfunction
  78. " vim: et sw=2 sts=2