[ILUG] Re: Question for Vim gurus

Matthew Sammon m at banjaxed.net
Tue Jul 3 19:07:07 IST 2001


* Rory Winston <rwinston at eircom.net> [2001-07-02 09:33:34]:
> really good, but what I'd like to be able to do is to place the cursor
> on a line containing a subprocedure, hit a key, and Vim to generate an
> automatically formatted comment block, e.g. for 
>
> sub foo()
> 
> Vim generates
> 
> # Name : foo
> # Author : blah
> # Last Modified: whenever

let MyName="Jo Blogs"
let MyDateFormat="%Y-%m-%d %H:%M:%S"

function! MyCommentBlock(MyName, MyDateFormat)
   let MyName=a:MyName
   let MyDateFormat=a:MyDateFormat
   normal 0w"aye
   normal o# Name : ^["ap
   normal o# Author : ^R=MyName^M^[
   normal o# Last Modified : ^R=strftime(MyDateFormat)^M^[
endfunction

nmap     ,C          :call MyCommentBlock(MyName, MyDateFormat)

you can also issue:
:call MyCommentBlock('John Foobar', '%d-%m-%y')
to avoid using the predefined vars at the top

In the above ^R = Ctrl + V followed by Ctrl + R
             ^] = Ctrl + V followed by Esc
             ^M = Ctrl + V followed by Ret

Also the above function does not check to see if a comment block
already exists, but this feature could be easily added with a call to
match() etc etc


-- 
Matthew Sammon <m at banjaxed.net>




More information about the ILUG mailing list