startify.vim 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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.1
  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. \ endif
  17. augroup END
  18. command! -nargs=? -bar -complete=customlist,startify#get_session_names SSave call startify#save_session(<f-args>)
  19. command! -nargs=? -bar -complete=customlist,startify#get_session_names SLoad call startify#load_session(<f-args>)
  20. command! -nargs=0 -bar Startify enew | call s:start()
  21. " Function: s:start {{{1
  22. function! s:start() abort
  23. setfiletype startify
  24. setlocal nonumber buftype=nofile
  25. if v:version >= 703
  26. setlocal norelativenumber
  27. endif
  28. if get(g:, 'startify_unlisted_buffer', 1)
  29. setlocal nobuflisted
  30. endif
  31. call append('$', [' startify>', '', ' [e] <empty buffer>'])
  32. let cnt = 0
  33. if get(g:, 'startify_show_files', 1) && !empty(v:oldfiles)
  34. let numfiles = get(g:, 'startify_show_files_number', 10)
  35. call append('$', '')
  36. for fname in v:oldfiles
  37. if !filereadable(expand(fname))
  38. \ || (expand(fname) =~# $VIMRUNTIME .'/doc')
  39. \ || (fname =~# 'bundle/.*/doc')
  40. continue
  41. endif
  42. call append('$', ' ['. cnt .']'. repeat(' ', 3 - strlen(string(cnt))) . fname)
  43. execute 'nnoremap <buffer> '. cnt .' :edit '. fname .'<cr>'
  44. let cnt += 1
  45. if cnt == numfiles
  46. break
  47. endif
  48. endfor
  49. endif
  50. let sfiles = split(globpath(g:startify_session_dir, '*'), '\n')
  51. if get(g:, 'startify_show_sessions', 1) && !empty(sfiles)
  52. call append('$', '')
  53. for i in range(len(sfiles))
  54. let idx = i + cnt
  55. call append('$', ' ['. idx .']'. repeat(' ', 3 - strlen(string(idx))) . fnamemodify(sfiles[i], ':t:r'))
  56. execute 'nnoremap <buffer> '. idx .' :source '. sfiles[i] .'<cr>'
  57. endfor
  58. let cnt = idx
  59. endif
  60. if exists('g:startify_bookmarks')
  61. call append('$', '')
  62. for fname in g:startify_bookmarks
  63. if !filereadable(expand(fname))
  64. continue
  65. endif
  66. let cnt += 1
  67. call append('$', ' ['. cnt .']'. repeat(' ', 3 - strlen(string(cnt))) . fname)
  68. execute 'nnoremap <buffer> '. cnt .' :edit '. fname .'<cr>'
  69. endfor
  70. endif
  71. call append('$', ['', ' [q] quit'])
  72. setlocal nomodifiable
  73. nnoremap <buffer> q :quit<cr>
  74. nnoremap <buffer><silent> e :enew<cr>
  75. nnoremap <buffer><silent> <cr> :execute 'normal '. <c-r><c-w><cr>
  76. autocmd! startify *
  77. autocmd startify CursorMoved <buffer> call cursor(line('.') < 4 ? 4 : 0, 5)
  78. autocmd startify BufLeave <buffer> autocmd! startify *
  79. call cursor(6, 5)
  80. endfunction
  81. " vim: et sw=2 sts=2