Vim open a file found through grep
bash, grep, vim
Solution
You can do `:r ! ack-grep "function tracking" ../` to pull the output directly into the `vim` buffer, and then use `gf` to navigate to the file under the cursor.
If you want to open the file in a new tab instead, you can do `Control-W, gf` in normal mode.
Update: If you want the output of the command to appear in a new tab, you can do the following, which opens a new tab, and then immediately pulls the output of the command into it.
:tabnew | r!ack-grep "function tracking" ../
Problem
So I'm browsing a file in vim. I realize the function I am looking for is another file. So I do `:! ack-grep "function tracking" ../` to look for it, and I see I need to examine file "../../tracking/api/ etc etc" some really long file name. what I'm doing now is trying to remember this file, type `fg` to get back into vim, and then :e "that really long file name". I'm wondering if there's an easier way to do this? For instance, can I do something like `vim -addtab <some file>` from the command line once I've used ack-grep to find what I'm looking for, and then when I do `fg` to get back to vim, the file will be open in one a tab? Awesome, lots of suggestions. I'll try them all out and in comments as I do. Then I'll pick what worked best for me once I've tried them all. So this is the function that I settled on: ``` function! s:NewTabGrep(...) let args=split(a:1) if len(args) == 2 let dir=args[1] else let dir='.' endif echom args[0] . " " . shellescape(dir) tabnew | execute "r ! ack-grep ". shellescape(args[0]) ." ". shellescape(dir) endfunction com! -nargs=? GrepTab call s:NewTabGrep('<args>') ``` This performs the search, and opens the results in a new vim tab. Then I can use CtrlP to open whichever file seems most interesting. Thanks to Merlin2011 for inspiration.