startify.vim 19 KB

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