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.


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

  • 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 '09 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 '09 at 23:03

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.

  • 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. – Sandip Bhattacharya Dec 17 '19 at 9:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy