startify.vim 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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.0
  5. if exists('g:autoloaded_startify') || &cp
  6. finish
  7. endif
  8. let g:autoloaded_startify = 1
  9. function! startify#get_session_names(lead, ...) abort
  10. return map(split(globpath(g:startify_session_dir, '*'.a:lead.'*', '\n')), 'fnamemodify(v:val, ":t")')
  11. endfunction
  12. function! startify#get_session_names_as_string(lead, ...) abort
  13. return join(map(split(globpath(g:startify_session_dir, '*'.a:lead.'*', '\n')), 'fnamemodify(v:val, ":t")'), "\n")
  14. endfunction
  15. function! startify#save_session(...) abort
  16. if !isdirectory(g:startify_session_dir)
  17. echo 'The session directory does not exist: '. g:startify_session_dir
  18. return
  19. endif
  20. let spath = g:startify_session_dir .'/'. (exists('a:1')
  21. \ ? a:1
  22. \ : input('Save under this session name: ', '', 'custom,startify#get_session_names_as_string'))
  23. \ | redraw
  24. if !filereadable(spath)
  25. execute 'mksession '. spath | echo 'Session saved under: '. spath
  26. return
  27. endif
  28. echo 'Session already exists. Overwrite? [y/n]' | redraw
  29. if nr2char(getchar()) == 'y'
  30. execute 'mksession! '. spath | echo 'Session saved under: '. spath
  31. else
  32. echo 'Did NOT save the session!'
  33. endif
  34. endfunction
  35. function! startify#load_session(...) abort
  36. if !isdirectory(g:startify_session_dir)
  37. echo 'The session directory does not exist: '. g:startify_session_dir
  38. return
  39. endif
  40. let spath = g:startify_session_dir .'/'. (exists('a:1')
  41. \ ? a:1
  42. \ : input('Load this session: ', '', 'custom,startify#get_session_names_as_string'))
  43. \ | redraw
  44. if filereadable(spath)
  45. execute 'source '. spath
  46. else
  47. echo 'No such file: '. spath
  48. endif
  49. endfunction
  50. " vim: et sw=2 sts=2