Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim: Highlight quickfix selected line with color different than 'Search'

Tags:

vim

What is the highlight group for the currently selected line in the quickfix window?

The selected line in the quickfix window uses Search for highlighting. I'd like to continue using yellow for Search highlighting, but use blue for quickfix selected line.

like image 290
Steve McKinney Avatar asked Nov 04 '12 15:11

Steve McKinney


People also ask

How do I make Vim start with no search highlighting?

Add the following to your vimrc if you want Vim to start with no search highlighting: It can be useful to highlight the word under the cursor like *, but without jumping to the next match. Then you can see the search highlights on the current screen, without any scrolling.

How to create a quick fix list using Vim?

For this vim has commands like :grep and :vimgrep, they create a quickfix list with the results of a search. With this command we can take advantage of the built-in search engine that comes with vim.

How to customize Vim color schemes and syntax highlighting?

How to Customize VIM Color Schemes and Syntax Highlighting 1 Customizing Color Schemes in Vim. First, launch the terminal in Ubuntu 20.04. ... 2 Syntax Highlighting in Vim. First, you will need to create a dummy text file with the Vim text editor to try out this method. ... 3 Conclusion. ...

How do I highlight all matches in a search?

To highlight all search matches, set the following option: With the defaults, setting this option causes all text matching the current search to be highlighted using the Search highlight group, which adds a yellow background to the current highlighting. See :help hl-Search, or type :hi Search to see what color you have it set to.


2 Answers

Ingo Karkat's answer is right. It's indeed hard-coded in vim code. I have created a patch - QuickFixCurrentLine.patch for vim8.

Patch is long enough to be posted here. Plus, it has mix of tabs and spaces. So, providing a link-only-answer.

EDIT: The patch has got upstreamed in the latest vim code.
The name of the highlight has been changed to quickfixline instead of quickfixcurrentline.

like image 188
anishsane Avatar answered Oct 02 '22 00:10

anishsane


The currently selected quickfix item is hard-coded to Search. You'd have to change the Vim source code and recompile to change this.

I see only limited ways to work around this with Vimscript. You could try to override the highlighting for the current line via :match / matchadd() (it has higher priority), but it would only cover the length of the text, not the entire line the original highlighting. Also, I think the currently selected item cannot be easily queried from Vim, so you'd have to hook into the quickfix-local <CR> mapping to update it, and stop using :cnext etc. to move to different errors.

:highlight BlueLine guibg=Blue
:autocmd BufReadPost quickfix match BlueLine /\%1l/
:autocmd BufReadPost quickfix nnoremap <buffer> <CR> :execute 'match BlueLine /\%' . line('.') . 'l/'<CR><CR>
like image 27
Ingo Karkat Avatar answered Oct 02 '22 00:10

Ingo Karkat