How can I open a file that results from grep?
Use grep -l
to just get the filename of the matching file and not the matching text, then combine it with vim
:
vim "$(grep -l some_pattern file_names)"
You can use quickfix
or errorfile
feature in vim
:
$ grep -n foo * > /tmp/foo.list
$ vim -q /tmp/foo.list
Vim will open the first file in /tmp/foo.list
and place the cursor directly in the line where foo
was found. You can go to the next instance using :cn
and previous instance using :cp
.
Side note: If you are already using vim
or gvim
, then I would suggest using its inbuilt grep
functionality. Read :help vimgrep
for more information.