Your command is almost thereEDIT: After reading your comment, I realize I didn't understand the question initially. Adding Here is a hyphen tosimple script which takes your command seemssearch term as an argument and prompts for the path to dosearch. If the trickresult is found in only one file, it opens the file for editing at the location of the search result.
#!/bin/bash
SRCHTRM="$1"
read -p "Where to search: " SRCHPATH
FILEFOUND=$(grep foo"$SRCHTRM" file_names$SRCHPATH)
FILEFOUNDCNT=$(grep "$SRCHTRM" $SRCHPATH | vimwc -l)
FILEAWK=$(echo "$FILEFOUND" | awk -F":" '{ print $1 }')
if [ "$FILEFOUNDCNT" -eq "1" ];then
vi +/"$SRCHTRM" "$FILEAWK"
else
echo "$1 was found in more than one file"
fi