5.7. Command-Line Manipulation

 < Day Day Up > 

tcsh provides functionality for manipulating the command line, including word or command completion and the ability to edit a command line.

5.7.1. Completion

The shell automatically completes words and commands when you press the Tab key, and notifies you when a completion is finished by appending a space to complete filenames or commands and a / to complete directories.

In addition, tcsh recognizes ~ notation for home directories; it assumes that words at the beginning of a line and following |, &, ;, ||, or && are commands, and modifies the search path appropriately. Completion can be done midword; only the letters to the left of the cursor are checked for completion.

5.7.2. Related Shell Variables

  • autolist

  • fignore

  • filec

  • listmax

  • listmaxrows

5.7.3. Related Command-Line Editor Commands

  • complete-word-back

  • complete-word-forward

  • expand-glob

  • list-glob

See the tcsh manpage for a discussion of the built-in command-line editor and its commands.

5.7.4. Related Shell Built-ins

  • complete

  • uncomplete

5.7.5. 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 -v       Select 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.

5.7.5.1. 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 (Emacs mode)

Command

Description

CTRL-P

Previous command.

CTRL-N

Next command.

Up arrow

Previous command.

Down arrow

Next command.

cmd-fragment M-p

Search history for cmd-fragment, which must be the beginning of a command.

cmd-fragment M-n

Like M-p, but search forward.

M-num

Repeat next command num times.

CTRL-Y

Yank previously deleted string.


5.7.5.2. vi mode

vi mode has two submodes, input mode and command mode. The default mode is input. You can toggle modes by pressing Esc; alternatively, in command mode, typing a (append) or i (insert) will return you to input mode.

The editing keystrokes available in vi mode are described in Tables 5-4 through 5-10.

Table 5-4. Command history (vi input and command modes)

Command

Description

CTRL-P

Previous command.

CTRL-N

Next command.

Up arrow

Previous command.

Down arrow

Next command.

Esc

Toggle mode.


Table 5-5. Editing (vi input mode)

Command

Description

CTRL-B

Move cursor back (left) one character.

CTRL-F

Move cursor forward (right) one character.

CTRL-A

Move cursor to beginning of line.

CTRL-E

Move cursor to end-of-line.

DEL or CTRL-H

Delete character to left of cursor.

CTRL-W

Delete word backward.

CTRL-U

Delete from beginning of line to cursor.

CTRL-K

Delete from cursor to end-of-line.


Table 5-6. Cursor positioning (vi command mode)

Command

Description

h or CTRL-H

Move cursor back (left) one character.

l or SPACE

Move cursor forward (right) one character.

w

Move cursor forward one word.

b

Move cursor back one word.

e

Move cursor to next word ending.

W, B, E

Like w, b, and e, but treat only whitespace as word separator instead of any nonalphanumeric character.

^ or CTRL-A

Move cursor to beginning of line (first nonwhitespace character).

0

Move cursor to beginning of line.

$ or CTRL-E

Move cursor to end-of-line.


Table 5-7. Text insertion (vi command mode)

Command

Description

a

Append new text after cursor until Esc.

i

Insert new text before cursor until Esc.

A

Append new text after end of line until Esc.

I

Insert new text before beginning of line until Esc.


Table 5-8. Text deletion (vi command mode)

Command

Description

x

Delete character under cursor.

X or DEL

Delete character to left of cursor.

dm

Delete from cursor to end of motion command m.

D

Same as d$.

CTRL-W

Delete word backward.

CTRL-U

Delete from beginning of line to cursor.

CTRL-K

Delete from cursor to end of line.


Table 5-9. Text replacement (vi command mode)

Command

Description

cm

Change characters from cursor to end of motion command m until Esc.

C

Same as c$.

rc

Replace character under cursor with character c.

R

Replace multiple characters until Esc.

s

Substitute character under cursor with characters typed until Esc.


Table 5-10. Character-seeking motion (vi command mode)

Command

Description

fc

Move cursor to next instance of c in line.

Fc

Move cursor to previous instance of c in line.

tc

Move cursor to just before next instance of c in line.

Tc

Move cursor to just after previous instance of c in line.

;

Repeat previous f or F command.

,

Repeat previous f or F command in opposite direction.


     < Day Day Up > 


    Unix in a Nutshell
    Unix in a Nutshell, Fourth Edition
    ISBN: 0596100299
    EAN: 2147483647
    Year: 2005
    Pages: 201

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net