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'
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.