Chad Perrin: SOB

11 November 2008

a few Vim tips for NaNoWriMo

Filed under: Geek,Writing — apotheon @ 12:37

I’m one of those people who uses Vim as his text editor even during the month of November when trying to bang out 50K or more words of a novel in 30 days or less. So far, I’m doing pretty well: at this point, I’m on track for crossing the 50K mark by the end of Sunday if I just write more than 2500 words a day — fifteen days early.

There are a few things I’ve done to enhance my productivity when working on a NaNoWriMo project.

First and foremost, I use Vim. It’s the single most productivity enhancing editor I’ve ever encountered, just counting the default behavior of the thing. Various other vi-compatible editors have many of the same beneficial characteristics, of course, including my second favorite editor, nvi. Unfortunately, nvi seems to lack support for some critical capabilities.

I also automate comment notation. For instance, if I want to comment out a paragraph (because when you’re engaged in the NaNoWriMo challenge you definitely don’t want to delete any words, unless that’s just step one for moving them by pasting them elsewhere), the way I have it configured, it takes only three keystrokes to tell Vim to insert any of several comment markers I use.

I place /*************************************************************** above a section I want to comment out. All I have to do to make that happen is enter s# in Vim’s Insert mode and move on to the next line, and the s# is automatically replaced by the slash and asterisks. The line in my .vimrc file that makes that happen is:

:abbr s# /***************************************************************

I place ***************************************************************/ below a section I want to comment out in much the same way, but with e# as the triggering text. The relevant line in my .vimrc is:

:abbr e# ***************************************************************/

These comment block markers are also useful for programming languages like C, as I’m sure some of you are aware. In fact, those two lines from my .vimrc file were already there for programming purposes, and I just started using them for NaNoWriMo purposes as well.

When I want to insert notes to myself, I use brackets and a distinctive phrase to mark them so they’ll be easier to find with text searches later. The phrase I use is “greeley stinks” (don’t ask). Comments end up looking like “[greeley stinks: This is a note to myself.]”

I use the same abbreviation feature of Vim to automate the note labeling text as I do for inserting comment block start and end markers. The relevant line in my .vimrc file looks like this:

:abbr [g [greeley stinks:

That way, I can just type [g, and when I hit the space bar to start typing the actual note, Vim fills in the rest.

A set of commands (used in Vim’s Command Mode) I have found useful for writing (and editing) large blocks of English language text (the sort of thing one does during NaNoWriMo) includes:

  • 0 = move to the beginning of the textual line
  • $ = move to the end of the textual line
  • ^ = move to the first non-whitespace character on a textual line
  • A = enter insert mode after the last character on the textual line
  • I = enter insert mode before the first character on the textual line
  • gj = move down to the same number of characters in from the left on the next visual line
  • gk = move up to the same number of characters in from the left on the previous visual line
  • gg = move the cursor to the first line of the entire document
  • G = move the cursor to the last line of the entire document
  • H = move the cursor to the first textual line visible on the screen
  • L = move the cursor to the last textual line visible on the screen
  • M = move the cursor to the middle textual line of all lines visible on the screen
  • ) = move to the immediately following sentence beginning
  • ( = move back to the immediately previous sentence beginning
  • b = move to the beginning of the word
  • e = move to the end of the word
  • B = move to the beginning of the whitespace-delimited character group
  • E = move to the end of the whitespace-delimited character group

I stick to actual Vim, in a terminal emulator, rather than using gVim (the GUI version of Vim). This isn’t just some kind of retro Unix conceit, either: gVim breaks the way I use the copy and paste functionality of the X Window System. In X, you can copy and paste something by highlighting it using the mouse and middle-clicking where you want it pasted. In gVim, as in most MS Windows applications, you have to aim your mouse cursor exactly where you want it pasted when you do this, but in Vim it will paste exactly where you have your Insert text cursor located, as long as the mouse cursor is somewhere within the terminal emulator window where your Vim instance is running. That means I can just plop my mouse cursor down inside the window in general, not have to worry about aiming the damned thing, and hit the middle mouse button to paste. It’s much quicker and less of a distraction when I’m on a roll typing up a lengthy section of text.

Touch-typing is a necessity, of course, not only because Vim is designed primarily to enhance the productivity of touch-typists, but also because, all else being equal, a touch-typist can type much faster than a hunt-and-peck typist.

I find that laptops are generally better for text typing and editing productivity with Vim, too. One of the big wins for Vim and other vi-like editors is that one never needs to remove one’s fingers from home row — which, of course, is primarily of benefit if you’re a touch-typist. Having to remove a hand from a keyboard to use a mouse, then move it back and settle into the right place before getting back into the groove, can really break one’s stride. Laptop keyboards tend to come with trackpoints and touchpads so that a separate mouse is not needed, which has the secondary benefit of allowing the touch-typist to manipulate the mouse without dragging his or her fingers away from home row. I’ve noticed that using a mouse a lot can lend itself to RSI, too, which can be something of a productivity killer during NaNoWriMo.


  1. Hi Chad,

    Nice article!

    Regarding GVim: you can do the same type of highlight+middle-mouse-click for copy+paste even here. The trick is to set

    :set mouse=””

    (no space between the double quotes)

    What this does is to leave the insertion cursor where it is, even if you click with mouse and highlight text elsewhere in the buffer. This is what I do by default to get over the annoying sensitivity of the mouse-pad on my laptop.

    Hope this helps.

    Thanks, Desika

    Comment by Desika Nadadur | I Am My Own Master — 30 December 2008 @ 12:53

  2. Thanks for the information, Desika. Obviously, I didn’t know that. If I ever find myself having to use gVim instead of plain ol’ console-based Vim, I’ll have to keep that in mind.

    I find the touchpads on laptops annoying, too. When typing, I get strange stuff happening because the heel of one hand or the other might brush against the touchpad, so the mouse pointer moves around and “clicks” on things when I don’t intend it to. That’s one of the reasons I tend to get ThinkPads; I can turn off the touchpad in the BIOS/CMOS settings, and just use the trackpoint instead.

    Comment by apotheon — 30 December 2008 @ 02:04

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

All original content Copyright Chad Perrin: Distributed under the terms of the Open Works License