121 lines
4.0 KiB
HTML
121 lines
4.0 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
|
<HTML>
|
|
<HEAD>
|
|
<title>Novice Bash Tip Issue 14</title>
|
|
</HEAD>
|
|
<BODY >
|
|
|
|
<H4>
|
|
"Linux Gazette...<I>making Linux just a little more lovable!</I>"
|
|
<IMG ALIGN=MIDDLE SRC="../gx/heart.gif"> </H4>
|
|
|
|
<P> <HR> <P>
|
|
<!--===================================================================-->
|
|
|
|
<center>
|
|
<H2>Novice Bash Tip -- Edit command-lines "joe-style"</H2>
|
|
<H4>By Joel Wilf,
|
|
<a href="mailto:av293@lafn.org">av293@lafn.org</a></H4>
|
|
</center>
|
|
|
|
<P> <HR> <P>
|
|
|
|
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.
|
|
<P>
|
|
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.
|
|
<P>
|
|
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:
|
|
|
|
<P>
|
|
<H3>Step 1: define keys with .inputrc:</H3>
|
|
<P>
|
|
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.
|
|
<P>
|
|
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:
|
|
<PRE> <h5>
|
|
"\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
|
|
</h5> </PRE>
|
|
You can also add the following lines, which fix the behavior of
|
|
the <home>, <end>, <delete>, and <backspace>
|
|
keys:
|
|
<PRE> <h5>
|
|
"\e[1~": beginning-of-line
|
|
"\e[3~": delete-char
|
|
"\e[4~": end-of-line
|
|
DEL: backward-delete-char
|
|
</h5> </PRE>
|
|
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.
|
|
|
|
<P>
|
|
<H3>Step 2: fix terminal settings with stty:</H3>
|
|
<P>
|
|
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.
|
|
<P>
|
|
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):
|
|
<PRE> <h5>
|
|
stty stop '^p'
|
|
</h5> </PRE>
|
|
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:
|
|
<PRE> <h5>
|
|
stty -a
|
|
</h5> </PRE>
|
|
This will display your terminal settings. If you reassigned the
|
|
"stop" key as shown above, you should see "stop = ^P".
|
|
<P>
|
|
Now you're home free. All you have to do is exit and log in
|
|
again. And you can edit commands "joe-style."
|
|
<P>
|
|
|
|
<!--===================================================================-->
|
|
<P> <hr> <P>
|
|
<center><H5>Copyright © 1997, Joel Wilf <BR>
|
|
Published in Issue 14 of the Linux Gazette</H5></center>
|
|
|
|
<!--===================================================================-->
|
|
<P> <hr> <P>
|
|
<A HREF="./index.html"><IMG ALIGN=BOTTOM SRC="../gx/indexnew.gif"
|
|
ALT="[ TABLE OF CONTENTS ]"></A>
|
|
<A HREF="../index.html"><IMG ALIGN=BOTTOM SRC="../gx/homenew.gif"
|
|
ALT="[ FRONT PAGE ]"></A>
|
|
<A HREF="./shells.html"><IMG SRC="../gx/back2.gif"
|
|
ALT=" Back "></A>
|
|
<A HREF="./vim.html"><IMG SRC="../gx/fwd.gif" ALT=" Next "></A>
|
|
<P> <hr> <P>
|
|
</BODY>
|
|
</HTML>
|
|
|