How to Customize Joe
Adding Win-esque Keystrokes

Sometimes the best applications are found on the Unix/Linux console. If one were to assume the standards I've already published for plain text files then one of the best applications for adhering to those standards is Joe (Joe's Own Editor). This tutorial was composed in Joe, of course, taking advantage of the new syntax highlighting for HTML files.

Many long-time computer users love Joe because they can resurrect their old WordStar keystrokes and get a lot of work done quickly. I never used WordStar; I love Joe because it permits all the formatting and editing features I need as a writer. Better yet, it can be customized to allow each user to include their own keystrokes. Yes, I admit I've been deeply tainted by the DOS/Win pattern of keystrokes. Most of the computer users in the world are in the same boat, so I'm hardly alone. I find it annoying that each text editor I've tried in Unix/Linux has its own unique keystrokes. Rather than learn a whole raft of different and confusing command sequences for each one, I've settled on a few, and Joe is my favorite, primarily because I can easily teach Joe how to behave to suit me.

Much of what follows is based on the work of Anne Baretta and the good folks on the Joe mailing list.

Basic Theory

You probably know that there is nothing inherent in the signals produced by your keyboard that puts out this or that character or code from the same key on every keyboard throughout the world. Otherwise, folks with non-English alphabets couldn't use computers in their own lanaguage. In Unix/Linux we run the keyboard output through an interpreter before it hits the application or the X server. Normally, we establish that interpreter during the installation of our OSs when we select our langaguage and keyboard layout. For some applications, we have to make special adjustments in various config files to change their default behavior. Joe is one of the few that knows how to read those codes directly, and you can tell Joe what they should mean.

For example, the F-keys. By default, none of them mean anything in Joe. If you are working in a console (no GUI) or in a terminal emulator (Konsole, XTerm, RxVT, Gnome-Terminal, etc.) there is a distinct code being transmitted, and we can capture that code with characters on screen. Simply type CTRL+V (for the clueless, that means hold down the CTRL key and then hit V). The next keystroke or combination you type will display a code that Joe can read. It will not work for a sequence of keystrokes, but only for a single or single combination. Let's try the F1 key:

