Command-Line Editing

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 common text editors: Emacs and vi. Emacs mode is the default; you can switch between the modes with:

    % bindkey -e     
                  Select Emacs bindings
    % bindkey -vSelect vi bindings

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 input 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 yank cut text and set a mark; vi mode does not.

  • The command-history searching capabilities differ.

Emacs mode

The various editing keystrokes available in Emacs mode are described in Tables 5-1 through 5-3.

Table 5-1. Cursor positioning (Emacs mode)

Command

Description

CTRL-B

Move cursor back (left) one character.

CTRL-F

Move cursor forward (right) one character.

M-b

Move cursor back one word.

M-f

Move cursor forward one word.

CTRL-A

Move cursor to beginning of line.

CTRL-E

Move cursor to end of line.

Table 5-2. Text deletion (Emacs mode)

Command

Description

DEL or CTRL-H

Delete character to left of cursor.

CTRL-D

Delete character under cursor.

M-d

Delete word.

M-DEL or M-CTRL-H

Delete word backward.

CTRL-K

Delete from cursor to end-of-line.

CTRL-U

Delete entire line.

Table 5-3. Command history ...

Get Unix in a Nutshell, 4th Edition 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.