Windows – Grep file in GVIM on Windows

grepvimwindows

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.

Best Answer

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 %
Related Question