^[OP

is what you will see in most cases. Here's what that means:

^[ = "escape" ("Hey, we're changing modes here!")

O P = the specific code Joe can read

Okay, so what do we do with this? First, you will need to get a copy of the Joe config file for your own home directory. It will be named joerc on every system I know about, and you can usually find it with the locate command. When you find it, copy it to your home directory:

cp /path/to/system/config/joerc ~/

In many BSD systems, you'll need to change permissions on the file first so you can edit it.

chmod 0644 joerc

Open your new joerc in any text editor. For now, ignore all the stuff at the top, and slide on down a ways until you start seeing the names of some odd commands set against the left margin, with another column that shows keystrokes in codes similar to what we saw above:

pgdn   .kN   Screen down
pgdn   ^V
pgdn   ^[ [ 6 ~
pgup   .kP   Screen up
pgup   ^U
pgup   ^[ [ 5 ~

Notice what comes by default in the config file -- both the pgup and pgdn commands are listed several times, and one entry for each includes one of those odd sequences that start with ^[ (escape sequence) and end with a couple of other codes. The third column, if there's anything there, explains in plain English what the command does. By the way, if you read above in the joerc file you'll find that the .kx business represents the "grey keys" or numeric keypad on older keyboards. You'll also learn that Joe understands some of the F-keys already, but none are used. Note that the caret ^ usually means the CTRL key. Hitting CTRL+[ or ^[ is the same as hitting the ESC key.

Now, for the rest of the story

What follows are the keystrokes I have added, so that Joe is comfortable for me. Explainations are under each example. You are advised to check each keystroke combination in the terminal or terminal emulator you will be using. RxVT is different from XTerm, for example. Older versions of Konsole will ignore some combinations, like CTRL+HOME. Notice that the codes which appear on your console output must be spaced out after the initial escape sequence ^[. Just follow the examples below. Insert your custom commands close to where you find similar commands. Keep this in mind: Joe tries to parse everything that is set against the left column. If Joe is confused by it, you'll have an error when you try to start it. Simply move the offending line one space right, and Joe will ignore it.

Move down in the file to the part where you see remarks about Ispell and Aspell. While most agree Aspell is somewhat better, it may not work well with Joe on some systems. Be sure you have installed the spell checking program you want to use. This especially is a problem in Debian-based Linux distros, and some BSDs, in that neither program is installed by default. I prefer Ispell:

ispellfile   .k7

I use F7 to start the spell checker (entire file; different command for just one word). Place the next two lines below the spelling commands:

:def capit filt,"tr a-z A-Z"
:def uncapit filt,"tr A-Z a-z"

These define two macros so that I can easily capitalize anything highlighted, or uncapitalize as well. They appear as the commands capit and uncapit just below:

capit   .k1
uncapit   .k2

which makes the F1 key capitalize everything highlighted, and F2 makes it lower case.

dnslide   ^[ [ 1 ; 3 B

upslide   ^[ [ 1 ; 3 A

ALT+DOWN will scroll the screen downward, leaving the cursor where it is. Similar command for scrolling upward: ALT+UP

blkcpy   .k8

blkmove   .k9

F8 will copy a highlighted block to where the cursor sits. F9 will move the block.

bof   ^[ [ 1 ; 5 H

eof   ^[ [ 1 ; 5 F

CTRL+HOME takes you to the beginning of file and CTRL+END takes you to the end.

center   .k4

Center a line of text with the single keystroke F4.

delch   ^[ [ 3 ~

Some Unix/Linux systems cling tenaciously to the ancient meaning of the DEL key, which is not what most of us expect. This will insure we delete the character under the cursor, and pull the remaining text left. The cursor does not move; it devours in place, pulling everything on its right and below.

fmtblk   .k3

F3 will now reformat the current paragraph, so that the right end of each line falls within my specified range (72 characters), tries to remove double spaces between words and sentences (read the top of the joerc file), and performs all sorts of other complex changes. Experiment and you will see.

bol   ^[ [ H

eol   ^[ [ F

This insures that the HOME and END keys take you to the beginning and end of the current line, respectively.

exsave   .k;

save   .F1

F10 will save the file and close it. F11 will save but continue editing, or give you the option of saving to a new filename.

markb   .k5

markk   .k6

F5 will begin the highlighting, and F6 will close it. You must start at the upper left of your block, or Joe will get confused.

mode,"T"   .kI

Hitting the INSERT key will toggle between "insert mode" and "overtype mode."

nextword   ^[ [ 1 ; 5 C

prevword   ^[ [ 1 ; 5 D

CTRL+RIGHT takes you to the next word, CTRL+LEFT the previous word.

When you are finished, be sure to save your joerc as .joerc. Adding a period to front of the file adds it to the collection of "dot-files" in your home directory that are designed for configuration files, and are normally not visible.

Syntax Highlighting

In plain text, it never matters. However, if you do any sort of coding, even with simple HTML files, it's quite useful to have your editor display various recognized symbols and commands in colors. For example, I'm writing this file in Joe, and I see tags with green brackets and cyan letters.

With older versions of Joe, you would find file-type options near the top of the configuration file. However, with later versions which offer syntax highlighting for a wider range of file-types, this has been placed in a separate file, .ftyperc. As before, you'll need to locate where the default version for your system resides and copy to your home directory. I include the leading dot to hide it from normal view. Whatever you name it, you must be sure to accurately source it in your .joerc. In mine, it looks like this:

:include /usr/home/jeh/.ftyperc

That's the full path to the file on my FreeBSD system. Inside the .ftyperc I have made some changes so Joe will load default instructions for various file-types with which I often work. Here are the options I set for files ending in ".txt" --

 Text file.
*.txt
-wordwrap
-tab 3
-indentc 32
-istep 1
-spaces
-purify
-rmargin 72
-french

Again, notice the top line of this example is indented one line. These options tell Joe (in sequence) to automatically line-wrap any thing extending beyond the right margin, that tabs are 3 characters wide, insert regular blank spaces when I hit the TAB key, when I indent a block (using ^K .) I want to shift one space at a time, when formatting indented blocks keep using regular blank spaces all the way down, when I reformat a paragraph replace any TAB spaces with regular blank spaces, my right margin should always be set at 72 characters, and that I don't want double spaces between sentences if I reformat anything.

I use similar instructions for both types of HTML files, and the same options when I call up Joe from Mutt (look for Mail file, *tmp/mutt-*).

Extras

By the way, did you know some of these same tricks can be used to create macros for things you type repeatedly? For example, I do all my HTML compositions in Joe. I also use Joe to clean up HTML files I get from other places for use in my personal archive. They are mostly academic documents, with lots of footnotes. The code to make footnote markers which move the browser down to the footnotes and back is used heavily, so I have made macros to speed up the task.

Down in the section of my .joerc devoted to coders, the heading is Compile (indented one space so Joe will ignore it, but humans can use it for guidance):

:def fnlnk "[<a href=\"#fnx\">x</a>]"
:def fnid "<a id=\"fnx\" name=\"fnx\" />"
:def rplnk "[<a href=\"#rpx\">return</a>]"
:def rpid "<a id=\"rpx\" name=\"rpx\" />"
:def htlnk "<a href=\"\">"

These are appropriate for Bash, based on its scripting language. If you use another shell, you'll need to research the scripting tags for that. I won't bog you down too much with that just now, but some of the slashes in the example above are necessary to get Bash (& Joe) to treat the following character as-is, instead of as a command. Further down in my .joerc are the following activation codes of these macros:

fnlnk  ^[ O 2 P  # SHIFT+F1 footnote link
fnid  ^[ O 2 Q  # SHIFT+F2 footnote id anchor
rplnk  ^[ O 2 R  # SHIFT+F3 return link
rpid  ^[ O 2 S  # SHIFT+F4 return id anchor
htlnk  ^[ [ 1 5 ; 2 ~  # SHIFT+F5 generic link

The net result is I can hit SHIFT+F4 and get this at the cursor:

<a id="rpx" name="rpx" />

Those who code HTML will recognize that as a reference point ("anchor") which brings the browser back up to the text from the applicable footnote. All I have to do each time I use these macros is change the x to the appropriate number. Thus, the footnotes (fn) and return points (rp) are easy to track, and provide an enhanced reading experience.

One final item: I like to know where I am in a file without having line numbers displayed along the left column (which is an option). Instead, I have configured Joe to display that information in the status line at the top of the window. In the FIRST SECTION of your .joerc, near the bottom of that section, you'll see some lines begin with -lmsg and -rmsg. The second one determines what is displayed on the right end of the status bar. By default, on most version of Linux and BSD, you'll see something like this: %S Row %r, followed by some other coding. Immediately after, I add this sequence: /%l (lower-case "L"). Thus, the line looks like this:

-rmsg  %S Row %r/%l Col %c %t  Ctrl-K H for help

In the status line at the top, it produces a display on the right side like this:

Row 403 /424  Col 1

meaning "Row 403 of 424 rows." Row is the same as line, obviously. Thus, the display tells me the cursor is near the bottom of the file, which may not be obvious if I can't see the last line displayed on the screen. You can make other customizations by reading the instructions in the file just above those lines. Beware of putting too much clutter in your status bar, though. The idea is to make it useful and informative.

Enjoy!


By Ed Hurst
Updated 10 Janurary 2007

COPYRIGHT NOTICE: People of honor need no copyright laws; they are only too happy to give credit where credit is due. Others will ignore copyright laws whenever they please. If you are of the latter, please note what Moses said about dishonorable behavior -- "be sure your sin will find you out" (Numbers 32:23)