You'll get your Mac news here from now on...

Help TMO Grow

Advertising Info

The Mac Observer Express Daily Newsletter

More Info

Site Navigation

Columns & Editorials

Mac OS X Command Line 101
by Richard Burton

Pico: An Easy To Use Command Line Editor
Part XVI of this series...
November 1st, 2002

For every problem, there is an explanation that is simple, neat, and wrong.
H.L. Mencken, Prejudices

This series is designed to help you learn more about the Mac OS X command line. If you have any questions about what you read here, check out the earlier columns, write back in the comments below, or join us in the Hardcore X! forum.

If you read this column regularly, you have my sympathy. But seriously, folks, you may remember the mild hoo-ha that resulted when I actually dared to *gasp* write about the vi editor. Like most holy wars, that involving your Unix editor choice often comes down to personal tastes and prejudices. Therefore, I tried to chose a middle path between something pretty complex (emacs) and something pretty simple (pico). Naturally it satisfied no one. Let this be a lesson, kids; by staying in the middle of the road, you're more likely to get hit by traffic.

However, as sometimes happens with shouts from the peanut gallery, someone yells out a good point. In this case, it may be that vi can be daunting for the inexperienced. And as I've said before, no one needs more daunts. Therefore, today's column is about a much simpler (though less powerful) editor, pico.

pico comes with Jaguar, so you don't need to download and install it. Just to be sure, check:

    [localhost:~] dr_unix% which pico
    [localhost:~] dr_unix% 
