"Linux Gazette...making Linux just a little more lovable!"


Novice Bash Tip -- Edit command-lines "joe-style"

By Joel Wilf, av293@lafn.org


If like me, you come from the world of DOS and WordStar, you feel right at home with the joe editor, which uses WordStar keystrokes.

But as soon as you exit joe, you're back in the land of bash, where command-lines are edited "emacs-style." Soon, your fingers are confused. Before you know it, you're pressing <control>-d to move the cursor, only to find your command-line disappearing.

But why use one set of keys to edit text and another to edit commands? The beauty of Linux is that you can customize it to your heart's content. Here's how to make bash act like our old friend, joe:

Step 1: define keys with .inputrc:

The bash command-line is handled by the GNU readline library. So it's not surprising that bash uses the same keystrokes as GNU emacs. Luckily, you can change these key-bindings simply by setting new values in the file .inputrc.

The first step is to go to your $HOME directory and open or create a text file named .inputrc. Then add the following lines, which tell bash to use the basic joe keystrokes:

 
"\C-d": forward-char "\C-s": backward-char "\C-f": forward-word "\C-a": backward-word "\C-g": delete-char "\C-t": kill-word "\C-y": kill-whole-line
You can also add the following lines, which fix the behavior of the <home>, <end>, <delete>, and <backspace> keys:
 
"\e[1~": beginning-of-line "\e[3~": delete-char "\e[4~": end-of-line DEL: backward-delete-char
Finally, you can use .inputrc to modify any one of the dozens of keystrokes and variables that control bash. (Among other things, you can get bash to stop beeping at you!) Check the READLINE section of the bash man page for details.

Step 2: fix terminal settings with stty:

An experienced Linuxer will see that the changes we made to .inputrc has created a problem. We set <control>-s to it's WordStar meaning. But the Linux terminal uses <control>-s to send the "stop" signal. Pressing <control>-s freezes the terminal until you type <control>-q, the "start" signal.

The easiest way to fix this is to tell the terminal to use a different "stop" key. To reassign "stop" to <control>-p, type the following line (and put it in your .bashrc to make it permanent):

 
stty stop '^p'
You can prove this works by pressing <control>-p then <control>-q. It's also a good idea to check your terminal configuration -- especially if you change other keys with .inputrc. Type:
 
stty -a
This will display your terminal settings. If you reassigned the "stop" key as shown above, you should see "stop = ^P".

Now you're home free. All you have to do is exit and log in again. And you can edit commands "joe-style."


Copyright © 1997, Joel Wilf
Published in Issue 14 of the Linux Gazette


[ TABLE OF CONTENTS ] [ FRONT PAGE ]  Back  Next