Saturday, April 08, 2006

A Couple Writing Tricks I've Discovered

I’ve written loads of material from design documentation to white papers to proposals.  Now I’m working on a book.  I’ve come up with several writing tricks which work well for me when dealing with code-related issues.

One trick is to use GVim to quickly get rid of indents on code snippets I’m going to be pasting in to O’Reilly’s template.  Sure, CopyAsHTML will get rid of indents if you so configure it, but using that results in fugly text.  For example, the following text in VS:



            // obtain stock information from xml file

            DataSet ds = new DataSet();

            System.IO.Stream file =

                Assembly.GetExecutingAssembly().GetManifestResourceStream( "NPlotDemo.resources.asx_jbh.xml" );

            ds.ReadXml( file, System.Data.XmlReadMode.ReadSchema );

            DataTable dt = ds.Tables[0];

becomes this nasty stuff:

<div style="font-family: Lucida Sans Typewriter; font-size: 10pt; color: black; background: white; font-weight: bold;">

<p style="margin: 0px;">plotSurface.Clear();</p>

<p style="margin: 0px;">&nbsp;</p>

<p style="margin: 0px;"><span style="color: green; font-weight: normal;">// obtain stock information from xml file</span></p>

<p style="margin: 0px;"><span style="color: teal; font-weight: normal;">DataSet</span> ds = <span style="color: blue; font-weight: normal;">new</span> <span style="color: teal; font-weight: normal;">DataSet</span>();</p>

<p style="margin: 0px;">System.IO.<span style="color: teal; font-weight: normal;">Stream</span> file =</p>

<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span style="color: teal; font-weight: normal;">Assembly</span><span style="font-weight: normal;">.GetExecutingAssembly().GetManifestResourceStream( </span><span style="color: maroon; font-weight: normal;">"NPlotDemo.resources.asx_jbh.xml"</span> );</p>

<p style="margin: 0px;">ds.ReadXml( file, System.Data.<span style="color: teal; font-weight: normal;">XmlReadMode</span><span style="font-weight: normal;">.ReadSchema );</span></p>

<p style="margin: 0px;"><span style="color: teal; font-weight: normal;">DataTable</span> dt = ds.Tables[0];</p>


That’s unusable.

Instead I copy the snippet from VS, pop open GVim via SlickRun, paste the contents in, and with Shift-V (visual line mode), Shift-G (select to bottom), < (shift left), and after two periods (repeat last command) I’ve got all the indents out. gg takes me back to the top of the file, then Shift-V, Shift-G and Ctrl-Insert to copy the entire buffer content.

OK, that may look like a bunch of keystrokes, but it actually goes pretty easy.  Plus it uses GVim/Vim which is the ultimate in lightweight text editors.   As a matter of fact, I could make a Vim macro to do all that in one swell foop…  I’ll knock that out soon. (Yes, yes, Notepad2 rocks.  GVim rulz.)

Second trick relates to making screenshots of multiple windows.  Alt-PrtScn nicely grabs the active window, eliminating background cruft.  But what to do when you’ve got several windows at once you need to grab and you don’t want a bunch of confusing junk in the spaces between the windows?  Easy: maximize an Explorer window opened to an empty (or lightly filled) and use that as your background.

I’d love to hear of any tricks you folks have come up with for authoring any sort of material, or pointers to good references for these sorts of tips.


tod said...

For screen shots I use Cropper. You can easily grab just a single portion of a window (like a picture or section of text) or elements of multiple windows (as you reference above). You can find it at:


Jim Holmes said...

I've tried Cropper and it just didn't click with me. Actually, it didn't just not click -- I hated it.

I didn't realize it did multiple window elements, though. I'll give it another eval.

Ayende Rahien said...

Jim, you can undo indenting in VS as well, select the text you want and hit SHIFT+TAB

Jim Holmes said...

Yeah, Ayende, I realize that, but then you've got to reformat that section again. I guess it's kind of a wash for total keystrokes, though.

(But doing that in VS means I don't get to use GVim which was my primary development environment during some good times!)

Jim Holmes said...

I just tried Cropper again. It's OK, but it doesn't grab elements of multiple windows, per say, it's just grabbing a region of the screen. I'm gonna work with it some more to give it a fair chance.

Matt said...

Regarding copying text, rather than just select text with the mouse, do it while pressing the alt key. This way you select a box worth of text, rather than lines. Combine with CopyAsHtml and you get beautiful results.

Jim Holmes said...

How dumb I am sometimes! I use that Alt box selection all the time for other uses and have just completely spaced it out for this use. Duh!

Thanks for the kick in the pants!

Subscribe (RSS)

The Leadership Journey