Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

open vi with passed file name

Tags:

bash

vim

I usually use like this

$ find -name testname.c
./dir1/dir2/testname.c
$ vi ./dir1/dir2/testname.c

it's to annoying to type file name with location again.

how can I do this with only one step?

I've tried

$ find -name testname.c | xargs vi 

but I failed.

like image 403
Sungguk Lim Avatar asked Apr 06 '12 02:04

Sungguk Lim


2 Answers

Use the -exec parameter to find.

$ find -name testname.c -exec  vi {} \;

If your find returns multiple matches though, the files will be opened sequentially. That is, when you close one, it will open the next. You won't get them all queued up in buffers.

To get them all open in buffers, use:

$ vi $(find -name testname.c)

Is this really vi, by the way, and not Vim, to which vi is often aliased nowadays?

like image 130
Michael Berkowski Avatar answered Oct 05 '22 03:10

Michael Berkowski


You can do it with the following commands in bash:

Either use

vi `find -name testname.c` 

Or use

vi $(!!)

if you have already typed find -name testname.c

Edit: possible duplication: bash - automatically capture output of last executed command into a variable

like image 28
K Z Avatar answered Oct 05 '22 04:10

K Z