1

I am seeing differences when using grep in terminal and :grep in vim

The former, grep -ri --include *.sh backup returns results.

The latter, :grep -ri --include *.sh backup does not.

Any thoughts?

Edit 1: :set grepprg returns grepprg=grep -n $* /dev/null

Edit 2: My only grep alias is alias grep='grep --color=auto'

Eric Francis
  • 23,039
  • 31
  • 88
  • 122
  • Different working directory? – romainl Jan 12 '15 at 16:37
  • 1
    Does your `grep` command really work? You aren't specifying a target for `grep`. You need something like `grep -ri --include *.sh backup .`. Also you may want to check out [`git grep`](http://git-scm.com/docs/git-grep)/[ag](https://github.com/ggreer/the_silver_searcher)/[ack](http://beyondgrep.com/). – Peter Rincker Jan 12 '15 at 16:38
  • My grep command really works. I believe the directory I am in is being used. – Eric Francis Jan 12 '15 at 17:16
  • Posted answer below. – Eric Francis Jan 12 '15 at 17:21
  • 1
    Looks like you are using a version of GNU grep 2.11+. [Where does grep -r search by default?](http://unix.stackexchange.com/q/38793). Which defaults to using the current working directory if using the `-r` flag. – Peter Rincker Jan 12 '15 at 18:50
  • @PeterRincker Should I not be relying on this capability? – Eric Francis Jan 12 '15 at 19:13
  • 1
    That really depends on your environment(s). If you are often working working on older machines or more unix complaint boxes then you may want to change your habits. Otherwise I wouldn't worry about it. However if you do find yourself doing a bunch of recursive grepping then I would recommend learning `git grep`, ag, and/or ack. – Peter Rincker Jan 12 '15 at 19:19

1 Answers1

2

Changing my grepprg value fixed my issue

In my ~/.vimrc

" Grep settings
set grepprg=grep\ -n\ $*

The default value of grepprg=grep -n $* /dev/null was using /dev/null as the directory.

Eric Francis
  • 23,039
  • 31
  • 88
  • 122
  • 4
    For those wondering, the reason why the default appends `/dev/null` to the grepprg; this is needed to force the grep commands to print the name of the file in which a match is found, if only one filename is specified. – Cam Nov 12 '17 at 21:01