I just ran across this page and thought I should mention how I do vim extensions in perl.

First, I put all the code in a module, which I load from the vim script. All of the mappings and functions I want to define are in the vim script, but they are just stubs for a perl functions, eg

function! s:rowwise_dd() range perl VIM::CSV::rowwise_dd endfunction nnoremap <buffer> <LocalLeader><Left> :perl VIM::CSV::prev_col<CR>
By putting only trivial perl in the vim script, I minimize difficult-to-debug problems that come from mixing perl and vim. Also, things like syntax highlighting work perfectly on the module.

Second, I want the module to syntax-check outside of vim (the major pay-off of step one). This is a simple matter of duplicating the prototypes that vim implicitly sets up, eg

sub VIM::DoCommand ($); sub VIM::Eval ($); sub VIM::Msg ($;$);
I have not made any effort to make my module run outside of vim, as it is quite intimately tied to vim.

Third (my favorite part), some syntactic sugar to make vim commands look like vim commands (this should be its own module, but I'm lazy):

use Filter::Util::Call; BEGIN { filter_add( sub { my $status = filter_read; return $status unless /^\s*:/; s/"/\\"/g; s/:(.*)/VIM::DoCommand "$1";/; return $status; }) } ... :w

By the way, the problem that you don't get any output from syntax errors is really a perl bug.


In reply to Re: Writing a Filter::Simple -based filter for .vim by pimlott
in thread Writing a Filter::Simple -based filter for .vim by Intrepid

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



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.