10

When using Vim is there a way that :grep or :vimgrep will color the patterns returned to the buffer?

Keith Pinson
  • 7,835
  • 7
  • 61
  • 104
Luis
  • 1,828
  • 2
  • 19
  • 27

4 Answers4

4

If you search for the pattern after you've :vimgrep'd it, Vim will highlight it. Just edit the :vimgrep pattern files into :g/pattern/.

For a richer solution, try this script.

George V. Reilly
  • 15,885
  • 7
  • 43
  • 38
  • 2
    Could you elaborate a bit more or provide an example for your suggestion? I do not fully understand what you mean with editing `:vimgrep pattern files` into `:g/pattern/`. – Wolfson May 20 '20 at 11:01
2

You can use the Unix grep:

:!grep --color pattern %

There may be other solutions using internal grep/vimgrep but this one works for me.

Taurus Olson
  • 3,153
  • 2
  • 26
  • 21
0

Maybe ack fits your bill?

user55400
  • 3,929
  • 1
  • 21
  • 13
0

Two ways:

  • For normal search / you can use :set hls.
  • Or you can use :match Search /pattern/. This will hightlight everything that matches pattern.
Peter Stuifzand
  • 5,084
  • 1
  • 23
  • 28