Mac OS X’s default shell,
tcsh
, lets you move your cursor around in the
command line, editing the line as you type. There are two main modes
for editing the command line, based on the two most commonly used
text editors: Emacs and vi. Emacs mode is the default; you can switch
between the modes with:
The main difference between the Emacs and vi bindings is that the Emacs bindings are modeless (i.e., they always work). With the vi bindings, you must switch between insert and command modes; different commands are useful in each mode. Additionally:
Emacs mode is simpler; vi mode allows finer control.
Emacs mode allows you to cut text and set a mark; vi mode does not.
The command-history-searching capabilities differ.
Table 4-2 through Table 4-4 describe the various editing keystrokes available in Emacs mode.
Table 4-2. Cursor-positioning commands (Emacs mode)
Command |
Description |
---|---|
Control-B |
Move the cursor back (left) one character |
Control-F |
Move the cursor forward (right) one character |
Esc-B |
Move the cursor back one word |
Esc-F |
Move the cursor forward one word |
Control-A |
Move the cursor to the beginning of the line |
Control-E |
Move the cursor to the end of the line |
Table 4-3. Text-deletion commands (Emacs mode)
Command |
Description |
---|---|
Del Control-H |
Delete the character to the left of the cursor |
Control-D |
Delete the character under the cursor |
Esc-D |
Delete the next word |
Esc-Delete or Esc-Control-H |
Delete the previous word |
Control-K |
Delete from the cursor to the end of the line |
Control-U |
Delete the entire line |
Table 4-4. Command control (Emacs mode)
Command |
Description |
---|---|
Control-P |
Recall the previous command from history |
Control-N |
Recall the next command from history |
Up arrow |
Recall the previous command from history |
Down arrow |
Recall the next command from history |
|
Search history for |
|
Like Esc-P, but search forward in the history |
Esc |
Repeat the next command |
Control-Y |
Yank the previously deleted string |
vi mode has two submodes:
insert mode and
command mode. The default mode is insert. You can toggle between the
modes by pressing Esc; alternatively, in command mode, typing
a
(append) or i
(insert) will return you to insert mode.
Table 4-5 through Table 4-11 describe the editing keystrokes available in vi mode.
Table 4-5. Commands available (vi’s Insert and Command mode)
Command |
Description |
---|---|
Control-P |
Recall the previous command from history |
Control-N |
Recall the next command from history |
Up arrow |
Recall the previous command from history |
Down arrow |
Recall the next command from history |
Table 4-6. Editing commands (vi Insert mode)
Command |
Description |
---|---|
Control-B |
Move the cursor back (left) one character |
Control-F |
Move the cursor forward (right) one character |
Control-A |
Move the cursor to the beginning of the line |
Control-E |
Move the cursor to the end of the line |
Delete or Control-H |
Delete the character to the left of the cursor |
Control-W |
Delete the previous word |
Control-U |
Delete from the beginning of the line to the cursor |
Control-K |
Delete from the cursor to the end of the line |
Table 4-7. Cursor-positioning commands (vi Command mode)
Command |
Description |
---|---|
h or Control-H |
Move the cursor back (left) one character |
l or Space |
Move the cursor forward (right) one word |
w |
Move the cursor forward (right) one word |
b |
Move the cursor back (left) one word |
e |
Move the cursor to the ending of the next word |
W, B, E |
Like w, b, and e, but treat whitespace as a word separator instead of any nonalphanumeric character |
^ or Control-A |
Move the cursor to the beginning of the line (first nonwhitespace character) |
O |
Move the cursor to the beginning of the line |
$ or Control-E |
Move the cursor to the end of the line |
Table 4-8. Text-insertion commands (vi Command mode)
Command |
Description |
---|---|
a |
Append new text after the cursor until Esc is pressed |
i |
Insert new text before the cursor until Esc is pressed |
A |
Append new text after the end of the line until Esc is pressed |
I |
Insert new text before the beginning of the line until Esc is pressed |
Table 4-9. Text-deletion commands (vi Command mode)
Command |
Description |
---|---|
x |
Delete the character under the cursor |
X or Delete |
Delete the character to the left of the cursor |
d |
Delete from the cursor to the end of motion command
|
D |
Same as d$ |
Control-W |
Delete the previous word |
Control-U |
Delete from the beginning of the line up to the cursor |
Control-K |
Delete from the cursor to the end of the line |
Table 4-10. Text-replacement commands (vi Command mode)
Command |
Description |
---|---|
c |
Change the characters from the cursor to the end of motion command
|
C |
Same as c$ |
r |
Replace the character under the cursor with the character
|
R |
Replace multiple characters until Esc is pressed |
s |
Substitute the character under the cursor with the characters typed until Esc is pressed |
Table 4-11. Character-seeking motion commands (vi Command mode)
As was just illustrated, the tcsh
shell offers
dozens of special keystroke characters for navigation on the command
line. Table 4-12 lists some additional command-line
keys for use in either Emacs or vi editing mode.
Table 4-12. Additional key commands for the tcsh shell
Key command |
Description |
---|---|
Control-C |
Interrupt the process; cancels the previous command ( -. works as well). |
Control-D |
Used to signal end of input for some programs and return you to the shell prompt. If Control-D is issued at a shell prompt, it will close the Terminal window. |
Control-I |
Display an |
Control-J |
Same as pressing the Return (or Enter) key; hitting Control-J after issuing a command will invoke the command, or it will take you to the next line in the shell if no command was given. |
Control-K |
Remove everything to the right of the insertion point. |
Control-L |
Clear the display. |
Control-Q |
Restart output after a pause by Control-S. |
Control-S |
Pause the output from a program that’s writing to the screen. |
Control-T |
Transpose the previous two characters. |
Control-Z |
Suspend a process. To restart the process, issue the
|
Esc-C |
Capitalize the word following the insertion point. |
Esc-Esc |
If only a partial path or filename is entered, pressing the Esc key twice will complete the name. |
Esc-L |
Change the next word to all lowercase letters. |
Esc-U |
Change the next word to all uppercase letters. |
Tab |
Get Mac OS X Pocket Reference now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.