Set different highlighting for Search versus current quickfix error

519 views
Skip to first unread message

Paul

unread,
Sep 4, 2013, 5:51:16 PM9/4/13
to vim...@googlegroups.com
The GUI highlighting for the current quickfix item seems to be the same as whatever I set the Search group to. Is there a way to have a different guibg color?

Tony Mechelynck

unread,
Sep 4, 2013, 6:44:24 PM9/4/13
to vim...@googlegroups.com
On 04/09/13 23:51, Paul wrote:
> The GUI highlighting for the current quickfix item seems to be the same as whatever I set the Search group to. Is there a way to have a different guibg color?
>
Ah? With me it doesn't: I just did a :helpgrep, and the current quickfix
item didn't get _any_ highlighting: with the cursor on it,

:echomsg synIDattr(synID(line("."),col("."),0),"name")
synIDattr(synIDtrans(synID(line("."),col("."),0)),"name")
synIDattr(synID(line("."),col("."),1),"name")
synIDattr(synIDtrans(synID(line("."),col("."),1)),"name")

(which is a command defined as :WhatSyntax in my vimrc) didn't display
anything. Or if it did, it was because there was some highlighted syntax
item (such as between |bars|) just under the cursor.

I'm using gvim 7.4.16 (Huge) with GTK2/GNOME2 GUI.


Best regards,
Tony.
--
"A bad man is worse when he pretends to be a saint."
[Francis Bacon]

Paul

unread,
Sep 4, 2013, 7:12:58 PM9/4/13
to vim...@googlegroups.com
On Wednesday, September 4, 2013 6:44:24 PM UTC-4, Tony Mechelynck wrote:
>On 04/09/13 23:51, Paul wrote:
>> The GUI highlighting for the current quickfix item seems to be the
>> same as whatever I set the Search group to. Is there a way to have
>> a different guibg color?
>
> ...With me it doesn't: I just did a :helpgrep, and the current quickfix

> item didn't get _any_ highlighting: with the cursor on it,
>
> :echomsg synIDattr(synID(line("."),col("."),0),"name")
> synIDattr(synIDtrans(synID(line("."),col("."),0)),"name")
> synIDattr(synID(line("."),col("."),1),"name")
> synIDattr(synIDtrans(synID(line("."),col("."),1)),"name")
>
> ...didn't display anything. Or if it did, it was because there was

> some highlighted syntax item (such as between |bars|) just under the
> cursor.
>
> I'm using gvim 7.4.16 (Huge) with GTK2/GNOME2 GUI.

I'm using vim 7.3 on Windows 7. When I issue:

:echomsg synIDattr(synID(line("."),col("."),0),"name")

:echomsg synIDattr(synIDtrans(synID(line("."),col("."),0)),"name")
:echomsg synIDattr(synID(line("."),col("."),1),"name")
:echomsg synIDattr(synIDtrans(synID(line("."),col("."),1)),"name")

I get:

qfFileName
Directory
qfFileName
Directory

It's interesting that you don't see the current quickfix item highlighted. I thought that maybe I set something to turn on quickfix highlighting, but I can't seem to find the switch. I searched the web and the quickfix help to see if quickfix is *suppose* to highlight the current item by default, but didn't find indications of that either.

Paul

unread,
Sep 4, 2013, 7:18:01 PM9/4/13
to vim...@googlegroups.com

Tony Mechelynck

unread,
Sep 4, 2013, 7:47:25 PM9/4/13
to vim...@googlegroups.com
I get the same as you do if I do :copen first. What I referred to was
the current quickfix item as found _in the text_ by :cnext, with no
quickfix window actually open.

I see this item as blue on white, and doing ":verbose hi qfFileName" in
the quickfix window gives

qfFileName xxx links to Directory
Last set from /usr/local/share/vim/vim74/syntax/qf.vim

The Search highlight, OTOH, is black on yellow. Not at all the same
thing for me, which makes me ask: Which colorscheme are you using?

To link qfFileName to something else, or to define specific colours for
it, just use a new or modified colorscheme.

To modify a colorscheme, first copy it to ~/.vim/colors/ (for *x
systems) or to ~/vimfiles/colors (for Windows), change its name, and
modify it there (including setting g:colors_name to the new name); then
alter the calling line so that it calls the new name. It is not possible
to invoke colorschemes recursively (or at least, I tried and didn't
succeed).


Best regards,
Tony.
--
Women are just like men, only different.

Paul