First, a little background. pico was originally developed to be the editor of choice for pine, a simple, easy-to-use command-line mail program written at the University of Washington. (In Unix' grand tradition of nested and self-referential acronyms, pine allegedly stands for "pine is not elm", elm being another command-line mail tool.)

pine was to be used by people who aren't comfortable with a Unix command line: secretaries, data entry clerks, students, and moving down the evolutionary scale, tenured professors and university administrators. As such, pine had to be plain, simple, and straightforward. Likewise, the editor had to be just as plain, simple, and straightforward as pine. This is no small task, but the people at U-dub are to be commended for the results. pine is about the best command-line mail utility I've stumbled across, and the editor, pico, can be grasped easily by secretaries and data entry clerks. Even Perl programmers like yours truly can use it. (Alas, bureaucrats have trouble with it, and the students are rather hit and miss. Well, let's face it, some things just aren't possible.)

Oh, and don't bother looking for pine with the which command; it doesn't come with Jaguar.

Invoking pico is straightforward. Just type:

    pico filename

So, if you've been following this column for a while, and still have the old file testfile in your home directory, type:

    pico testfile

at the command line prompt. This should give you something along the lines of :

       UW PICO(tm) 2.5                   File: testfile                             
    Now is the time for all good men (and women, of course) to
    come to the aid of the party.
    We're out of ice cream.
    This is a very long line, with more than the eighty characters that you will no$
    Work is the curse of the drinking classes. - Oscar Wilde
                                    [ Read 8 lines ]
    ^G Get Help  ^O WriteOut  ^R Read File ^Y Prev Pg   ^K Cut Text  ^C Cur Pos   
    ^X Exit      ^J Justify   ^W Where is  ^V Next Pg   ^U UnCut Text^T To  Spell

So, what have we here? Remember, pico is designed for ease of use. If you want to add text, just start typing. There is no 'command mode' and 'insert mode' as in vi. Likewise, you can move around using the four arrow keys.

All of the pico editing commands are control-characters, and some of the most commonly used are listed along the bottom of the terminal window. For those new to these sorts of things, this just means that you hold down the control key (on the lower left or lower right of your keyboard) while you hit the key. Since there is no printable "control" character as such, it is represented by a carat, ^, followed by the letter. See the "^G Get Help" in the lower left of the screen? The "^G" denotes a control-G. Hold down the control key and hit a "G" (lower or upper case, it doesn't matter). This should take you to the help screen, thus:

       UW PICO(tm) 2.5                   File: testfile                             
            Pico Help Text
            Pico is designed to be a simple, easy-to-use text editor with a
            layout very similar to the pine mailer.  The status line at the
            top of the display shows pico's version, the current file being
            edited and whether or not there are outstanding modifications
            that have not been saved.  The third line from the bottom is used
            to report informational messages and for additional command input.
            The bottom two lines list the available editing commands.
            Each character typed is automatically inserted into the buffer
            at the current cursor position.  Editing commands and cursor
            movement (besides arrow keys) are given to pico by typing
            special control-key sequences.  A caret, '^', is used to denote
            the control key, sometimes marked "CTRL", so the CTRL-q key
            combination is written as ^Q.
            The following functions are available in pico (where applicable,
            corresponding function key commands are in parentheses).
    ^X Exit Help                           ^V Next Pg                             
If you do a ^V to move down a page, you should see the start of a complete list of pico commands. One of the first things that will strike you is that pico has a lot fewer commands than vi. This makes pico easier to learn, though less powerful. (Everything comes at a price, you know.) The commands I've found most useful are:
  • The arrow keys, obviously.
  • ^G: Get Help. Because I don't use pico all the time, I don't have all the commands at the tip of my brain (so-called).
  • ^E: End of line. This moves the cursor to the end of the line. It saves a lot of arrowing around.
  • ^A: Star of line. This moves the cursor to the start of the line. Ditto on the arrowing.
  • ^V: Advance the cursor one page.
  • ^Y: Move the cursor back one page.
  • ^L: Refresh the screen. This is useful if the system throws warning messages to your terminal screen.
  • ^W: "Where is". Search forward for text.
  • ^K: Cut text. This removes the current line. If you used the ^^ (control-^) command to select text, then the selected text is removed.
  • ^J: Justify text.
  • ^U: Uncut (aka paste) the cut text. However, immediately after a Justify, it will unjustify instead. (More on this below.)
  • ^R: Insert the contents of an external file at the current cursor position.
  • ^O: Output file. Save the file without exiting pico.
  • ^X: Exit. (You are asked if you want to save or not at this point.)
Most of these are straightforward. It should go without saying that the ^W command searches for plain, case-insensitive text, not for a regular expression; that's why I'm saying it. Again, it's simpler but not as powerful. Using ^J to justify text might take a bit of explanation. Recall the line:
    This is a very long line, with more than the eighty characters that you will no$
In vi, the whole line was printed to the terminal but 'wrapped' around the end of the window. pico shows one line of text, however long, per line in the terminal window. The dollar sign ($) at the end is pico's way to tell you that the line is longer than the width of your window. If you want to see the whole thing you can just use the arrow keys or the ^W command to move along it. If you want to split it into a series of lines, and why wouldn't you, just tell pico to justify the text. Use the arrow keys to move the cursor to the line in question, then hit ^J and ... tada!
    This is a very long line, with more than the eighty characters that you 
    will normally see on the terminal. Notice how it wrapped around?
^J can also be used to piece together fragments of consecutive lines into justified text, which is nice for reformatting a paragraph which you've either added to or taken from.

Also, notice that a message has appeared just above the list of commands on the bottom two lines.

                                 [ Can now UnJustify! ]
    ^G Get Help  ^O WriteOut  ^R Read File ^Y Prev Pg   ^K Cut Text  ^C Cur Pos   
    ^X Exit      ^J Justify   ^W Where is  ^V Next Pg   ^U UnJustify ^T To Spell  
pico will generally print any such messages on this line. Notice that the ^U command is now "Unjustify", not "UnCut Text". This is one place where pico is inconsistent in commands. Upon issuing this Unjustify command, we get:
    This is a very long line, with more than the eighty characters that you will no$
If you are really bored, you can do this all day. You have to be quick about it, though. After justifying the text, if you move your cursor off of the paragraph, ^U returns to "UnCut Text".

So there we have it, a simple, straightforward, easy-to-use command-line editor. In fact, almost the experienced geeks among you may have noticed that many things are in place for writing our own shell scripts. We're not there yet, though; in our next column, we'll look at editing your commands on the command line, using some of the tools we've seen so far.

You are encouraged to send Richard your comments, or to post them below.

Most Recent Mac OS X Command Line 101 Columns

Command Line History & Editing Your Commands
November 22nd

Pico: An Easy To Use Command Line Editor
November 1st

Understanding The "grep" Command In Mac OS X
October 4th

Command Line History & Editing Your Commands
September 6th

Mac OS X Command Line 101 Archives

Back to The Mac Observer For More Mac News!

Richard Burton is a longtime Unix programmer and a handsome brute. He spends his spare time yelling at the television during Colts and Pacers games, writing politically incorrect short stories, and trying to shoot the neighbor's cat (not really) nesting in his garage. He can be seen running roughshod over the TMO forums under the alias tbone1.

Today's Mac Headlines

[Podcast]Podcast - Apple Weekly Report #135: Apple Lawsuits, Banned iPhone Ad, Green MacBook Ad

We also offer Today's News On One Page!

Yesterday's News


[Podcast]Podcast - Mac Geek Gab #178: Batch Permission Changes, Encrypting Follow-up, Re-Enabling AirPort, and GigE speeds

We also offer Yesterday's News On One Page!

Mac Products Guide
New Arrivals
New and updated products added to the Guide.

Hot Deals
Great prices on hot selling Mac products from your favorite Macintosh resellers.

Special Offers
Promotions and offers direct from Macintosh developers and magazines.

Browse the software section for over 17,000 Macintosh applications and software titles.

Over 4,000 peripherals and accessories such as cameras, printers, scanners, keyboards, mice and more.

© All information presented on this site is copyrighted by The Mac Observer except where otherwise noted. No portion of this site may be copied without express written consent. Other sites are invited to link to any aspect of this site provided that all content is presented in its original form and is not placed within another .