Kevin Old wrote:
Hello everyone,
I have been thinking about implementing this little feature to help
clean up my code. Here's the scoop. I'm a Perl programmer and I use
a templating module called HTML::Mason which allows perl code within
certain "tags". Here's an example of the code:
<% $tmpl->template_top() %>
% $m->call_next();
<% $tmpl->template_bottom %>
<%init>
use Myapp::HTML;
use Myapp:Config qw(IMG_BASE_URL);
my $tmpl = Myapp::HTML->new({
title => 'Something',
js => ['jquery.js'] },
);
</%init>
<%flags>
inherit => undef
</%flags>
Between the <%init> tags is just straight Perl code. I have two maps
I've setup in vim that will run the contents of a file through an
external program (perltidy) and clean up my code. They are:
map ti :%!perltidy " clean entire file
map mt :.!perltidy " clean current line
Just wondering if there'd be a way that I could write a map that would
work for a current "block" of code. Maybe autodetect what block I'm
in? In this case whatever block I'm in (init). If I couldn't
autodetect the block I'm in, that'd be ok cause I could just map the
few types of blocks into separate map commands.
Should I go about this with a regex and then pass that line range to
the external command?
Any help is greatly appreciated!
Kevin
If you type : on a highlighted Visual area, you'll get :'<,'> as the range
(where '< means "the first line of the Visual area" and '> means "the last
line of the Visual area"). If you use that on an ex-command which accepts a
range (defined with the -range modifier) the range will be passed to the
command; otherwise it will be executed once for every line in the range.
v<object> where <object> is a Normal-mode "object", will highlight the
concerned object. Example: vip for the "inner paragraph".
Best regards,
Tony.