Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Question:

Can someone provide a very simple proof-of-concept perl sample that works as a text filter for (g)Vim?

Background:

H is editing text with Vim. Vim can filter a region of text using (among other things) the built-in Vim-script language or an external program. H already has a trusty arsenal of perl scripts that can do various text-filtering operations, and H wants to use those instead of essentially re-writing them all in Vim-speak.

Problem:

H is able to get Vim filtering to work with other external programs, but not with perl. For example:

!sort <-- this Vim command calls a binary, OK !myfilter.pl <-- this Vim command calls a perl script, FAIL
The root of the problem appears to be that H cannot figure out how to get the input from Vim through STDIN.

Proposed Solution:

H simply wants to see a bare-bones simple perl script that can filter text successfully from Vim (just like !sort can do) just to prove that it can indeed be done. It doesn't have to be sort, just something simple like:

#!/usr/local/perl ### myfilter.pl my $sTest = ''; while(<STDIN>){$sTest .= $_;} print " _IT_WORKED_ $sTest _IT_WORKED_ ";

NOTE: The previous code might as well be pseudocode, because it is not working. When run from Vim, the target text is not filtered, but simply blanked out. The _IT_WORKED_ tags do, however, appear.
NOTE: H has not been able to find any examples in the usual search venues.
NOTE: Alternate solution proposals are welcome, but see Constraints.

Constraints:

  • H requests cross-platform solution (linux and windows).
  • Vim :echo has("perl") returns false, and re-installing or recompiling Vim source is not an option.
  • H is willing to try an alternate approach (e.g., mucking with the Clipboard, temp files) as long as it is still cross-platform.
  • H knows that external process is less performant than native Vim, but performance loss is more acceptable than wheel-reinvention.
TIA

Update:Thanks for all the suggestions, unfortunately none of them worked on Windows, this seems to be a problem with inter-process communication between Vim and STDIN on Windows ... still looking for a solution
Update:Bingo. bmann and Re: Batch files in Win/Perl helped re-emphasize the long-known (yet forgotten) Windows bug ... pl2bat has a solution. Knee-jerk nauseated aversion to the words 'MSDOS' and 'batch' caused repressed memory syndrome...

20050219 Edit by castaway: Changed title from 'HOWTO: A simple, perl-based text filter for Vim'


In reply to How do I create a simple, perl-based text filter for Vim by dimar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-04-19 23:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found