The "vi
" way (vs the "ex
way") is historically more like:
vi /tmp/$$.out
~
~
:r!locate php.ini
Instead of trying to pipe to vi
from stdin or stdout (which is not normally supported outside of vim
-alikes), you open vi
and use ex
Command mode to execute your "shell stuff". Then you can munge the results in-place.
This method should work in any proper ex
implementation. vi
is traditionally just a Visual Interface to ex
.
Or putting it another way, ex -v
is more commonly known / executed as "vi
" for short.
You could even perform these kinds of operations with a macro (@
) in Input mode and/or use u
ndo to make changes and/or corrections.
The ex
way
If you want to do it in a script then it could be with ex
commands from a here-doc or something:
tmp=/tmp/$$.out
ex -s ${tmp} <<'EOS'
r!locate php.ini
wq
EOS
vi ${tmp}
You can use almost any combination of valid scripting / sh
or ex
commands with this method, such as the find
suggestion from others.
This could also be done with ed
but I was never one of the cool kids.
Again, ex
is POSIX, so it should work in GNU/Linux, *BSD, HP-UX, AIX, etc.
Variation
Presuming there are no security concerns, you might redirect to a file first then munge it separately, depending on your use case:
tmp=/tmp/$$.out
locate php.ini > ${tmp}
vi ${tmp}
However...
If just browsing is truly your goal then you may only need something like:
locate php.ini | more
I am throwing that out there because we can all over-complicate simple things at times.
reset
to reset your terminal when it gets screwed up (you don't have to disconnect from ssh session). – wisbucky Nov 01 '18 at 22:17