startify.vim 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  1. " vim: et sw=2 sts=2
  2. " Plugin: https://github.com/mhinz/vim-startify
  3. " Description: A fancy start screen for Vim.
  4. " Maintainer: Marco Hinz <http://github.com/mhinz>
  5. if exists('g:autoloaded_startify') || &compatible
  6. finish
  7. endif
  8. let g:autoloaded_startify = 1
  9. " Init: values {{{1
  10. let s:numfiles = get(g:, 'startify_files_number', 10)
  11. let s:show_special = get(g:, 'startify_enable_special', 1)
  12. let s:delete_buffers = get(g:, 'startify_session_delete_buffers')
  13. let s:relative_path = get(g:, 'startify_relative_path') ? ':.' : ':p:~'
  14. let s:session_dir = resolve(expand(get(g:, 'startify_session_dir',
  15. \ has('win32') ? '$HOME\vimfiles\session' : '~/.vim/session')))
  16. let s:skiplist = get(g:, 'startify_skiplist', [
  17. \ 'COMMIT_EDITMSG',
  18. \ escape(fnamemodify($VIMRUNTIME, ':p'), '\') .'doc',
  19. \ 'bundle/.*/doc',
  20. \ ])
  21. " Function: #get_separator {{{1
  22. function! startify#get_separator() abort
  23. return !exists('+shellslash') || &shellslash ? '/' : '\'
  24. endfunction
  25. let s:sep = startify#get_separator()
  26. " Function: #get_lastline {{{1
  27. function! startify#get_lastline() abort
  28. return s:lastline + 1
  29. endfunction
  30. " Function: #insane_in_the_membrane {{{1
  31. function! startify#insane_in_the_membrane() abort
  32. if &insertmode
  33. return
  34. endif
  35. if !empty(v:servername) && exists('g:startify_skiplist_server')
  36. for servname in g:startify_skiplist_server
  37. if servname == v:servername
  38. return
  39. endif
  40. endfor
  41. endif
  42. setlocal
  43. \ bufhidden=wipe
  44. \ buftype=nofile
  45. \ nobuflisted
  46. \ nocursorcolumn
  47. \ nocursorline
  48. \ nolist
  49. \ nonumber
  50. \ noswapfile
  51. if empty(&statusline)
  52. setlocal statusline=\ startify
  53. endif
  54. if v:version >= 703
  55. setlocal norelativenumber
  56. endif
  57. if exists('g:startify_custom_header')
  58. call append('$', g:startify_custom_header)
  59. endif
  60. let s:tick = 0
  61. let s:entries = {}
  62. if s:show_special
  63. call append('$', [' [e] <empty buffer>', ''])
  64. endif
  65. call s:register(line('$')-1, 'e', 'special', 'enew', '')
  66. let s:entry_number = 0
  67. if filereadable('Session.vim')
  68. call append('$', [' [0] '. getcwd() . s:sep .'Session.vim', ''])
  69. call s:register(line('$')-1, '0', 'session',
  70. \ 'call startify#session_delete_buffers() | source', 'Session.vim')
  71. let s:entry_number = 1
  72. let l:show_session = 1
  73. endif
  74. if empty(v:oldfiles)
  75. echohl WarningMsg
  76. echomsg "startify: Can't read viminfo file. Read :help startify-faq-02"
  77. echohl NONE
  78. endif
  79. let b:startify_section_header_lines = []
  80. let s:lists = get(g:, 'startify_list_order', [
  81. \ [' Most recently used files:'],
  82. \ 'files',
  83. \ [' Most recently used files in the current directory:'],
  84. \ 'dir',
  85. \ [' My sessions:'],
  86. \ 'sessions',
  87. \ [' My bookmarks:'],
  88. \ 'bookmarks',
  89. \ ])
  90. for item in s:lists
  91. if type(item) == 1
  92. call s:show_{item}()
  93. else
  94. let s:last_message = item
  95. endif
  96. unlet item
  97. endfor
  98. silent $delete _
  99. if s:show_special
  100. call append('$', ['', ' [q] <quit>'])
  101. call s:register(line('$'), 'q', 'special', 'call s:close()', '')
  102. else
  103. " Don't overwrite the last regular entry, thus +1
  104. call s:register(line('$')+1, 'q', 'special', 'call s:close()', '')
  105. endif
  106. " compute first line offset
  107. let s:firstline = 2
  108. " increase offset if there is a custom header
  109. if exists('g:startify_custom_header')
  110. let s:firstline += len(g:startify_custom_header)
  111. endif
  112. " no special, no local Session.vim, but a section header
  113. if !s:show_special && !exists('l:show_session') && type(s:lists[0]) == 3
  114. let s:firstline += len(s:lists[0]) + 1
  115. endif
  116. let s:lastline = line('$')
  117. if exists('g:startify_custom_footer')
  118. call append('$', g:startify_custom_footer)
  119. endif
  120. setlocal nomodifiable nomodified
  121. call s:set_mappings()
  122. call cursor(s:firstline + (s:show_special ? 2 : 0), 5)
  123. autocmd startify CursorMoved <buffer> call s:set_cursor()
  124. set filetype=startify
  125. silent! doautocmd <nomodeline> User Startified
  126. endfunction
  127. " Function: #session_load {{{1
  128. function! startify#session_load(...) abort
  129. if !isdirectory(s:session_dir)
  130. echomsg 'The session directory does not exist: '. s:session_dir
  131. return
  132. elseif empty(startify#session_list_as_string(''))
  133. echomsg 'There are no sessions...'
  134. return
  135. endif
  136. call inputsave()
  137. let spath = s:session_dir . s:sep . (exists('a:1')
  138. \ ? a:1
  139. \ : input('Load this session: ', fnamemodify(v:this_session, ':t'), 'custom,startify#session_list_as_string'))
  140. \ | redraw
  141. call inputrestore()
  142. if filereadable(spath)
  143. if get(g:, 'startify_session_persistence')
  144. \ && exists('v:this_session')
  145. \ && filewritable(v:this_session)
  146. call startify#session_write(fnameescape(v:this_session))
  147. endif
  148. call startify#session_delete_buffers()
  149. execute 'source '. fnameescape(spath)
  150. else
  151. echo 'No such file: '. spath
  152. endif
  153. endfunction
  154. " Function: #session_save {{{1
  155. function! startify#session_save(...) abort
  156. if !isdirectory(s:session_dir)
  157. if exists('*mkdir')
  158. echo 'The session directory does not exist: '. s:session_dir .'. Create it? [y/n]'
  159. if (nr2char(getchar()) == 'y')
  160. call mkdir(s:session_dir, 'p')
  161. else
  162. echo
  163. return
  164. endif
  165. else
  166. echo 'The session directory does not exist: '. s:session_dir
  167. return
  168. endif
  169. endif
  170. call inputsave()
  171. let sname = exists('a:1')
  172. \ ? a:1
  173. \ : input('Save under this session name: ', fnamemodify(v:this_session, ':t'), 'custom,startify#session_list_as_string')
  174. \ | redraw
  175. call inputrestore()
  176. if empty(sname)
  177. echo 'You gave an empty name!'
  178. return
  179. endif
  180. let spath = s:session_dir . s:sep . sname
  181. if !filereadable(spath)
  182. call startify#session_write(fnameescape(spath))
  183. echo 'Session saved under: '. spath
  184. return
  185. endif
  186. echo 'Session already exists. Overwrite? [y/n]' | redraw
  187. if nr2char(getchar()) == 'y'
  188. call startify#session_write(fnameescape(spath))
  189. echo 'Session saved under: '. spath
  190. else
  191. echo 'Did NOT save the session!'
  192. endif
  193. endfunction
  194. " Function: #session_close {{{1
  195. function! startify#session_close() abort
  196. if exists('v:this_session') && filewritable(v:this_session)
  197. call startify#session_write(fnameescape(v:this_session))
  198. let v:this_session = ''
  199. endif
  200. call startify#session_delete_buffers()
  201. Startify
  202. endfunction
  203. " Function: #session_write {{{1
  204. function! startify#session_write(spath)
  205. let ssop = &sessionoptions
  206. try
  207. " if this function is called while being in the Startify buffer
  208. " (by loading another session or running :SSave/:SLoad directly)
  209. " switch back to the previous buffer before saving the session
  210. if &filetype == 'startify'
  211. let callingbuffer = bufnr('#')
  212. if callingbuffer > 0
  213. execute 'buffer' callingbuffer
  214. endif
  215. endif
  216. " prevent saving already deleted buffers that were in the arglist
  217. for arg in argv()
  218. if !buflisted(arg)
  219. execute 'argdelete' fnameescape(arg)
  220. endif
  221. endfor
  222. set sessionoptions-=options
  223. execute 'mksession!' a:spath
  224. catch
  225. execute 'echoerr' string(v:exception)
  226. finally
  227. let &sessionoptions = ssop
  228. endtry
  229. if exists('g:startify_session_remove_lines')
  230. \ || exists('g:startify_session_savevars')
  231. \ || exists('g:startify_session_savecmds')
  232. execute 'split' a:spath
  233. " remove lines from the session file
  234. if exists('g:startify_session_remove_lines')
  235. for pattern in g:startify_session_remove_lines
  236. execute 'silent global/'. pattern .'/delete _'
  237. endfor
  238. endif
  239. " put existing variables from savevars into session file
  240. if exists('g:startify_session_savevars')
  241. call append(line('$')-3, map(filter(copy(g:startify_session_savevars), 'exists(v:val)'), '"let ". v:val ." = ". strtrans(string(eval(v:val)))'))
  242. endif
  243. " put commands from savecmds into session file
  244. if exists('g:startify_session_savecmds')
  245. call append(line('$')-3, g:startify_session_savecmds)
  246. endif
  247. setlocal bufhidden=delete
  248. silent update
  249. silent hide
  250. endif
  251. endfunction
  252. " Function: #session_delete {{{1
  253. function! startify#session_delete(...) abort
  254. if !isdirectory(s:session_dir)
  255. echo 'The session directory does not exist: '. s:session_dir
  256. return
  257. elseif empty(startify#session_list_as_string(''))
  258. echo 'There are no sessions...'
  259. return
  260. endif
  261. call inputsave()
  262. let spath = s:session_dir . s:sep . (exists('a:1')
  263. \ ? a:1
  264. \ : input('Delete this session: ', fnamemodify(v:this_session, ':t'), 'custom,startify#session_list_as_string'))
  265. \ | redraw
  266. call inputrestore()
  267. echo 'Really delete '. spath .'? [y/n]' | redraw
  268. if (nr2char(getchar()) == 'y')
  269. if delete(spath) == 0
  270. echo 'Deleted session '. spath .'!'
  271. else
  272. echo 'Deletion failed!'
  273. endif
  274. else
  275. echo 'Deletion aborted!'
  276. endif
  277. endfunction
  278. " Function: #session_delete_buffers {{{1
  279. function! startify#session_delete_buffers() abort
  280. if !s:delete_buffers
  281. return
  282. endif
  283. let n = 1
  284. while n <= bufnr('$')
  285. if buflisted(n)
  286. silent execute 'bdelete' n
  287. endif
  288. let n += 1
  289. endwhile
  290. endfunction
  291. " Function: #session_list {{{1
  292. function! startify#session_list(lead, ...) abort
  293. return map(split(globpath(s:session_dir, '*'.a:lead.'*'), '\n'), 'fnamemodify(v:val, ":t")')
  294. endfunction
  295. " Function: #session_list_as_string {{{1
  296. function! startify#session_list_as_string(lead, ...) abort
  297. return join(map(split(globpath(s:session_dir, '*'.a:lead.'*'), '\n'), 'fnamemodify(v:val, ":t")'), "\n")
  298. endfunction
  299. " Function: #debug {{{1
  300. function! startify#debug()
  301. if exists('s:entries')
  302. for k in sort(keys(s:entries))
  303. echomsg '['. k .'] = '. string(s:entries[k])
  304. endfor
  305. endif
  306. endfunction
  307. " Function: #open_buffers {{{1
  308. function! startify#open_buffers(...) abort
  309. if exists('a:1') " used in mappings
  310. call s:open_buffer(s:entries[a:1])
  311. return
  312. endif
  313. let marked = filter(copy(s:entries), 'v:val.marked')
  314. if empty(marked) " open current entry
  315. call s:open_buffer(s:entries[line('.')])
  316. return
  317. endif
  318. enew
  319. setlocal nobuflisted
  320. " Open all marked entries.
  321. for entry in sort(values(marked), 's:sort_by_tick')
  322. call s:open_buffer(entry)
  323. endfor
  324. endfunction
  325. " Function: s:open_buffer {{{1
  326. function! s:open_buffer(entry)
  327. if a:entry.type == 'special'
  328. execute a:entry.cmd
  329. elseif a:entry.type == 'session'
  330. execute a:entry.cmd a:entry.path
  331. elseif a:entry.type == 'file'
  332. if line2byte('$') == -1
  333. execute 'edit' a:entry.path
  334. else
  335. execute a:entry.cmd a:entry.path
  336. endif
  337. call s:check_user_options()
  338. endif
  339. endfunction
  340. " Function: s:display_by_path {{{1
  341. function! s:display_by_path(path_prefix, path_format) abort
  342. let oldfiles = call(get(g:, 'startify_enable_unsafe') ? 's:filter_oldfiles_unsafe' : 's:filter_oldfiles',
  343. \ [a:path_prefix, a:path_format])
  344. if !empty(oldfiles)
  345. if exists('s:last_message')
  346. call s:print_section_header()
  347. endif
  348. for [absolute_path, entry_path] in oldfiles
  349. let index = s:get_index_as_string(s:entry_number)
  350. call append('$', ' ['. index .']'. repeat(' ', (3 - strlen(index))) . entry_path)
  351. if has('win32')
  352. let absolute_path = substitute(absolute_path, '\[', '\[[]', 'g')
  353. endif
  354. call s:register(line('$'), index, 'file', 'edit', absolute_path)
  355. let s:entry_number += 1
  356. endfor
  357. call append('$', '')
  358. endif
  359. endfunction
  360. " Function: s:filter_oldfiles {{{1
  361. function! s:filter_oldfiles(path_prefix, path_format) abort
  362. let path_prefix = '\V'. escape(a:path_prefix, '\')
  363. let counter = s:numfiles
  364. let entries = {}
  365. let oldfiles = []
  366. for fname in v:oldfiles
  367. if counter <= 0
  368. break
  369. endif
  370. let absolute_path = fnamemodify(resolve(fname), ":p")
  371. " filter duplicates, bookmarks and entries from the skiplist
  372. if has_key(entries, absolute_path)
  373. \ || !filereadable(absolute_path)
  374. \ || s:is_in_skiplist(absolute_path)
  375. \ || (exists('g:startify_bookmarks') && s:is_bookmark(absolute_path))
  376. \ || match(absolute_path, path_prefix)
  377. continue
  378. endif
  379. let entry_path = fnamemodify(absolute_path, a:path_format)
  380. let entries[absolute_path] = 1
  381. let counter -= 1
  382. let oldfiles += [[fnameescape(absolute_path), entry_path]]
  383. endfor
  384. return oldfiles
  385. endfun
  386. " Function: s:filter_oldfiles_unsafe {{{1
  387. function! s:filter_oldfiles_unsafe(path_prefix, path_format) abort
  388. let path_prefix = '\V'. escape(a:path_prefix, '\')
  389. let counter = s:numfiles
  390. let entries = {}
  391. let oldfiles = []
  392. for fname in v:oldfiles
  393. if counter <= 0
  394. break
  395. endif
  396. let absolute_path = glob(fnamemodify(fname, ":p"))
  397. if empty(absolute_path)
  398. \ || has_key(entries, absolute_path)
  399. \ || s:is_in_skiplist(absolute_path)
  400. \ || match(absolute_path, path_prefix)
  401. continue
  402. endif
  403. let entry_path = fnamemodify(absolute_path, a:path_format)
  404. let entries[absolute_path] = 1
  405. let counter -= 1
  406. let oldfiles += [[fnameescape(absolute_path), entry_path]]
  407. endfor
  408. return oldfiles
  409. endfun
  410. " Function: s:show_dir {{{1
  411. function! s:show_dir() abort
  412. return s:display_by_path(getcwd(), ':.')
  413. endfunction
  414. " Function: s:show_files {{{1
  415. function! s:show_files() abort
  416. return s:display_by_path('', s:relative_path)
  417. endfunction
  418. " Function: s:show_sessions {{{1
  419. function! s:show_sessions() abort
  420. let sfiles = split(globpath(s:session_dir, '*'), '\n')
  421. if empty(sfiles)
  422. if exists('s:last_message')
  423. unlet s:last_message
  424. endif
  425. return
  426. endif
  427. if exists('s:last_message')
  428. call s:print_section_header()
  429. endif
  430. for i in range(len(sfiles))
  431. let index = s:get_index_as_string(s:entry_number)
  432. let fname = fnamemodify(sfiles[i], ':t')
  433. call append('$', ' ['. index .']'. repeat(' ', (3 - strlen(index))) . fname)
  434. if has('win32')
  435. let fname = substitute(fname, '\[', '\[[]', 'g')
  436. endif
  437. call s:register(line('$'), index, 'session', 'SLoad', fname)
  438. let s:entry_number += 1
  439. endfor
  440. call append('$', '')
  441. endfunction
  442. " Function: s:show_bookmarks {{{1
  443. function! s:show_bookmarks() abort
  444. if !exists('g:startify_bookmarks') || empty(g:startify_bookmarks)
  445. return
  446. endif
  447. if exists('s:last_message')
  448. call s:print_section_header()
  449. endif
  450. for fname in g:startify_bookmarks
  451. let index = s:get_index_as_string(s:entry_number)
  452. call append('$', ' ['. index .']'. repeat(' ', (3 - strlen(index))) . fname)
  453. if has('win32')
  454. let fname = substitute(fname, '\[', '\[[]', 'g')
  455. endif
  456. call s:register(line('$'), index, 'file', 'edit', fname)
  457. let s:entry_number += 1
  458. endfor
  459. call append('$', '')
  460. endfunction
  461. " Function: s:is_in_skiplist {{{1
  462. function! s:is_in_skiplist(arg) abort
  463. for regexp in s:skiplist
  464. try
  465. if a:arg =~# regexp
  466. return 1
  467. endif
  468. catch
  469. echohl WarningMsg
  470. echomsg 'startify: Pattern '. string(regexp) .' threw an exception. Read :help g:startify_skiplist'
  471. echohl NONE
  472. endtry
  473. endfor
  474. endfunction
  475. " Function: s:is_bookmark {{{1
  476. function! s:is_bookmark(arg) abort
  477. for foo in map(filter(copy(g:startify_bookmarks), '!isdirectory(v:val)'), 'resolve(fnamemodify(v:val, ":p"))')
  478. if foo == a:arg
  479. return 1
  480. endif
  481. endfor
  482. endfunction
  483. " Function: s:set_cursor {{{1
  484. function! s:set_cursor() abort
  485. let s:oldline = exists('s:newline') ? s:newline : 5
  486. let s:newline = line('.')
  487. " going up (-1) or down (1)
  488. let movement = 2 * (s:newline > s:oldline) - 1
  489. " skip section headers lines until an entry is found
  490. while index(b:startify_section_header_lines, s:newline) != -1
  491. let s:newline += movement
  492. endwhile
  493. " skip blank lines between lists
  494. if empty(getline(s:newline))
  495. let s:newline += movement
  496. endif
  497. " don't go beyond first or last entry
  498. let s:newline = max([s:firstline, min([s:lastline, s:newline])])
  499. call cursor(s:newline, 5)
  500. endfunction
  501. " Function: s:set_mappings {{{1
  502. function! s:set_mappings() abort
  503. for k in keys(s:entries)
  504. execute 'nnoremap <buffer><silent>' s:entries[k].index
  505. \ ':call startify#open_buffers('. string(k) .')<cr>'
  506. endfor
  507. nnoremap <buffer><silent> i :enew <bar> startinsert<cr>
  508. nnoremap <buffer><silent> <insert> :enew <bar> startinsert<cr>
  509. nnoremap <buffer><silent> b :call <sid>set_mark('B')<cr>
  510. nnoremap <buffer><silent> s :call <sid>set_mark('S')<cr>
  511. nnoremap <buffer><silent> t :call <sid>set_mark('T')<cr>
  512. nnoremap <buffer><silent> v :call <sid>set_mark('V')<cr>
  513. nnoremap <buffer><silent> <cr> :call startify#open_buffers()<cr>
  514. nnoremap <buffer><silent> <2-LeftMouse> :call startify#open_buffers()<cr>
  515. " Prevent 'nnoremap j gj' mappings, since they would break navigation.
  516. " (One can't leave the [x].)
  517. if !empty(maparg('j', 'n'))
  518. nnoremap <buffer> j j
  519. endif
  520. if !empty(maparg('k', 'n'))
  521. nnoremap <buffer> k k
  522. endif
  523. endfunction
  524. " Function: s:set_mark {{{1
  525. function! s:set_mark(type, ...) abort
  526. let index = expand('<cword>')
  527. let line = exists('a:1') ? a:1 : line('.')
  528. let entry = s:entries[line]
  529. if entry.type != 'file'
  530. return
  531. endif
  532. let default_cmds = {
  533. \ 'B': 'edit',
  534. \ 'S': 'split',
  535. \ 'V': 'vsplit',
  536. \ 'T': 'tabnew',
  537. \ }
  538. setlocal modifiable
  539. if entry.marked && index[0] == a:type
  540. let entry.cmd = 'edit'
  541. let entry.marked = 0
  542. execute 'normal! ci]'. entry.index
  543. else
  544. let entry.cmd = default_cmds[a:type]
  545. let entry.marked = 1
  546. let entry.tick = s:tick
  547. let s:tick += 1
  548. execute 'normal! ci]'. repeat(a:type, len(index))
  549. endif
  550. setlocal nomodifiable nomodified
  551. endfunction
  552. " Function: s:sort_by_tick {{{1
  553. function! s:sort_by_tick(one, two)
  554. return a:one.tick - a:two.tick
  555. endfunction
  556. " Function: s:check_user_options {{{1
  557. function! s:check_user_options() abort
  558. let path = expand('%')
  559. let session = path . s:sep .'Session.vim'
  560. " change to VCS root directory
  561. if get(g:, 'startify_session_autoload') && filereadable(session)
  562. execute 'source' session
  563. elseif get(g:, 'startify_change_to_vcs_root')
  564. call s:cd_to_vcs_root(path)
  565. " change directory
  566. elseif get(g:, 'startify_change_to_dir', 1)
  567. if isdirectory(path)
  568. lcd %
  569. else
  570. lcd %:p:h
  571. endif
  572. endif
  573. endfunction
  574. " Function: s:cd_to_vcs_root {{{1
  575. function! s:cd_to_vcs_root(path) abort
  576. let dir = fnamemodify(a:path, ':p:h')
  577. for vcs in [ '.git', '.hg', '.bzr', '.svn' ]
  578. let root = finddir(vcs, dir .';')
  579. if !empty(root)
  580. execute 'cd '. fnamemodify(root, ':h')
  581. return
  582. endif
  583. endfor
  584. endfunction
  585. " Function: s:close {{{1
  586. function! s:close() abort
  587. if len(filter(range(0, bufnr('$')), 'buflisted(v:val)'))
  588. if bufloaded(bufnr('#')) && bufnr('#') != bufnr('%')
  589. buffer #
  590. else
  591. bnext
  592. endif
  593. else
  594. quit
  595. endif
  596. endfunction
  597. " Function: s:get_index_as_string {{{1
  598. function! s:get_index_as_string(idx) abort
  599. if exists('g:startify_custom_indices')
  600. let listlen = len(g:startify_custom_indices)
  601. return (a:idx < listlen) ? g:startify_custom_indices[a:idx] : string(a:idx - listlen)
  602. else
  603. return string(a:idx)
  604. endif
  605. endfunction
  606. " Function: s:print_section_header {{{1
  607. function! s:print_section_header() abort
  608. $
  609. let curline = line('.')
  610. for lnum in range(curline, curline + len(s:last_message) + 1)
  611. call add(b:startify_section_header_lines, lnum)
  612. endfor
  613. call append('$', s:last_message + [''])
  614. unlet s:last_message
  615. endfunction
  616. " Function: s:register {{{1
  617. function! s:register(line, index, type, cmd, path)
  618. let s:entries[a:line] = {
  619. \ 'index': a:index,
  620. \ 'type': a:type,
  621. \ 'cmd': a:cmd,
  622. \ 'path': a:path,
  623. \ 'marked': 0,
  624. \ }
  625. endfunction