Is there a way in vim to change search text highlight color in visual mode only? - vim

(I am using the nord-vim color scheme, but this is an issue with all color schemes in vim that I've tried, and I am looking for what settings need to be changed to accomplish the desired goal)
I have a problem in vim where if I do a search the highlight text color for the search matches is the same as the visual mode background color, so if I search for some text and then visually select some lines of text containing one or more search results, the text disappears. It does so because visual mode is changing the background color but not the text color, which is the desired behavior, except in the one case of search results, which I would like to change the text color of but only in visual mode.
Is this possible in vim?
EXAMPLE:
(do a search for some text, and it is highlighted)
(visually select some lines of text containing search results)
I would like it if the search results changed text color to some other distinguishable color, to indicate that they are search results, but only in visual mode.

It is sadly not documented but it happens so that some highlight groups, like Visual, have some sort of priority over others, like Search:
hi Visual cterm=NONE ctermbg=cyan ctermfg=black
hi Search cterm=NONE ctermbg=yellow ctermfg=black
AFAIK, the only way to explicitly increase the priority of a highlight group is to set its cterm/gui attribute to reverse and swap the *fg and *bg attributes:
hi Visual cterm=NONE ctermbg=cyan ctermfg=black
hi Search cterm=reverse ctermbg=black ctermfg=yellow
But even then, you will notice that it's only the reverse bit that has some effect when interacting with Visual, with the color attributes of Search totally ignored, which may or may not be satisfactory.
This gist explains how best to override highlight groups.

Related

In vim, how do I change the highlight color of the currently highlighted search term?

From Fandom:
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.
hi Search will change the color of matching patterns in vim, but not the currently selected search term, which has an unreadable yellow background. How can I change this currently selected background to something else? What's the hi ### term?
The option is called IncSearch so the line will look something like this:
hi IncSearch cterm=NONE ctermfg=yellow ctermbg=green
It is possible to look at the colorschemes in the $VIMRUNTIME/colors/*.vim files of the machine.

How to change vimtex highlight colors for matching delimiters?

I've installed vimtex and have enabled highlighting of matching delimiters, but it's a bit painful to see the highlighted part. How can I change the highlight color?
This can be changed using the MatchParen highlighting group, for example:
:hi MatchParen ctermbg=5

How to retrieve the current mode color highlight used in the status line?

I'm working on adding an automatic highlight for my current line in Vim, that matches the current mode color used in the status line. So far I haven't had much success if finding a way to get what that current color is.
The colors for the status line are being set based on the current theme, so I'd rather set my current line color dynamically rather than hard coding it.
For example, a few of my mode colors are:
Normal = Blue
Insert = Green
Visual = Red
I'd like to be able to retrieve the exact color codes used for those highlights from the current theme, so that I can set up a few simple autocommands to use them for mode switches.
Is there a way to easily retrieve these colors?
You can query the colors and attributes of a highlight group via synIDattr(); you can find an example at :help hlID().
If you intend to use the cursorline feature and have a single-colored statusline that gets its StatusLine highlight group changed dynamically by autocmds, simply linking both (:hi link CursorLine StatusLine) might already work.
PS: I personally would find it highlight confusing if the same colored line could either represent the current line or one of the horizontal separators between windows, but your mileage obviously varies...

How do I change the unused background color in vim?

How do you change the unused / bottom portion of the vim editor? The picture will hopefully clarify my terrible description :).
That section is controlled by the highlight group NonText. So you can add the following line after your colorscheme line to set the background color to blue.
highlight NonText ctermbg=blue
Of course change blue to whatever color you want. Also if you are in gvim you will want to use guibg= to set the background color.

How to correctly highlight cursor line in VIM?

VIM can be configured to highlight current line via :hi cursorline guibg=green and set cursorline commands. But if I enable tabs display via:
:hi specialkey guifg=grey guibg=grey
:set listchars="tab"
:set list
Cursor line highlight will corrupt tabs display:
alt text http://dl.dropbox.com/u/239055/vim_cursorline_bug.png
Any hints how i can avoid corruption so may tabs are highlighted with one color and cursor line is highlighted with another color without any ^I displayed at intersection?
Try setting listchars without the quotes:
:set listchars=tab:>-
This shows the tab as >------- instead of ^I, which I think is what you were asking. When the cursor is on the line with the tab, the whole line is displayed in the cursorline colour.
It appears that the cursorline colour takes precedence over the specialkey colour, which is consistent with your screenshot.

Resources