startify.vim 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. if exists('+shellslash')
  32. let old_ssl = &shellslash
  33. set noshellslash
  34. endif
  35. call append('$', [' startify>', '', ' [e] <empty buffer>'])
  36. let cnt = 0
  37. if get(g:, 'startify_show_files', 1) && !empty(v:oldfiles)
  38. let numfiles = get(g:, 'startify_show_files_number', 10)
  39. call append('$', '')
  40. for fname in v:oldfiles
  41. if !filereadable(expand(fname))
  42. \ || (expand(fname) =~# $VIMRUNTIME .'/doc')
  43. \ || (fname =~# 'bundle/.*/doc')
  44. continue
  45. endif
  46. call append('$', ' ['. cnt .']'. repeat(' ', 3 - strlen(string(cnt))) . fname)
  47. execute 'nnoremap <buffer> '. cnt .' :edit '. fnameescape(fname) .'<cr>'
  48. let cnt += 1
  49. if cnt == numfiles
  50. break
  51. endif
  52. endfor
  53. endif
  54. let sfiles = split(globpath(g:startify_session_dir, '*'), '\n')
  55. if get(g:, 'startify_show_sessions', 1) && !empty(sfiles)
  56. call append('$', '')
  57. for i in range(len(sfiles))
  58. let idx = i + cnt
  59. call append('$', ' ['. idx .']'. repeat(' ', 3 - strlen(string(idx))) . fnamemodify(sfiles[i], ':t:r'))
  60. execute 'nnoremap <buffer> '. idx .' :source '. fnameescape(sfiles[i]) .'<cr>'
  61. endfor
  62. let cnt = idx
  63. endif
  64. if exists('g:startify_bookmarks')
  65. call append('$', '')
  66. for fname in g:startify_bookmarks
  67. if !filereadable(expand(fname))
  68. continue
  69. endif
  70. let cnt += 1
  71. call append('$', ' ['. cnt .']'. repeat(' ', 3 - strlen(string(cnt))) . fname)
  72. execute 'nnoremap <buffer> '. cnt .' :edit '. fnameescape(fname) .'<cr>'
  73. endfor
  74. endif
  75. call append('$', ['', ' [q] quit'])
  76. setlocal nomodifiable
  77. nnoremap <buffer> q :quit<cr>
  78. nnoremap <buffer><silent> e :enew<cr>
  79. nnoremap <buffer><silent> <cr> :execute 'normal '. <c-r><c-w><cr>
  80. autocmd! startify *
  81. autocmd startify CursorMoved <buffer> call cursor(line('.') < 4 ? 4 : 0, 5)
  82. autocmd startify BufLeave <buffer> autocmd! startify *
  83. if exists('old_ssl')
  84. let &shellslash = old_ssl
  85. endif
  86. call cursor(6, 5)
  87. endfunction
  88. " vim: et sw=2 sts=2