in reply to Suggested templates for Perl

I have a very flexible three-part system that turns Vim (my favorite editor) into the perfect Perl IDE for me. Part 1 is a shell script that creates the file, adds a shebang, a dated comment with the author's name, and a 'use strict;' -

#!/bin/bash # Created by Ben Okopnik on Mon Apr 28 11:41:01 EDT 2008 # Enter your name here; otherwise, your login name will be used name="" [ -z "$1" ] && { printf "Usage: $0 <file_to_create>\n"; exit; } [ -f "$1" ] && { printf "File already exists!\n"; exit; } printf "#!`which perl` -w\n" > $1 printf "# Created by ${name:-$USER} on `date`\nuse strict;\n\n\n" >> $ +1 chmod +x $1 vi + $1

The next two parts are Vim keymaps which live in my "~/.vimrc":

map <silent> <F2> :set filetype=perl<CR>:set kp=perldoc\ -f<CR>:0<CR>: +-r!which perl<CR>I#!<ESC>$a -w<ESC>o# Created by Ben Okopnik on^[:r!d +ate<CR>-J^<CR>iuse strict;<CR><CR> map <F5> :w<CR>:![ -x "%:p" ]\|\|chmod +x "%:p"<CR>:!"%:p"

The 'F2' key inserts the same content as the script would plus sets up a few useful things in Vim - e.g., hitting the 'K' key now runs 'perldoc -f ' instead of 'man ' on the word under the cursor. Perl syntax highlighting is also enabled. The 'F5' key saves the file, makes it executable if it's not already, then presents you with the command line dialog where hitting the 'Enter' key will execute the current file. You can also enter any arguments your script needs at that time. When it's done, you're returned to your Vi session.

I realize that this is more than just a template, but for me, that bit is pretty much inextricably tied up with all the rest of it. I'm too Lazy to use just templates. :)


-- 
Human history becomes more and more a race between education and catastrophe. -- HG Wells