Skip to main content
replaced http://unix.stackexchange.com/ with https://unix.stackexchange.com/
Source Link

How might I more easily use a filename found by grep as an argument to vim:

$ grep -r foo *
lib/beatles/john.c
lib/pantera/phil.c
lib/pinkfloyd/roger.c
lib/pinkfloyd/richard.c
lib/whitestripes/elephant/jack.c

$ vim lib/pinkfloyd/roger.c

To autocomplete with Bash, I need to type " l \t p \t i \t r \t o \t " because many other files match. Is there an easer way to say "Give me the third found file?" Maybe something like one of these:

$ vim $3        // Third line
$ vim 'roger'   // Only line with string 'roger'
$ vim TabTabTab // Each Tab completes a different filename from grep

I do use Tmux and I know that I can go up and select the filename and then paste it. But that is still a bit clumsy, even as a VIM user. There must be a better way!

Note that I am not looking for a solution to script the grep outputscript the grep output, rather this is something that I will be using manually as I grep for and open files with VIM.

EDIT: I am looking for a general solution, not one that will always target 'roger' or always target the third item.

How might I more easily use a filename found by grep as an argument to vim:

$ grep -r foo *
lib/beatles/john.c
lib/pantera/phil.c
lib/pinkfloyd/roger.c
lib/pinkfloyd/richard.c
lib/whitestripes/elephant/jack.c

$ vim lib/pinkfloyd/roger.c

To autocomplete with Bash, I need to type " l \t p \t i \t r \t o \t " because many other files match. Is there an easer way to say "Give me the third found file?" Maybe something like one of these:

$ vim $3        // Third line
$ vim 'roger'   // Only line with string 'roger'
$ vim TabTabTab // Each Tab completes a different filename from grep

I do use Tmux and I know that I can go up and select the filename and then paste it. But that is still a bit clumsy, even as a VIM user. There must be a better way!

Note that I am not looking for a solution to script the grep output, rather this is something that I will be using manually as I grep for and open files with VIM.

EDIT: I am looking for a general solution, not one that will always target 'roger' or always target the third item.

How might I more easily use a filename found by grep as an argument to vim:

$ grep -r foo *
lib/beatles/john.c
lib/pantera/phil.c
lib/pinkfloyd/roger.c
lib/pinkfloyd/richard.c
lib/whitestripes/elephant/jack.c

$ vim lib/pinkfloyd/roger.c

To autocomplete with Bash, I need to type " l \t p \t i \t r \t o \t " because many other files match. Is there an easer way to say "Give me the third found file?" Maybe something like one of these:

$ vim $3        // Third line
$ vim 'roger'   // Only line with string 'roger'
$ vim TabTabTab // Each Tab completes a different filename from grep

I do use Tmux and I know that I can go up and select the filename and then paste it. But that is still a bit clumsy, even as a VIM user. There must be a better way!

Note that I am not looking for a solution to script the grep output, rather this is something that I will be using manually as I grep for and open files with VIM.

EDIT: I am looking for a general solution, not one that will always target 'roger' or always target the third item.

Clarify question.
Source Link
dotancohen
  • 16.5k
  • 28
  • 87
  • 124

How might I more easily use a filename found by grep as an argument to vim:

$ grep -r foo *
lib/beatles/john.c
lib/pantera/phil.c
lib/pinkfloyd/roger.c
lib/pinkfloyd/richard.c
lib/whitestripes/elephant/jack.c

$ vim lib/pinkfloyd/roger.c

To autocomplete with Bash, I need to type " l \t p \t i \t r \t o \t " because many other files match. Is there an easer way to say "Give me the third found file?" Maybe something like one of these:

$ vim $3        // Third line
$ vim 'roger'   // Only line with string 'roger'
$ vim TabTabTab // Each Tab completes a different filename from grep

I do use Tmux and I know that I can go up and select the filename and then paste it. But that is still a bit clumsy, even as a VIM user. There must be a better way!

Note that I am not looking for a solution to script the grep output, rather this is something that I will be using manually as I grep for and open files with VIM.

EDIT: I am looking for a general solution, not one that will always target 'roger' or always target the third item.

How might I more easily use a filename found by grep as an argument to vim:

$ grep -r foo *
lib/beatles/john.c
lib/pantera/phil.c
lib/pinkfloyd/roger.c
lib/pinkfloyd/richard.c
lib/whitestripes/elephant/jack.c

$ vim lib/pinkfloyd/roger.c

To autocomplete with Bash, I need to type " l \t p \t i \t r \t o \t " because many other files match. Is there an easer way to say "Give me the third found file?" Maybe something like one of these:

$ vim $3        // Third line
$ vim 'roger'   // Only line with string 'roger'
$ vim TabTabTab // Each Tab completes a different filename from grep

I do use Tmux and I know that I can go up and select the filename and then paste it. But that is still a bit clumsy, even as a VIM user. There must be a better way!

Note that I am not looking for a solution to script the grep output, rather this is something that I will be using manually as I grep for and open files with VIM.

How might I more easily use a filename found by grep as an argument to vim:

$ grep -r foo *
lib/beatles/john.c
lib/pantera/phil.c
lib/pinkfloyd/roger.c
lib/pinkfloyd/richard.c
lib/whitestripes/elephant/jack.c

$ vim lib/pinkfloyd/roger.c

To autocomplete with Bash, I need to type " l \t p \t i \t r \t o \t " because many other files match. Is there an easer way to say "Give me the third found file?" Maybe something like one of these:

$ vim $3        // Third line
$ vim 'roger'   // Only line with string 'roger'
$ vim TabTabTab // Each Tab completes a different filename from grep

I do use Tmux and I know that I can go up and select the filename and then paste it. But that is still a bit clumsy, even as a VIM user. There must be a better way!

Note that I am not looking for a solution to script the grep output, rather this is something that I will be using manually as I grep for and open files with VIM.

EDIT: I am looking for a general solution, not one that will always target 'roger' or always target the third item.

Source Link
dotancohen
  • 16.5k
  • 28
  • 87
  • 124

Autocomplete from grep output

How might I more easily use a filename found by grep as an argument to vim:

$ grep -r foo *
lib/beatles/john.c
lib/pantera/phil.c
lib/pinkfloyd/roger.c
lib/pinkfloyd/richard.c
lib/whitestripes/elephant/jack.c

$ vim lib/pinkfloyd/roger.c

To autocomplete with Bash, I need to type " l \t p \t i \t r \t o \t " because many other files match. Is there an easer way to say "Give me the third found file?" Maybe something like one of these:

$ vim $3        // Third line
$ vim 'roger'   // Only line with string 'roger'
$ vim TabTabTab // Each Tab completes a different filename from grep

I do use Tmux and I know that I can go up and select the filename and then paste it. But that is still a bit clumsy, even as a VIM user. There must be a better way!

Note that I am not looking for a solution to script the grep output, rather this is something that I will be using manually as I grep for and open files with VIM.