Commandments of text editing

As a programmer, one of the main user interfaces I work with day-to-day is a text editor. I find this interface to be extremely natural and efficient, when it's done right. A text editor isn't the same thing as a wordprocessor - text is all monospaced and there are no fonts or embellishments like bold, italic and underline. Colour may be present for syntax highlighting purposes, but you can't set the colour of individual characters. An important aspect of a text editor is that what you see should be exactly what you get - there should be no "hidden" information. For this reason I eschew spaces at the ends of lines and tab characters (though unfortunately documents with such things sometimes have to be handled for compatibility reasons).

I think that a find that a text editor is best thought of as a (very large) 2D grid, with one character in each cell of the grid. Moving around this grid should be predictable - the left arrow key should always move the cursor one space to the left (unless it's at the beginning of the line, in which case it should do nothing). Similarly for the other arrow keys. Home should always move the cursor to column 1 of the current line, End should move it to the cell after the last character in the current line. If you move it the cursor from the end of a long line up or down to a shorter line, the cursor shouldn't jump to the end of the line, it should remain in the same column, and spaces should be inserted as necessary if you type in such non-existent locations.

To get around the document more quickly, the PgUp and PgDn keys should scroll the document up and down a screenful at a time (leaving the cursor in the same location on the screen). Pressing the arrow keys with Ctrl held down should move the cursor a predictable amount (say 5 characters/lines at a time). Many editors take Ctrl+Left and Ctrl+Right to mean "move left a word" and "move right a word" but I think consistency in number of characters moved is more useful.

Ctrl+PgUp and Ctrl+PgDn should take one to the beginning or end of the document respectively.

Moving through the document while keeping the cursor in the same place is useful too - let's use the Alt key for this. If Alt is held down the same move is performed relative to the document but the cursor is kept in the same place on the screen.

The shift key should be used to select text (i.e. if you move the cursor with the shift key held down, the text from the point where you pressed shift to the current cursor location should be selected. One should also be able to use the mouse for selecting text (though it's rare that I find myself doing this in a good text editor). Selecting rectangular areas of text is also occasionally useful, though sufficiently rare not to need a modifier key dedicated to it. Typing in a selection should delete it, as should the Del key when text is selected. When text is not selected, Del should delete the character or line break to the right of the cursor.

It's very important that all the CUA keyboard shortcuts work:
Ctrl+C for copy
Ctrl+X for cut
Ctrl+V for paste
Ctrl+Z for undo
Ctrl+Y for redo
Ctrl+S for save
Ctrl+A for select entire document
Ctrl+F for search

The insert key should toggle insert mode (very useful when working with fixed-width data).

A few other things I miss if they aren't there: F3 to load a new file. Alt+W to save the current selection as a new file. Alt+R to read a file and insert it into the document at the cursor position. Esc to switch to a menu for accessing less often used functions such as macros and window splitting. Alt+F6 for switching to the next file in the ring.

The text editor I have found that follows most of these ideals is TSE, and it's always one of the first things I install on a new machine. With some tweaking I could probably get it even closer to my ideal. Unfortunately it doesn't run well on Linux at the moment. For this reason (and others) one of these days I may write my own text editor to replace it.

2 Responses to “Commandments of text editing”

  1. Jim Leonard says:

    TSE has one glaring omission -- no Undo!!! For that reason I don't use it.

    I did a review of editors a while ago, geared towards 8088 of course: http://www.oldskool.org/guides/texteditors

    • Andrew says:

      I had forgotten that the DOS versions of QEdit/TSE/TSEJr didn't have undo (QEdit used to be my DOS editor but I guess I didn't miss that feature, not being used to undoing editors back then).

      TSE for Windows does have Undo, and that's what I use from day to day.

Leave a Reply