Vim: "highlight syntax match " for QuickFixLine.

Created on 8 Mar 2020  路  4Comments  路  Source: vim/vim

Hello, thank you for reading this :)

It would be nice to be able to change the highlight syntax match of QuickFixLine, so that it allows multiple highlights in one single line. For example:

Instead of highlighting the whole line like this:

Change the foreground of the quickfix highlight to this:

enhancement

Most helpful comment

If you want the middle of the line in green, and the end in white, you could try this:

hi link QuickFixLineStart QuickFixLine
hi QuickFixLineMiddle ctermbg=green guibg=green
hi QuickFixLineEnd ctermbg=white guibg=white
augroup CustomQuickFixLine
    au!
    au FileType qf call CustomQuickFixLine('init')
augroup END
fu CustomQuickFixLine(action) abort
    if a:action is# 'init'
        call CustomQuickFixLine('install match')
        augroup UpdateCustomQuickFixLine
            au! * <buffer>
            au CursorMoved <buffer> call CustomQuickFixLine('update')
        augroup END
    elseif a:action is# 'update' && get(get(b:, '_cqfl', {}), 'last_line') != line('.')
        if exists('b:_cqfl')
            call map(get(b:_cqfl, 'id', []), {_,v -> matchdelete(v)}) | unlet b:_cqfl
        endif
        call CustomQuickFixLine('install match')
    elseif a:action is# 'install match'
        let pat = ['^.\{-}|', '^.\{-}|\zs.\{-}|', '^.\{-}|.\{-}|\zs.\{-}$']
        let curline = line('.')
        call map(pat, {_,v -> '\%'..curline..'l'..v})
        let b:_cqfl = {}
        let b:_cqfl.id = map(['Start', 'Middle', 'End'], {i,v -> matchadd('QuickFixLine'..v, pat[i])})
        let b:_cqfl.last_line = line('.')
    endif
endfu

All 4 comments

If I understood you correctly you want to keep the same colors but only bold. You can achieve this with the following:

hi QuickFixLine cterm=bold gui=bold ctermfg=NONE ctermbg=NONE guifg=NONE guibg=NONE

Add it to your colorscheme or vimrc.

Well, I guess that works too for my scenario. Thanks!

If you want the middle of the line in green, and the end in white, you could try this:

hi link QuickFixLineStart QuickFixLine
hi QuickFixLineMiddle ctermbg=green guibg=green
hi QuickFixLineEnd ctermbg=white guibg=white
augroup CustomQuickFixLine
    au!
    au FileType qf call CustomQuickFixLine('init')
augroup END
fu CustomQuickFixLine(action) abort
    if a:action is# 'init'
        call CustomQuickFixLine('install match')
        augroup UpdateCustomQuickFixLine
            au! * <buffer>
            au CursorMoved <buffer> call CustomQuickFixLine('update')
        augroup END
    elseif a:action is# 'update' && get(get(b:, '_cqfl', {}), 'last_line') != line('.')
        if exists('b:_cqfl')
            call map(get(b:_cqfl, 'id', []), {_,v -> matchdelete(v)}) | unlet b:_cqfl
        endif
        call CustomQuickFixLine('install match')
    elseif a:action is# 'install match'
        let pat = ['^.\{-}|', '^.\{-}|\zs.\{-}|', '^.\{-}|.\{-}|\zs.\{-}$']
        let curline = line('.')
        call map(pat, {_,v -> '\%'..curline..'l'..v})
        let b:_cqfl = {}
        let b:_cqfl.id = map(['Start', 'Middle', 'End'], {i,v -> matchadd('QuickFixLine'..v, pat[i])})
        let b:_cqfl.last_line = line('.')
    endif
endfu

I guess this can be closed.

Was this page helpful?
0 / 5 - 0 ratings