Friday, October 26, 2012

Multiline strings and "ruby << endpattern"

Hi,

I was under the impression that vimscript didn't support heredocs, so
I was surprised to discover that this works :

ruby << EOF
print "hello"
EOF

... swiftly followed by disappointment as I couldn't persuade it to
work with regular string literals ( eg "let foo=<<EOF...", or "MyFunc
<< EOF...".

Is there any way of putting heredoc-like string literals in vimscript?
If not, what magic is going on with the ruby() function?


( Background - I'm trying to embed a ruby script into a vim script.
I'm currently shelling out to ruby with system(), along the lines of :

let ruby_script = "
\ puts ARGV[1].upcase \n
\ puts ARGV[1].downcase \n
\"
let result = system("ruby -- - some_args", ruby_script)

- the embedded ruby script would be a lot nicer if it could use the
"ruby << EOF..." method, but a) I need to capture stdout from the
script, which doesn't seem possible(?) b) I can't see a way of passing
arguments or interpolating local variables into the heredoc string.)


Any hints?

-Jonathan

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: