[vox-tech] vim coolness - printing code

Peter Jay Salzman p at dirac.org
Fri Dec 31 09:07:53 PST 2004


Hi all,

Suppose you're tracking down a bug in your program but need to go somewhere,
like DMV, and you want to take your code with you while you wait on line.

The program is too long to print out in its entirety, so you could:

   1. Make a temporary copy of the program
   2. Edit out the code before the code of interest
   3. Edit out the code after the code of interest
   4. Save the temp file
   5. Print the temp file.
   6. Delete the temp file.

Or you could do this:

   1. Visual select the code of interest
   2. Type:  "!enscript"  (no ':')


I just tried it on a lark, and it worked.  I've piped stuff before in Vim,
so maybe I shouldn't be so surprised.  Suppose this is the code of interest:



sub Read_Plotvar()
{
	return if (! -r "$var{plotvars}");  # No plotvar file exists

	open(FP, "<$var{plotvars}");
	print "\nPlotvars:\n";


	while( $_ = <FP> )
	{
		next if /^#/;      # Skip comments
		/(.*): (.*)/;      # Grab the variable and its value

		die "Malformed plotvar" if (! defined $1 || ! defined $2);

		$plotvar{$1} = $2;
		DEBUG && print "  $1: $2\n";
	}

	DEBUG && print "\n";
}


   1. Place cursor anywhere on the first line.
   2. Type "shift-v" to enter line selection mode.
   3. Type "j" to go down one line.
   4. Type "%" to reach the bottom of the subroutine.
   5. Type "!enscript"  (no ':')



I can do this whole process in under 2 seconds for arbitrarily large
functions.

Thought this was neat enough to post...

Pete


-- 
The mathematics of physics has become ever more abstract, rather than more
complicated.  The mind of God appears to be abstract but not complicated.
He also appears to like group theory.  --  Tony Zee's "Fearful Symmetry"

GPG Fingerprint: B9F1 6CF3 47C4 7CD8 D33E  70A9 A3B9 1945 67EA 951D


More information about the vox-tech mailing list