unread,
Sep 4, 2013, 8:33:10 PM9/4/13
to vim...@googlegroups.com
On Wednesday, September 4, 2013 7:47:25 PM UTC-4, Tony Mechelynck wrote:
> ...if I do :copen first...I see this item as blue on white, and

> doing ":verbose hi qfFileName" in the quickfix window gives
>
> qfFileName xxx links to Directory
> Last set from /usr/local/share/vim/vim74/syntax/qf.vim
>
> The Search highlight, OTOH, is black on yellow. Not at all the same
> thing for me, which makes me ask: Which colorscheme are you using?
>
> To link qfFileName to something else, or to define specific colours
> for it, just use a new or modified colorscheme.
>
> To modify a colorscheme, first copy it to ~/.vim/colors/ (for *x
> systems) or to ~/vimfiles/colors (for Windows), change its name, and
> modify it there (including setting g:colors_name to the new name);
> then alter the calling line so that it calls the new name. It is not
> possible to invoke colorschemes recursively (or at least, I tried
> and didn't succeed).

I have a colorscheme called mine.vim containing lots of highlight commands. Prepended to those commands is the preamble

set background=dark
hi clear
if exists("syntax_on")
syntax reset
endif
let g:colors_name = "mine"

I've actually set g:colors_name to "mine" in the course of trying to figure out how it works. It was "blue" before, probably because I never figured out how it worked, and "blue" was a good fallback colorscheme. Reading the help on colors_name and experimenting, it seems that g:colors_name is only used to get back the colorscheme if you haven't toggled the background setting. If you have, g:colors_name is wiped out.

In any case, none of the :hi statements in mine.vim contain the word "Directory", so I added to following to turn on a bit of green:

hi Directory guibg=#00cc00

All this did was to highlight the filename field of all quickfix entries with a green background. The current quickfix item, however, is still highlighted in the Search guibg (red). This means the entire row, not just a single field in the row.

Based on my last post, I suspect that this is hard-coded.

Thanks for tinkering and posting. I think I have a better idea of how color schemes work now.

Tony Mechelynck

unread,
Sep 4, 2013, 9:48:48 PM9/4/13
to vim...@googlegroups.com
Ah, yes. Now by setting 'nocul' or by moving the cursor to a different
line of the quickfix window (which I normally don't use: :cnext :cprev
:cnfile :cpfile :cfirst :clast are normally enough for me), I see the
yellow background on the whole line. Let's see...

If I do
:hi Search guibg=pink
the whole line gets a pink background. Now let's try to find if there
are any other highlights which link to Search... No there isn't, so yes,
it must be hardcoded.

But you can hide it (as long as the cursor remains on the line) by
setting 'cursorline'. The CursorLine highlight will then override the
Search highlight for the current quickfix line as long as the cursor
remains on it.


Best regards,
Tony.
--
George, after tying on a whopper the night before, woke up in the morning to
find a pathetically unattractive woman sleeping blissfully beside him. He
leaped out of bed, dressed quickly, and furtively placed $100 on top of the
bureau. He then started to tiptoe out of the room. But, as he passed the
foot of the bed, he felt a tug at his trouser leg. Glancing down, he saw
another female even homelier than the one he'd left in bed. She gazed up
at him soulfully, and asked, "Nothing for the bridesmaid?"

Paul

unread,
Sep 4, 2013, 9:56:16 PM9/4/13
to vim...@googlegroups.com
On Wednesday, September 4, 2013 9:48:48 Tony Mechelynck wrote:
> ...by setting 'nocul' or by moving the cursor to a different line of

> the quickfix window (which I normally don't use: :cnext :cprev
> :cnfile :cpfile :cfirst :clast are normally enough for me), I see
> the yellow background on the whole line. Let's see...
>
> If I do
> :hi Search guibg=pink
> the whole line gets a pink background. Now let's try to find if
> there are any other highlights which link to Search... No there
> isn't, so yes, it must be hardcoded.
>
> But you can hide it (as long as the cursor remains on the line) by
> setting 'cursorline'. The CursorLine highlight will then override
> the Search highlight for the current quickfix line as long as the
> cursor remains on it.

Thanks Tony. Maybe I can use that in a pinch sometime.

Benjamin R. Haskell

unread,
Sep 5, 2013, 1:37:12 AM9/5/13
to vim...@googlegroups.com
On Wed, 4 Sep 2013, Paul wrote:

> It seems to be hard coded. Apparently not easy to circumvent:
> http://stackoverflow.com/questions/13220073/vim-highlight-quickfix-selected-line-with-color-different-than-search
>

In case you are (or anyone else is) interested in changing the source,
the hard-coding happens at line 2007 of src/quickfix.c¹:

2006: msg_outtrans_attr(IObuff, i == qi->qf_lists[qi->qf_curlist].qf_index
2007: ? hl_attr(HLF_L) : hl_attr(HLF_D));

HLF_L is the C constant for the "L"ast search highlighting. So, it's
not hardcoded to "Search", per se, but rather whatever is in the "l:"
key of the 'highlight' setting (default "l:Search"). It is,
unfortunately, linked to actual search highlighting -- i.e. you can't
have different highlight groups for searching and the active quickfix
line.

It's slightly odd that all the other colors in the quickfix window are
overrideable. The following four groups are defined in
$VIMRUNTIME/syntax/qf.vim² (default link listed in parens):

qfFileName (Directory)
qfSeparator (no default)
qfLineNr (LineNr)
qfError (Error)

--
Best,
Ben

¹: https://code.google.com/p/vim/source/browse/src/quickfix.c#2007
²: Based on that file, it's also clear that quickfix highlighting will
fail on a filename containing a pipe (blech).

Paul

unread,
Sep 5, 2013, 10:47:57 AM9/5/13
to vim...@googlegroups.com
On Thursday, September 5, 2013 1:37:12 AM UTC-4, Benjamin R. Haskell wrote:
> In case you are (or anyone else is) interested in changing the source,
> the hard-coding happens at line 2007 of src/quickfix.c¹:

Thanks, Ben. Maybe one day. It's been 10 (or more) years since I coded in C++, so it wouldn't be an afternoon jaunt through the code for me.

Charles Campbell

unread,
Sep 5, 2013, 11:42:22 AM9/5/13
to vim...@googlegroups.com
Sorry, Tony -- I need to differ with you on this.

syntax/qf.vim is a syntax file; it is not a colorscheme, and it is
unnecessary to modify or alter any colorschemes.

Instead, if you wish to override qfFileName, etc, put your alterations into

$HOME/after/syntax/qf.vim

Therein, you may put things such as

hi link qfFileName Special
hi qfSeparator guifg=SeaGreen1 guibg=orange3

Doing so will override syntax/qf.vim's selection of default colors.

Regards,
Chip Campbell

Tony Mechelynck

unread,
Sep 5, 2013, 10:44:25 PM9/5/13
to vim...@googlegroups.com
hm, yes, that would also work; but usually I prefer not to meddle with a
syntax script if the syntax analysis is OK but the choice of colours is
not to my taste. A colour scheme can change the colours any which way,
it may replace yellow by pink in one highlight group, remove a highlight
link in one place, add one in another place… Anything that involves only
colours can be done by a colorscheme, provided that the different
colours you want to set belong to different highlight groups, at least
before taking highlight links into account.

I already have my own ~/.vim/colors/almost-default.vim (which sets only
the colours which I want different from the default) so for me it is
easy to tweak this or that highlight definition by putting all colour
changes in this one place.


Best regards,
Tony.
--
`Lasu' Releases SAG 0.3 -- Freeware Book Takes Paves For New World Order
by staff writers

...
The SAG is one of the major products developed via the Information
Superhighway, the brain child of Al Gore, US Vice President. The ISHW
is being developed with massive govenment funding, since studies show
that it already has more than four hundred users, three years before
the first prototypes are ready. Asked whether he was worried about the
foreign influence in an expensive American Dream, the vice president
said, ``Finland? Oh, we've already bought them, but we haven't told
anyone yet. They're great at building model airplanes as well. And _ I
can spell potato.'' House representatives are not mollified, however,
wanting to see the terms of the deal first, fearing another Alaska.
Rumors about the SAG release have imbalanced the American stock
market for weeks. Several major publishing houses reached an all time
low in the New York Stock Exchange, while publicly competing for the
publishing agreement with Mr. Wirzenius. The negotiations did not work
out, tough. ``Not enough dough,'' says the author, although spokesmen
at both Prentice-Hall and Playboy, Inc., claim the author was incapable
of expressing his wishes in a coherent form during face to face talks,
preferring to communicate via e-mail. ``He kept muttering something
about jiffies and pegs,'' they say.
...
-- Lars Wirzenius <wirz...@cs.helsinki.fi>
[comp.os.linux.announce]

Reply all
Reply to author
Forward
0 new messages