Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

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 %
share|improve this answer
2  
By all means, stick with :g. find and findstr seem to be specifically engineered to trip up the grep-familiar. –  bonsaiviking Apr 16 '12 at 16:13
    
Terrific, thank you! I knew that there had to be a VIM-internal command! –  dotancohen Apr 16 '12 at 18:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.