startify.vim 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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',
  11. \ has('win32') ? '$HOME\vimfiles\session' : '~/.vim/session')))
  12. augroup startify
  13. autocmd!
  14. autocmd VimEnter * if !argc() && (line2byte('$') == -1) | call s:insane_in_the_membrane() | endif
  15. augroup END
  16. command! -nargs=? -bar -complete=customlist,startify#get_session_names SSave call startify#save_session(<f-args>)
  17. command! -nargs=? -bar -complete=customlist,startify#get_session_names SLoad call startify#load_session(<f-args>)
  18. command! -nargs=0 -bar Startify enew | call s:insane_in_the_membrane()
  19. " Function: s:insane_in_the_membrane {{{1
  20. function! s:insane_in_the_membrane() abort
  21. setfiletype startify
  22. setlocal nonumber buftype=nofile
  23. if v:version >= 703
  24. setlocal norelativenumber
  25. endif
  26. if get(g:, 'startify_unlisted_buffer', 1)
  27. setlocal nobuflisted
  28. endif
  29. call s:genesis()
  30. endfunction
  31. " Function: s:genesis {{{1
  32. function! s:genesis() abort
  33. call append('$', [' startify>', '', ' [e] <empty buffer>'])
  34. let cnt = 0
  35. let sep = startify#get_sep()
  36. if get(g:, 'startify_show_files', 1) && !empty(v:oldfiles)
  37. let numfiles = get(g:, 'startify_show_files_number', 10)
  38. call append('$', '')
  39. for fname in v:oldfiles
  40. let expfname = expand(fname)
  41. if !filereadable(expfname) || (exists('g:startify_skiplist') && startify#process_skiplist(expfname))
  42. continue
  43. endif
  44. call append('$', ' ['. cnt .']'. repeat(' ', 3 - strlen(string(cnt))) . fname)
  45. execute 'nnoremap <buffer> '. cnt .' :edit '. startify#escape(fname) .'<cr>'
  46. let cnt += 1
  47. if cnt == numfiles
  48. break
  49. endif
  50. endfor
  51. endif
  52. let sfiles = split(globpath(g:startify_session_dir, '*'), '\n')
  53. if get(g:, 'startify_show_sessions', 1) && !empty(sfiles)
  54. call append('$', '')
  55. for i in range(len(sfiles))
  56. let idx = i + cnt
  57. call append('$', ' ['. idx .']'. repeat(' ', 3 - strlen(string(idx))) . fnamemodify(sfiles[i], ':t:r'))
  58. execute 'nnoremap <buffer> '. idx .' :source '. startify#escape(sfiles[i]) .'<cr>'
  59. endfor
  60. let cnt = idx
  61. endif
  62. if exists('g:startify_bookmarks')
  63. call append('$', '')
  64. for fname in g:startify_bookmarks
  65. if !filereadable(expand(fname))
  66. continue
  67. endif
  68. let cnt += 1
  69. call append('$', ' ['. cnt .']'. repeat(' ', 3 - strlen(string(cnt))) . fname)
  70. execute 'nnoremap <buffer> '. cnt .' :edit '. startify#escape(fname) .'<cr>'
  71. endfor
  72. endif
  73. call append('$', ['', ' [q] quit'])
  74. setlocal nomodifiable
  75. nnoremap <buffer> q :quit<cr>
  76. nnoremap <buffer><silent> e :enew<cr>
  77. nnoremap <buffer><silent> <cr> :normal <c-r><c-w><cr>
  78. autocmd! startify *
  79. autocmd startify CursorMoved <buffer> call s:set_cursor()
  80. autocmd startify BufDelete <buffer> autocmd! startify *
  81. call cursor(6, 5)
  82. endfunction
  83. " Function: s:set_cursor {{{1
  84. function! s:set_cursor() abort
  85. let s:line_old = exists('s:line_new') ? s:line_new : 5
  86. let s:line_new = line('.')
  87. if empty(getline(s:line_new))
  88. if s:line_new > s:line_old
  89. let s:line_new += 1
  90. call cursor(s:line_new, 5) " going down
  91. else
  92. let s:line_new -= 1
  93. call cursor((s:line_new < 4 ? 4 : s:line_new), 5) " going up
  94. endif
  95. else
  96. call cursor((s:line_new < 4 ? 4 : 0), 5) " hold cursor in column
  97. endif
  98. endfunction
  99. " vim: et sw=2 sts=2