Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
Shells: User's Guide: HP 9000 Computers > Chapter 20 Command Lines and Command History

Using Inline Editing Modes

» 

Technical documentation

Complete book in PDF
» Feedback
Content starts here

 » Table of Contents

 » Index

There are two types of editing modes available in POSIX and Korn Shell: the vi mode and the emacs mode. A discussion of each of these methods follows. These Shell editing modes emulate the corresponding editors and all common commands are the same. Inline editing is very similar to using the editor in that inline editing uses the common editor's commands.

Using vi Line Edit Mode

The vi editing mode uses the same commands as the vi editor. If you are unfamiliar with the vi editor, see Using HP-UX, or The Ultimate Guide to the vi and ex Text Editors.

Enabling vi Line Edit Mode

There are several ways to enable the vi editing mode. One is to type:

set -o vi

For further details on the set command see Chapter 23 “Advanced Concepts and Commands”.

Another is to set and export the VISUAL shell variable in your .profile or .kshrc, to a value ending in vi:

VISUAL=vi
export VISUAL

If VISUAL is assigned a string that ends in vi, gmacs, or emacs, then the corresponding editor mode is enabled.

Finally, you can set and export EDITOR in your .profile or .kshrc:

EDITOR=vi
export EDITOR

Now, if VISUAL is not set, and EDITOR is assigned a string containing vi, gmacs, or emacs, then the corresponding editor mode is enabled.

Performing Inline Edits

Now, you are ready to perform inline editing. Enabling an editor mode places you into the editor's command mode, although when typing it does not appear anything has changed. This allows you to continue typing and executing command lines as before. It also allows you to type ESC and enter input mode. Once you are in input mode, you can edit the specified line using most vi commands and then re-execute it by typing Return. For example, suppose you type:

$ echo surprris

Then, before you press the Return, press ESC. Now you can move on the line using Backspace (not LeftArrow) to the point where you made your mistake. Then you execute the vi delete command, x, to remove the extra r and the append command, A, to add the letter e to the end of the line:

$ echo surprrisESCBackspaceBackspacexAeESCReturn

The new line and output looks like this:

$ echo surprise
surprise

For a complete listing of all the vi commands usable within the POSIX and Korn Shell vi mode, see the sh-posix(1) and ksh(1) manual pages in the HP-UX Reference.

Using emacs and gmacs Line Edit Mode

The other editors implemented for inline editing are emacs and gmacs. The only difference between these two editor modes is the function of the CTRL-T command (which transposes characters).

With these editors there is no command mode; you are always in input mode. To use emacs or gmacs commands, you hold the CTRL key down while pressing a character key or press ESC followed by a character key.

Enabling emacs Line Edit Mode

Again, there are different ways to enable emacs or gmacs mode. One is to type:

set -o emacs

or

set -o gmacs

The other is to set either VISUAL or EDITOR as described in “Enabling vi Line Edit Mode”.

Performing Inline Edits

Now, you are ready to perform inline editing with emacs. As you know, enabling an editor mode places you into the editor's command mode. Although, to you it does not appear anything has changed as you continue typing in and executing command lines. For example, suppose you type:

$ echo surrpri

Before you press the Return, press four CTRL-Bs. This moves you left on the line to the point where you made your first mistake. Then, it is a simple matter of executing the CTRL-D or delete command on the extra r. To move forward again, use CTRL-E to move the cursor to the end of the line. Now, simply type in the rest of the line:

$ echo surrpriCTRL-BCTRL-BCTRL-BCTRL-BCTRL-DCTRL-EseReturn

The new line and output looks like this:

$ echo surprise
surprise

There are also ESC sequences that move you forward and backward by words rather than letters: ESCb moves you backward one word and ESCf moves you forward one word.

For a complete listing of all the emacs commands usable within the POSIX and Korn Shell emacs mode, see the sh-posix(1) and ksh(1) manual entries in the HP-UX Reference.

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© 1983-1991 Hewlett-Packard Development Company, L.P.