cat a.txt
echo hi
echo hu
echo ha
Q: how can I execute ex.: the second line in a.txt when it is opened with vi?
so "vi a.txt" -> then SOMEMAGICCOMMAND -> then the "echo hu" is executed as a command. How?
cat a.txt
echo hi
echo hu
echo ha
Q: how can I execute ex.: the second line in a.txt when it is opened with vi?
so "vi a.txt" -> then SOMEMAGICCOMMAND -> then the "echo hu" is executed as a command. How?
Executes current line and captures the output in the file replacing the line
:. !sh
Executes lines 2 to 4 and captures the output in the file replacing those lines
:2,4 !sh
Executes the whole file and captures the output in the file replacing all lines
:% !sh
Same as above but without capturing the output in the file, just printing it
:.w !sh
:2,4w !sh
:%w !sh
Assuming you're using vim
I know that if you select the line containing the text (Shift + V) and then give the command:
:!sh
It will execute the selected line and replace it with the results.
You can see what happens in the demo below.