6

Right now, all of my search results in vim are highlighted in a bright (i.e. unreadable) yellow. I was wondering if there was a way to set the highlighting for search results to underline instead of highlight. I did some searching online and it seems possible, but the vim documentation is so obfuscated that I can't make out the syntax for this.

2 Answers 2

9

You need to modify the highlighting for the 'Search' syntax element. You can do that with a command like this:

:highlight Search guibg=black guifg=yellow gui=underline

That command will set the text color (i.e, foreground) of the found search words to yellow (againt black background) and will underline them. The command above alters only the highlighting for the gui, which means in gvim. Altering in terminal, I think would be this:

:highlight Search ctermbg=black ctermfg=yellow term=underline

2
  • This command set the bg and fg colors successfully. I presume it also set the underline flag, but it seems like my terminal can't show underline. However, bg = black and fg = yellow is much better, thanks!
    – Kevin
    Dec 22, 2009 at 21:03
  • 1
    @Kevin: It may just be that I gave you the wrong info re: underline. 'cterm' stands for "color terminal" and 'term' for "normal terminal". You're definitely using a cterm. So you might try this for underline: highlight Search ctermbg=black ctermfg=yellow cterm=underline
    – Herbert Sitz
    Dec 22, 2009 at 23:03
2

As another answer noted, you can set the syntax highlighting of search results by targetting Search

:highlight Search guibg=guibg guifg=guifg gui=italic,underline,bold

Setting the guibg and guifg to themselves should undo any gross colors that may be showing. If you want the results to be more/less noticeable you can tweak the gui settings (:help highlight-args for details). If you want the bg and fg colors reversed in a theme-friendly way you can use gui=inverse.

1
  • 1
    To highlight just using underline and keeping rest of the color the same, your command helped. But with some corrections. On my MacVim, guibg as a value was not allowed. bg was. So this worked: highlight Search guibg=bg guifg=fg gui=underline. Thanks for the reference to the help page. Dec 17, 2019 at 9:22

You must log in to answer this question.