startify.vim 3.4 KB

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