startify.vim 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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:start() | 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:start()
  19. " Function: s:start {{{1
  20. function! s:start() 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 append('$', [' startify>', '', ' [e] <empty buffer>'])
  30. let cnt = 0
  31. let sep = startify#get_sep()
  32. if get(g:, 'startify_show_files', 1) && !empty(v:oldfiles)
  33. let numfiles = get(g:, 'startify_show_files_number', 10)
  34. call append('$', '')
  35. for fname in v:oldfiles
  36. let expfname = expand(fname)
  37. if !filereadable(expfname) || (exists('g:startify_skiplist') && startify#process_skiplist(expfname))
  38. continue
  39. endif
  40. call append('$', ' ['. cnt .']'. repeat(' ', 3 - strlen(string(cnt))) . fname)
  41. execute 'nnoremap <buffer> '. cnt .' :edit '. startify#escape(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 '. startify#escape(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 '. startify#escape(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> :normal <c-r><c-w><cr>
  74. autocmd! startify *
  75. autocmd startify CursorMoved <buffer> call s:set_cursor()
  76. autocmd startify BufDelete <buffer> autocmd! startify *
  77. call cursor(6, 5)
  78. endfunction
  79. " Function: s:set_cursor {{{1
  80. function! s:set_cursor() abort
  81. let s:line_old = exists('s:line_new') ? s:line_new : 5
  82. let s:line_new = line('.')
  83. if empty(getline(s:line_new))
  84. if s:line_new > s:line_old
  85. let s:line_new += 1
  86. call cursor(s:line_new, 5) " going down
  87. else
  88. let s:line_new -= 1
  89. call cursor((s:line_new < 4 ? 4 : s:line_new), 5) " going up
  90. endif
  91. else
  92. call cursor((s:line_new < 4 ? 4 : 0), 5) " hold cursor in column
  93. endif
  94. endfunction
  95. " vim: et sw=2 sts=2