Find files with grep and open in editor

For Emacs you would typically perform the find/grep inside Emacs.

e.g. use M-x rgrep

The results are then processed by Emacs and you can easily jump to any result.


First off, you are not specifying the search path after the pattern.
For the simplest method:

vim $(grep -l "static void main" *)

For the smarter one (doesn't open Vim unless there were any results):

files=$(grep -l "static void main" *) && vim $files

You can use ** in the file pattern to search recursively. For example, to search for all lines containing dostuff() in all .c files in the parent directory and all its subdirectories, use:

:vimgrep /dostuff()/ ../**/*.c

Read more @ http://vim.wikia.com/wiki/Find_in_files_within_Vim

For an editor independent way, try

vim -o $(grep -rl string directory)

Tags:

Vim

Emacs

Bash

Grep