home of the madduck/ blog/
alias grep=vim ... ?

I love: regular expressions and vim

I hate: regular expressions of sed and grep

I adore: vim's enhanced regular expressions

I want: to be able to use vim from the command line to do advanced searches across sets of files, like:

# find "foo" followed by whitespace and "bar", even across lines
$ vim $SOMETHING 'g/foo\_s*bar/'

# words ending in "bar"
$ vim $SOMETHING 'g/bar\>/'

# words starting with "foo"
$ vim $SOMETHING 'g/\<foo/'

... and more. What does $SOMETHING have to be set to?

Update: Neil Moore suggests the following shell function:

vgrep () {
  local S="$1"; shift
  vim -es +"argdo g/$S" +':q!' "$@"

This works. I shall be posting any improvements I make over the next couple of weeks in another blog post. If there are any. But I suppose options like -i and -v might be good to have.