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

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.

Related

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

(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.

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 change the highlight style in Vim spellcheck?

Right now, when I do :set spell in my Vim, I get spelling errors highlighted as if they are selected text. What I want is an MS-Word like underlining of spelling errors. I tried to lookup :help spell but could not find a clue. Any help is appreciated.
Spelling errors are highlighted using the SpellBad highlighting group. To get it highlighted as you want, you should put something like
hi clear SpellBad
hi SpellBad cterm=underline
" Set style for gVim
hi SpellBad gui=undercurl
after the last line that is altering the color scheme in your vimrc (it is either set background=(dark|light) or colorscheme {schemename}).
See also :h hl-SpellBad for names and descriptions of other Spell* highlight groups.
The above needs to be typed everytime you set colorscheme. If you wish to avoid it, you should use autocmd.
See https://vi.stackexchange.com/questions/18295/how-to-set-a-colorscheme-that-still-shows-spelling-errors
For a quick and dirty way to change the highlighting color if you have a colorscheme loaded, is to modify your colorscheme.
Running, :verbose highlight SpellBad showed me where the config file is for my theme. More like, it showed where the SpellBad directive was set. Your mileage may vary. Please see below output:
:verbose highlight SpellBad
SpellBad xxx term=reverse ctermbg=9 gui=undercurl guisp=Red
Last set from /usr/share/vim/vim81/colors/desert.vim line 17
I navigated to desert.vim and added, hi SpellBad term=reverse ctermbg=226 gui=undercurl guisp=Yellow1 and saved the file. (you'll need sudo to modify the file). Once I reopened vim and ran, :verbose highlight SpellBad the output was now:
:verbose highlight SpellBad
SpellBad xxx term=reverse ctermbg=226 gui=undercurl guisp=Yellow1
Last set from /usr/share/vim/vim81/colors/desert.vim line 35
My highlight color was changed! Note that if you change your colorscheme, you'll most likely have to change the highlight color in your selected colorscheme file.

Resources