qf.vim 924 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. " Vim filetype plugin file
  2. " Language: Vim's quickfix window
  3. " Maintainer: Lech Lorens <Lech.Lorens@gmail.com>
  4. " Last Changed: 30 Apr 2012
  5. if exists("b:did_ftplugin")
  6. finish
  7. endif
  8. " Don't load another plugin for this buffer
  9. let b:did_ftplugin = 1
  10. let b:undo_ftplugin = "set stl<"
  11. " Display the command that produced the list in the quickfix window:
  12. setlocal stl=%t%{exists('w:quickfix_title')?\ '\ '.w:quickfix_title\ :\ ''}\ %=%-15(%l,%c%V%)\ %P
  13. function! s:setup_toc() abort
  14. if get(w:, 'quickfix_title') !~# '\<TOC$' || &syntax != 'qf'
  15. return
  16. endif
  17. let list = getloclist(0)
  18. if empty(list)
  19. return
  20. endif
  21. let bufnr = list[0].bufnr
  22. setlocal modifiable
  23. silent %delete _
  24. call setline(1, map(list, 'v:val.text'))
  25. setlocal nomodifiable nomodified
  26. let &syntax = getbufvar(bufnr, '&syntax')
  27. endfunction
  28. augroup qf_toc
  29. autocmd!
  30. autocmd Syntax <buffer> call s:setup_toc()
  31. augroup END