<<

. 18
( 69 .)



>>

Beginning of line Move to the start of the current line.
C-a
Backward char Move one character to the left.
C-b
End of line Move to the end of the current line.
C-e
Forward char Move one character to the right.
C-f
Next line Move down one line.
C-n
Previous line Move up one line.
C-p
Search backward Search backward for text.
C-r
Search forward Search forward for text.
C-s
Beginning of buffer Move to the start of the file.
M-<
End of buffer Move to the end of the file.
M->




– emacs adds the text to the
¤ Type your text directly
INSERT TEXT IN EMACS
into emacs. file at the insertion point.
„ Position the cursor where
you want to insert text.




77
UNIX FOR MAC




EDIT A FILE WITH EMACS
To make it easier to type Meta keystroke commands, those

Y
ou can edit and save text files in emacs with
indicated by the M- prefix, you can configure the Terminal
keystroke commands that use the Control and Meta
application to use the Option key. You can activate this
keys. You can also configure the Terminal application
Window setting from the Terminal menu. It allows you to
to allow the Option key to function as the Meta key.
type Meta keystrokes by holding down the Option key
while pressing the appropriate key, instead of pressing and
There are literally hundreds of emacs commands that you
releasing the Esc key before the following key.
can use, and you can even add additional extensions to
emacs to increase this number. Many of the more esoteric
You can also get emacs to recognize and work with your
commands in emacs are only of interest to serious Unix
mouse, a capability that most shell applications do not
users. As a beginning user, you may want to type C-h t to
possess. To do this, you enable the Terminal Window setting
read the emacs tutorial. To do this, you hold down the
named Option click to position cursor; when you hold
Control key and type the letter h, then release the Control
down the Option key and click your mouse, emacs moves
key and type the letter t.
the cursor to the current position of the mouse pointer.
A short list of commands that let you edit your files appears
on the facing page. As with other text editors, emacs does
not make your changes permanent until you save the file.




EDIT A FILE WITH EMACS




– The emacs editor exits and
¤ Press Control + S.
SAVE YOUR FILE EXIT EMACS
returns you to the shell
„ Press Control + X. „ Press Control + X.
– The emacs editor saves command line.
your file.
¤ Press Control + C.


78
5
WORK WITH TEXT EDITORS


The table below contains some emacs commands that you can use to edit
text files and save your changes.

KEYSTROKES COMMAND NAME EFFECT
Delete char Delete the current character.
C-d
Kill line Delete the current line, current position to end of line.
C-k
Transpose chars Transpose, or switch, two characters.
C-t
Save buffer, kill emacs Exit emacs.
C-x C-c
Find file Open a new file for editing.
C-x C-f
Save file Save the file.
C-x C-s
Transpose lines Transpose, or switch, two lines.
C-x C-t
Write file Save the file under a different name.
C-x C-w
Undo Undo the last change to the file.
C-x u
Query replace Find and replace text, type y to confirm.
M-%
Transpose words Transpose, or switch, two words.
M-w

Keep in mind that the prefix C- means to hold down the Control key while
pressing another key, and M- means you must press and release the Esc key
before typing the following key. You can also hold down the Option key to
type M- keystrokes, if you have enabled the correct Terminal setting.



Terminal




Window Settings...




– The Terminal Inspector ‹ Click the Use option key ˇ Click the red Close
CONFIGURE TERMINAL
TO WORK WITH EMACS window appears. as meta key check box. button to save your
„ Click Terminal ➪ Window preferences.
¤ Select Emulation from the › Click the Option click to
Settings. – The Terminal now uses
drop-down menu. position cursor check box.
the Option key as a Meta
key.
79
UNIX FOR MAC




SET YOUR PROMPT
multi-user system, or if you frequently log on remotely to

Y
ou can change your command line prompt by setting
other computers. However, many users are only on one
special shell variables. Changing your prompt lets you
computer at a time ” the one they are sitting in front of ”
customize the information that the prompt displays
and only as a single user. If this is true for you, you may
to better suit your needs.
want to set your prompt to the time, the number of
commands entered, or the full path.
The prompt lets you know that you are entering text into
the shell, rather than a program. When it reappears, this
In addition to the shell command prompt, you can set
tells you that the last command has finished executing. You
several other prompts. You use the prompt2 setting if you
can set your shell prompt to contain whatever information
end a command line with a backslash (\), indicating that the
you like using the following command:
current command continues on the next line. You see the
prompt3 message if you have auto correction on for
set prompt = 'prompt formatting sequence'
misspelled commands. You see the rprompt message on
A prompt formatting sequence is a series of letters, the right side of the Terminal window for every command.
symbols, and special character codes that serves as your
Prompt settings only last as long as the Terminal window in
prompt. A list of the most useful special formatting codes
which they are set is open. To make them permanent, see
appears on the facing page.
"Edit Your .tcshrc File" in this chapter.
The default prompt is set to the name of the computer, the
partial path, and your short username. This is useful on a



SET YOUR PROMPT




¤ Type a prompt formatting ¤ Type a prompt formatting
CHANGE THE DEFAULT PROMPT SET THE SECOND PROMPT
sequence in single quotes, sequence in single quotes,
„ Type set prompt = and a „ Type set prompt2 = and a
and press Return. and press Return.
space. space.
– The prompt changes. – The second prompt
changes.
80
6
CUSTOMIZE YOUR SHELL

set prompt = '[%m:%c3] %n%# ' is the standard
shell prompt in Mac OS X. The formatting Code table
explains the meanings of these and other special codes.

FORMATTING CODE EXAMPLE MEANING
%c Documents The current directory.
%d Fri The day of the week.
%D 06 The day of the month.
%cnumber local/etc/httpd A partial pathname.
%h 14 This is the 14th command.
%M ferro.idyllmtn.com The full name of the computer.
%m ferro The short name of the computer.
%n user Your short username.
%p 10:04:21pm The precise time.
%t 10:04pm The current time.
%w Dec The month of the year.
%W 12 The numerical month of the year.
%y 02 The year in two digits.
%Y 2003 The year in four digits.
%# % The % symbol, # if you are root.




¤ Type a prompt formatting ¤ Type a prompt formatting
SET THE THIRD PROMPT SET THE RIGHT-HAND PROMPT
sequence in single quotes, sequence in single quotes,
„ Type set prompt3 = and a „ Type set rprompt = and a
and press Return. and press Return.
space. space.
– The third prompt changes. – The right-hand prompt
changes.
81
UNIX FOR MAC


SET COMMAND ALIASES
As a result, all of your rm commands automatically include

Y
ou can save time and reduce typing by setting short
the -i option.
aliases for long commands. You can use the alias
command to define and list aliases. To create a new
If you redefine a command, such as the rm command, using
alias, you can use a command line like this:
an alias, and you need to use the original version, not the
alias, you can do so by typing a backslash (\) before the
alias short-alias 'longer command'
command name. This bypasses aliases and invokes an
executable program in your path or a shell built-in
One commonly used alias is ll, which most Unix users
command.
define with the following command:
To list all of your aliases, you can type alias without any
alias ll 'ls -l'
arguments. If you need to remove an alias, you can use the
This alias allows you to type ll as a command and have it unalias command.
execute the ls -l command, which shows a long listing.
Like other shell settings, your aliases only remain as long as
You can insert additional arguments, such as a directory,
your Terminal window is open. You can make your aliases

<<

. 18
( 69 .)



>>