Re: Execute command for current block of code
On Wed, Nov 22, 2006 at 11:32:46AM -0800, Gary Johnson wrote: On 2006-11-22, A.J.Mechelynck [EMAIL PROTECTED] wrote: vobject where object is a Normal-mode object, will highlight the concerned object. Example: vip for the inner paragraph. And if you're using the matchit.vim plugin with your tags specified in b:match_words, then a% will highlight the current block as defined by your tags. :help v_a% I was thinking of the same thing. Two more points: if you have not yet installed the help files for matchit.vim, see :help matchit-install After that, you should have help tags for v_a% . See also :help matchit-newlang for how to recognize your custom tags. HTH --Benji Fisher
Execute command for current block of code
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 -- Kevin Old [EMAIL PROTECTED]
Re: Execute command for current block of code
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. vobject where object is a Normal-mode object, will highlight the concerned object. Example: vip for the inner paragraph. Best regards, Tony.
Re: Execute command for current block of code
Hi Tony, Actually, I didn't know that highlighting visually and hitting the : will give me the range. That's half the battle for me on this. I've tried putting that into a mapping like this: map vti :',' !perltidy but when I visually select a chunk of code then type vti I get and error saying: E492: Not an editor command ',' !perltidy Now my question is, how do I program a mapping so that I don't have to type the !perltidy after I highlight the lines of code I need cleaned up. Thanks, Kevin On 11/22/06, A.J.Mechelynck [EMAIL PROTECTED] wrote: 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. vobject where object is a Normal-mode object, will highlight the concerned object. Example: vip for the inner paragraph. Best regards, Tony. -- Kevin Old [EMAIL PROTECTED]
Re: Execute command for current block of code
* Kevin Old on Wednesday, November 22, 2006 at 12:57:27 -0500: Actually, I didn't know that highlighting visually and hitting the : will give me the range. That's half the battle for me on this. I've tried putting that into a mapping like this: map vti :',' !perltidy vmap vti :!perltidyCR c -- _B A U S T E L L E N_ lesen! --- http://www.blacktrash.org/baustellen.html
Re: Execute command for current block of code
Christian Ebert wrote: * Kevin Old on Wednesday, November 22, 2006 at 12:57:27 -0500: Actually, I didn't know that highlighting visually and hitting the : will give me the range. That's half the battle for me on this. I've tried putting that into a mapping like this: map vti :',' !perltidy vmap vti :!perltidyCR c See also :help filter Best regards, Tony.
Re: Execute command for current block of code
On 2006-11-22, A.J.Mechelynck [EMAIL PROTECTED] wrote: vobject where object is a Normal-mode object, will highlight the concerned object. Example: vip for the inner paragraph. And if you're using the matchit.vim plugin with your tags specified in b:match_words, then a% will highlight the current block as defined by your tags. :help v_a% HTH, Gary -- Gary Johnson | Agilent Technologies [EMAIL PROTECTED] | Wireless Division | Spokane, Washington, USA