<<

. 15
( 69 .)



>>

learn. Because of its simplicity, Pico is a good choice for
delete key to erase text to the left of the cursor.
new users of the Mac OS X shell as well as experienced
users who need to do simple text editing.



OPEN A FILE WITH PICO




– The Pico editor opens the – This area displays the
¤ Type the name of a text
OPEN A FILE WITH PICO
file and press Return. file and displays it for you. document.
„ Type pico and a space.
– This area displays the – This area displays Pico
filename. commands.




60
5
WORK WITH TEXT EDITORS


The basic keystrokes for Pico appear on-screen. The function of each keystroke
is not immediately obvious, so this table summarizes the most useful Pico
commands. Many of these commands are not intuitive, but the mnemonics
may help. For example, to view the help screen you would press Control + G,
not Control + H, so you might think of the command as getting help.

KEYSTROKE MNEMONIC FUNCTION
^C Current location Display the location of the cursor.
^D Delete Delete the character under the cursor.
^G Get help Display the program help screens.
^J Justify Reformat a paragraph.
^O write Out Save the current file.
^R Read file Insert the contents of another file.
^X eXit Quit Pico; save if necessary.
^W Where is Find text in the current file.
^V - Scroll down a page.
^Y - Scroll up a page.




– Pico inserts your text at the
¤ Type the text you want to
ENTER TEXT IN PICO
add. cursor.
„ Position the cursor where
you want to enter text.




61
UNIX FOR MAC




EDIT A FILE WITH PICO
The Pico text editor has several command-line options that

Y
ou can edit text in the Pico editor, performing basic
you can use when starting the editor. The -f option
tasks such as finding specific text or saving a file. Pico
activates the function keys, although you should note that
is based on the text-editing functions of the Pine
only the first four keys, F1 through F4, work in Mac OS X.
e-mail program, a shell application that allows you to
The -v option opens a file in read-only mode, which means
compose, send, and read e-mail. You can learn more about
that you cannot make any changes in the file.
installing and using the Pine e-mail program in Chapter 13.
The most useful Pico editing commands are those that find
If you edit a file with long lines, Pico does not automatically
and modify text, save a file, and then allow you to exit the
wrap the lines of text to fit the size of the window. Instead,
text editor. For example, to locate a phrase or word, you can
Pico shows a dollar sign ($) at the right side of the Terminal
press Control + W. Saving a file is the same as writing an
window for each line that extends beyond the width of the
output file, so you can use the Control + O command to
window. You can view those lines by moving the cursor up
save your work. If you do not save your file, and you press
or down with the arrow keys, and then using the right and
Control + X, Pico asks you whether you want to save the file.
left arrows to move through the line.




EDIT A FILE WITH PICO




– The search menu appears. – Pico moves the cursor to
FIND TEXT IN PICO
the text.
„ Press Control + W. ¤ Type the text you want to
find and press Return.




62
5
WORK WITH TEXT EDITORS




You can move text within your file by using the cut-and-paste
functions of Pico. Pico uses keyboard commands to mark,
copy, delete, and move sections of text. Pico does not allow
you to export text to other applications.
To cut a section of text in Pico, move the cursor to the start
of the text you want to cut by using the arrow keys. Press
Control + Shift + 6. Pico marks the beginning of the text block
that you want to select by highlighting it in black. Using the
arrow keys, move the cursor to the end of the text selection
and press Control + K. Pico cuts the block from the file. This
is an easy way to delete large sections of text.
To paste text into a new location, use the arrow keys to
position the cursor where you want to move the deleted text
and press Control + U. This command uncuts, or pastes, the
text.




¤ Type y to save your file or
Note: You can change the filename
SAVE A FILE WITH PICO QUIT PICO
by using the Delete key or adding n to exit without saving.
„ Press Control + O. „ Press Control + X.
text.
– The Pico editor exits.
– The Pico editor prompts – The Pico editor asks
¤ Type the name of the file
you with the current whether you want to save
and press Return.
filename. your file.
– Pico saves the file.

63
UNIX FOR MAC




OPEN A FILE WITH VI
a sample filename with the full path would be

Y
ou can use the vi editor to edit text files. The vi editor
/tmp/vi.Y8pi7R, because vi stores temporary files in the
is more powerful than Pico and can perform many
/tmp directory.
more text-editing functions. The name vi is short for
visual; vi is a visual editor because you can edit the files on-
When vi displays a file, lines that are longer than the width
screen as you see them, as opposed to using the command
of the Terminal screen continue on the next line. The vi
line as you would with sed, a stream editor. To begin using
editor breaks lines at the edge of the screen, which means
the vi editor, you can type vi at the command prompt with
that the first half of a word may appear at the end of one
an optional filename argument:
line, with the other half beginning on the next line. The
word itself is still intact and whole; vi simply displays it this
vi file-name
way for editing purposes.
If you do not specify a filename, the vi editor creates a
The vi editor automatically uses the full Terminal window. If
temporary file for you and opens that temporary file for
there are additional lines on the screen that vi does not use
editing. The name of the temporary file consists of a
to display the file, a tilde (˜) appears at the beginning of
seemingly random series of characters and numbers;
each of these lines. These are not part of your file; they
simply indicate the end of the content of the file.


OPEN A FILE WITH VI




– The vi editor opens and – This area displays the
¤ Type the name of a text
EDIT A FILE IN VI
file and press Return. displays the file. document.
„ Type vi and a space.
– This area displays the ‹ Press Control + Shift + X
filename. to exit the file.




64
5
WORK WITH TEXT EDITORS


You can change the behavior of the vi editor by setting editor options.
You do this by typing a colon (:), the word set, a space, and then the
option name. For example, to turn on line numbers, type :set number. To
turn off an option, type a colon, the word set, a space, the word no, and
then ” with no space before it ” the name of the option. For example,
to turn off line numbers, you type :set nonumber.

OPTION FUNCTION
autoindent Automatically indent new lines.
list Display a $ symbol to indicate the end of each line.
number Display line numbers on the left.
ruler Display the current line number and character position.
showmode Show the current mode, for example, insert, in the lower
right corner.
verbose Use wordy and informative warnings and messages.

You can see which options are currently set if you type :set and press
Return. For a full list of all vi editor options, type :set all.




– The vi editor starts and – Tilde symbols indicate the
¤ Type the name of a new
CREATE A NEW FILE WITH VI
document and press Return. displays an empty file. end of the file.
„ Type vi and a space.




65
UNIX FOR MAC




MOVEMENT WITHIN VI
To move within a document in vi, the application must be in

Y
ou can use single keystroke commands to move
Command mode. The vi editor offers many ways to
through a file in the vi editor. One feature that
navigate the content of a file, some of which appear on the
distinguishes the vi editor from the other visual
facing page. The easiest way is to use the arrow keys to
editors is the concept of modes. The vi editor is always
move the cursor, as you would in Pico. You can also use the
in one of two states, Command mode or Input mode.
lowercase letters h, j, k, and l to move the cursor around
Command mode allows you to use keystroke commands to
on-screen.
delete lines, move text, or save files. Input mode allows you
to type text into the document at the location of the cursor.
The find command in vi is much like the find command
While in Command mode, you can use keystroke
in less. When you type a forward slash (/) and enter the

<<

. 15
( 69 .)



>>