l i n u x - u s e r s - g r o u p - o f - d a v i s
Next Meeting:
July 7: Social gathering
Next Installfest:
Latest News:
Jun. 14: June LUGOD meeting cancelled
Page last updated:
2004 Dec 31 09:23

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
[vox-tech] vim coolness - printing code
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[vox-tech] vim coolness - printing code

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

Thought this was neat enough to post...


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
vox-tech mailing list

LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
Sunset Systems
Who graciously hosts our website & mailing lists!