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:


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


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


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

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.