running ruby -p -e from vim

S

seannakasone

For you vim users:

Because you can do a lot with just 1 line of ruby code, it seems
natural to use ruby with the -p -e options to editor text from within
an editor like vim. However, I just can't seem to figure out how to
use |v| and $&. vim seems to interpret these and i escaping them with
'\' doesn't work.

i.e. let's say i do a visual block on these lines.
the quick brown cat
the quick brown cat

And I wanted to run these commands:
:'<,'> !ruby -p -e "gsub(/cat/) {|v| puts v}
:'<,'> !ruby -p -e "gsub(/cat/) {|v| puts #{$&}}

how do i escape the characters to prevent vim from interpreting them?
 
D

Dumaiu

Never tried Ruby with Vim, but I should. It looks like you are
trying in your example to call gsub() without a receiver. From reading
`:help ruby`, I'd say you would have much better luck using Vim's
embedded Ruby API. `:version` should list '+ruby' somewhere in its
output. If it doesn't, let us know and we'll go from there.

-J
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,087
Latest member
JeremyMedl

Latest Threads

Top