How to format Vim quickfix entries?

后端 未结 2 1164
青春惊慌失措
青春惊慌失措 2020-12-10 15:49

This is the vim-script to generate Markdown outline:

fun! TOC()
    call setloclist(0, [])
    let save_cursor = getpos(\".\")
    call cursor(1, 1)
    whil         


        
2条回答
  •  失恋的感觉
    2020-12-10 16:17

    I ended up implementing this on plasticboy/vim-markdown on this PR (with GIF animation) using set modifiable + substitution instead of conceal with something along:

    function! b:Markdown_Toc()
        silent lvimgrep '^#' %
        vertical lopen
        let &winwidth=(&columns/2)
        set modifiable
        %s/\v^([^|]*\|){2,2} #//
        for i in range(1, line('$'))
            let l:line = getline(i)
            let l:header = matchstr(l:line, '^#*')
            let l:length = len(l:header)
            let l:line = substitute(l:line, '\v^#*[ ]*', '', '')
            let l:line = substitute(l:line, '\v[ ]*#*$', '', '')
            let l:line = repeat(' ', (2 * l:length)) . l:line
            call setline(i, l:line)
        endfor
        set nomodified
        set nomodifiable
    endfunction
    

    But you might prefer:

    Plugin 'plasticboy/vim-markdown'
    

    It's up to you. =)

    Screenshot:

    enter image description here

提交回复
热议问题