1

Suppose I want to edit a new libvirt XML file:

virsh dumpxml machine1 > machine2.xml

Then I open the file with vim,

vim machine2.xml

and then I want to change the UUID. Now do this, I use

:r ! uuidgen

But the new UUID is inserted under the current line:

<uuid>6r123ttz-6t01-356t-1y7h-g7oe196c8u3m</uuid>
e67baf90-751b-4aea-a14b-aca1b881542b

How may I insert the output of the uuidgen command into the current line, so that if I have

<uuid></uuid>

(with the cursor between ><), then, by executing uuidgen I get

<uuid>e67baf90-751b-4aea-a14b-aca1b881542b</uuid>

The question is: is possible to use the :r vim command without adding a new line?

  • I reformulated the question. If you feel that I misrepresented you, then feel free to roll back the edit. – Kusalananda Mar 25 at 6:49
1

I had a play around and this doesn't do exactly as you want as :r will always enter a newline. But it should do what you want for a result.

:.!UUID=`uuidgen` ; echo "<uuid>$UUID</uuid>"

It puts the stdout on the current line (not at the cursor) - the smarts are done with the command that is being invoked.

  • It create also a newline, is a nice workaround, so for the moment I consider as right answer – elbarna Mar 25 at 22:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.