Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I return values from a Perl method in a Vim script?

Tags:

vim

perl

I'm writing a Vim script. I have a function that uses embedded Perl. How do I return values from my Perl code?

like image 789
Eric Johnson Avatar asked Apr 04 '11 21:04

Eric Johnson


1 Answers

The key is to escape any single quotes in the value you are trying to return, and then use VIM::DoCommand("return '$data'").

For example:

function PhoneHome()
    perl << EOF
        use IO::Socket;
        my $mothership = IO::Socket->INET->connect()
        my $data = <$mothership>;
        $data =~ s|'|''|g; # escape '
        VIM::DoCommand("return '$data'")
    EOF
endfunction

Also see :help perl and :help perl-DoCommand. But for the most part this is not really documented.

like image 196
Eric Johnson Avatar answered Oct 20 '22 23:10

Eric Johnson