6

On Linux, I sometimes see a list of all the lines which match a term with this handy command:

:! grep -n "term" %

However, I am now stuck on a Windows XP SP3 machine which lacks grep! Is there a way to get this list from within VIM itself, or using some other Windows tool via :!?

Thanks.

1 Answer 1

7

Use :g.

:g/term

:g/term/p

(Trivia: grep was named after the same g/re/p command in the ed editor, where re stands for "regular expression". The p suffix is optional, and is an abbrev for :print.)

To also display line numbers, either add :nu:

:g/term/nu

or just enable 'number' with :set number.


As an alternative to grep, Windows comes with tools find and findstr that have the same basic functions.

:! find "term" %

:! findstr term %
2
  • 3
    By all means, stick with :g. find and findstr seem to be specifically engineered to trip up the grep-familiar. Apr 16, 2012 at 16:13
  • Terrific, thank you! I knew that there had to be a VIM-internal command!
    – dotancohen
    Apr 16, 2012 at 18:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .