I want to run a system command from vim (:help :!
), and I want to pass the contents of a string variable as stdin for that command.
I already know I can pass lines from the current buffer as stdin (see :help :w_c
). But I don't want to modify the current buffer, and I don't want to make a new buffer.
I know I can write the string to a temporary file, then pipe that file as input and delete it. Right now, that's the best solution I know for my application. But it would be cleaner to avoid creating the file in the first place.
Can it be done?
so basically, you have a variable, say, a string, and you want to pass this variable to an external command, and get returned value in a variable instead of buffers.
If above is right, you could do in this way, see the following example:
let s="vim is good"
let r=system("sed 's/good/the best/'",s)
echo r
"display vim is the best
echo s
"display vim is good
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With