startify.vim 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  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')
  302. execute s:entries[a:1].cmd s:entries[a:1].path
  303. return
  304. endif
  305. let marked = filter(copy(s:entries), 'v:val.marked')
  306. if empty(marked)
  307. call s:set_mark('B')
  308. return startify#open_buffers()
  309. endif
  310. enew
  311. setlocal nobuflisted
  312. for entry in sort(values(marked), 's:sort_by_tick')
  313. if line2byte('$') == -1
  314. execute 'edit' entry.path
  315. else
  316. execute entry.cmd entry.path
  317. endif
  318. call s:check_user_options()
  319. endfor
  320. endfunction
  321. " Function: s:display_by_path {{{1
  322. function! s:display_by_path(path_prefix, path_format) abort
  323. let oldfiles = call(get(g:, 'startify_enable_unsafe') ? 's:filter_oldfiles_unsafe' : 's:filter_oldfiles',
  324. \ [a:path_prefix, a:path_format])
  325. if !empty(oldfiles)
  326. if exists('s:last_message')
  327. call s:print_section_header()
  328. endif
  329. for [absolute_path, entry_path] in oldfiles
  330. let index = s:get_index_as_string(s:entry_number)
  331. call append('$', ' ['. index .']'. repeat(' ', (3 - strlen(index))) . entry_path)
  332. if has('win32')
  333. let absolute_path = substitute(absolute_path, '\[', '\[[]', 'g')
  334. endif
  335. let s:entries[line('$')] = {
  336. \ 'index': index,
  337. \ 'type': 'file',
  338. \ 'cmd': 'edit',
  339. \ 'path': absolute_path,
  340. \ 'marked': 0,
  341. \ }
  342. let s:entry_number += 1
  343. endfor
  344. call append('$', '')
  345. endif
  346. endfunction
  347. " Function: s:filter_oldfiles {{{1
  348. function! s:filter_oldfiles(path_prefix, path_format) abort
  349. let path_prefix = '\V'. escape(a:path_prefix, '\')
  350. let counter = s:numfiles
  351. let entries = {}
  352. let oldfiles = []
  353. for fname in v:oldfiles
  354. if counter <= 0
  355. break
  356. endif
  357. let absolute_path = fnamemodify(resolve(fname), ":p")
  358. " filter duplicates, bookmarks and entries from the skiplist
  359. if has_key(entries, absolute_path)
  360. \ || !filereadable(absolute_path)
  361. \ || s:is_in_skiplist(absolute_path)
  362. \ || (exists('g:startify_bookmarks') && s:is_bookmark(absolute_path))
  363. \ || match(absolute_path, path_prefix)
  364. continue
  365. endif
  366. let entry_path = fnamemodify(absolute_path, a:path_format)
  367. let entries[absolute_path] = 1
  368. let counter -= 1
  369. let oldfiles += [[fnameescape(absolute_path), entry_path]]
  370. endfor
  371. return oldfiles
  372. endfun
  373. " Function: s:filter_oldfiles_unsafe {{{1
  374. function! s:filter_oldfiles_unsafe(path_prefix, path_format) abort
  375. let path_prefix = '\V'. escape(a:path_prefix, '\')
  376. let counter = s:numfiles
  377. let entries = {}
  378. let oldfiles = []
  379. for fname in v:oldfiles
  380. if counter <= 0
  381. break
  382. endif
  383. let absolute_path = glob(fnamemodify(fname, ":p"))
  384. if empty(absolute_path)
  385. \ || has_key(entries, absolute_path)
  386. \ || s:is_in_skiplist(absolute_path)
  387. \ || match(absolute_path, path_prefix)
  388. continue
  389. endif
  390. let entry_path = fnamemodify(absolute_path, a:path_format)
  391. let entries[absolute_path] = 1
  392. let counter -= 1
  393. let oldfiles += [[fnameescape(absolute_path), entry_path]]
  394. endfor
  395. return oldfiles
  396. endfun
  397. " Function: s:show_dir {{{1
  398. function! s:show_dir() abort
  399. return s:display_by_path(getcwd(), ':.')
  400. endfunction
  401. " Function: s:show_files {{{1
  402. function! s:show_files() abort
  403. return s:display_by_path('', s:relative_path)
  404. endfunction
  405. " Function: s:show_sessions {{{1
  406. function! s:show_sessions() abort
  407. let sfiles = split(globpath(s:session_dir, '*'), '\n')
  408. if empty(sfiles)
  409. if exists('s:last_message')
  410. unlet s:last_message
  411. endif
  412. return
  413. endif
  414. if exists('s:last_message')
  415. call s:print_section_header()
  416. endif
  417. for i in range(len(sfiles))
  418. let index = s:get_index_as_string(s:entry_number)
  419. let fname = fnamemodify(sfiles[i], ':t')
  420. call append('$', ' ['. index .']'. repeat(' ', (3 - strlen(index))) . fname)
  421. if has('win32')
  422. let fname = substitute(fname, '\[', '\[[]', 'g')
  423. endif
  424. let s:entries[line('$')] = {
  425. \ 'index': index,
  426. \ 'type': 'session',
  427. \ 'cmd': 'SLoad',
  428. \ 'path': fname,
  429. \ 'marked': 0,
  430. \ }
  431. let s:entry_number += 1
  432. endfor
  433. call append('$', '')
  434. endfunction
  435. " Function: s:show_bookmarks {{{1
  436. function! s:show_bookmarks() abort
  437. if !exists('g:startify_bookmarks') || empty(g:startify_bookmarks)
  438. return
  439. endif
  440. if exists('s:last_message')
  441. call s:print_section_header()
  442. endif
  443. for fname in g:startify_bookmarks
  444. let index = s:get_index_as_string(s:entry_number)
  445. call append('$', ' ['. index .']'. repeat(' ', (3 - strlen(index))) . fname)
  446. if has('win32')
  447. let absolute_path = substitute(fname, '\[', '\[[]', 'g')
  448. endif
  449. let s:entries[line('$')] = {
  450. \ 'index': index,
  451. \ 'type': 'file',
  452. \ 'cmd': 'edit',
  453. \ 'path': fname,
  454. \ 'marked': 0,
  455. \ }
  456. let s:entry_number += 1
  457. endfor
  458. call append('$', '')
  459. endfunction
  460. " Function: s:is_in_skiplist {{{1
  461. function! s:is_in_skiplist(arg) abort
  462. for regexp in s:skiplist
  463. if (a:arg =~# regexp)
  464. return 1
  465. endif
  466. endfor
  467. endfunction
  468. " Function: s:is_bookmark {{{1
  469. function! s:is_bookmark(arg) abort
  470. for foo in map(filter(copy(g:startify_bookmarks), '!isdirectory(v:val)'), 'resolve(fnamemodify(v:val, ":p"))')
  471. if foo == a:arg
  472. return 1
  473. endif
  474. endfor
  475. endfunction
  476. " Function: s:set_cursor {{{1
  477. function! s:set_cursor() abort
  478. let s:oldline = exists('s:newline') ? s:newline : 5
  479. let s:newline = line('.')
  480. " going up (-1) or down (1)
  481. let movement = 2 * (s:newline > s:oldline) - 1
  482. " skip section headers lines until an entry is found
  483. while index(b:startify_section_header_lines, s:newline) != -1
  484. let s:newline += movement
  485. endwhile
  486. " skip blank lines between lists
  487. if empty(getline(s:newline))
  488. let s:newline += movement
  489. endif
  490. " don't go beyond first or last entry
  491. let s:newline = max([s:firstline, min([s:lastline, s:newline])])
  492. call cursor(s:newline, 5)
  493. endfunction
  494. " Function: s:set_mappings {{{1
  495. function! s:set_mappings() abort
  496. for k in keys(s:entries)
  497. execute 'nnoremap <buffer><silent>' s:entries[k].index
  498. \ ':call startify#open_buffers('. string(k) .')<cr>'
  499. endfor
  500. nnoremap <buffer><silent> e :enew<cr>
  501. nnoremap <buffer><silent> i :enew <bar> startinsert<cr>
  502. nnoremap <buffer><silent> <insert> :enew <bar> startinsert<cr>
  503. nnoremap <buffer><silent> b :call <sid>set_mark('B')<cr>
  504. nnoremap <buffer><silent> s :call <sid>set_mark('S')<cr>
  505. nnoremap <buffer><silent> t :call <sid>set_mark('T')<cr>
  506. nnoremap <buffer><silent> v :call <sid>set_mark('V')<cr>
  507. nnoremap <buffer><silent> <cr> :call startify#open_buffers()<cr>
  508. nnoremap <buffer><silent> <2-LeftMouse> :call startify#open_buffers()<cr>
  509. nnoremap <buffer><silent> q :call <sid>close()<cr>
  510. " Prevent 'nnoremap j gj' mappings, since they would break navigation.
  511. " (One can't leave the [x].)
  512. if !empty(maparg('j', 'n'))
  513. nnoremap <buffer> j j
  514. endif
  515. if !empty(maparg('k', 'n'))
  516. nnoremap <buffer> k k
  517. endif
  518. endfunction
  519. " Function: s:set_mark {{{1
  520. function! s:set_mark(type) abort
  521. let index = expand('<cword>')
  522. let entry = s:entries[line('.')]
  523. if (index =~# '^[eq]$') || (entry.type == 'session')
  524. return
  525. endif
  526. let default_cmds = {
  527. \ 'B': 'edit',
  528. \ 'S': 'split',
  529. \ 'V': 'vsplit',
  530. \ 'T': 'tabnew',
  531. \ }
  532. setlocal modifiable
  533. if entry.marked && index[0] == a:type
  534. let entry.cmd = 'edit'
  535. let entry.marked = 0
  536. execute 'normal! ci]'. entry.index
  537. else
  538. let entry.cmd = default_cmds[a:type]
  539. let entry.marked = 1
  540. let entry.tick = s:tick
  541. let s:tick += 1
  542. execute 'normal! ci]'. repeat(a:type, len(index))
  543. endif
  544. setlocal nomodifiable nomodified
  545. endfunction
  546. " Function: s:sort_by_tick {{{1
  547. function! s:sort_by_tick(one, two)
  548. return a:one.tick - a:two.tick
  549. endfunction
  550. " Function: s:check_user_options {{{1
  551. function! s:check_user_options() abort
  552. let path = expand('%')
  553. let session = path . s:sep .'Session.vim'
  554. " change to VCS root directory
  555. if get(g:, 'startify_session_autoload') && filereadable(session)
  556. execute 'source' session
  557. elseif get(g:, 'startify_change_to_vcs_root')
  558. call s:cd_to_vcs_root(path)
  559. " change directory
  560. elseif get(g:, 'startify_change_to_dir', 1)
  561. if isdirectory(path)
  562. lcd %
  563. else
  564. lcd %:h
  565. endif
  566. endif
  567. endfunction
  568. " Function: s:cd_to_vcs_root {{{1
  569. function! s:cd_to_vcs_root(path) abort
  570. let dir = fnamemodify(a:path, ':p:h')
  571. for vcs in [ '.git', '.hg', '.bzr', '.svn' ]
  572. let root = finddir(vcs, dir .';')
  573. if !empty(root)
  574. execute 'cd '. fnamemodify(root, ':h')
  575. return
  576. endif
  577. endfor
  578. endfunction
  579. " Function: s:close {{{1
  580. function! s:close() abort
  581. if len(filter(range(0, bufnr('$')), 'buflisted(v:val)'))
  582. if bufloaded(bufnr('#')) && bufnr('#') != bufnr('%')
  583. buffer #
  584. else
  585. bnext
  586. endif
  587. else
  588. quit
  589. endif
  590. endfunction
  591. " Function: s:get_index_as_string {{{1
  592. function! s:get_index_as_string(idx) abort
  593. if exists('g:startify_custom_indices')
  594. let listlen = len(g:startify_custom_indices)
  595. return (a:idx < listlen) ? g:startify_custom_indices[a:idx] : string(a:idx - listlen)
  596. else
  597. return string(a:idx)
  598. endif
  599. endfunction
  600. " Function: s:print_section_header {{{1
  601. function! s:print_section_header() abort
  602. $
  603. let curline = line('.')
  604. for lnum in range(curline, curline + len(s:last_message) + 1)
  605. call add(b:startify_section_header_lines, lnum)
  606. endfor
  607. call append('$', s:last_message + [''])
  608. unlet s:last_message
  609. endfunction