Unix 101: pico Editor

Pico is a file editor used on Unix systems. It comes with pine, where it is used by default to compose new messages, but it can also be used as a stand-alone editor. It is invoked by the command pico filename, where filename is replaced with the name of your file.

Editing commands are invoked by control key sequences (i.e. pressing the control key together with another key.*) Several menu-like status lines at the bottom of the screen show which commands are active at any given time. Key strokes that do not constitute control key sequences are entered as text at the current cursor position.

Cursor movement

You can move your cursor by using the arrow keys; you may also use any of the following editing commands:
 

Ctrl-a Beginning of current line
Ctrl-e End of current line
Ctrl-v Forward one screen
Ctrl-y Backward one screen
Ctrl-f Forward a character
Ctrl-b Backward a character
Ctrl-p Previous line
Ctrl-n Next line

Saving a file

You can save the file you are working on by using the Ctrl-o (write out) command. If you exit Pico by using the Ctrl-x (exit) command, you will be given a chance to save the file.

Deleting text

Ctrl-d Delete the character the cursor is on
Ctrl-e Delete to end of current line
Ctrl-k Delete the line the cursor is on
Ctrl-u Restore the last line that was deleted

Cutting and pasting

You can mark text for cutting and pasting by using the Ctrl-^ command. After entering this command, move the cursor to highlight the text you wish to cut. Use Ctrl-k (Cut) to cut the text. Then use Ctrl-u (Uncut) to paste it.

Searching

You can search for a given text by using the Ctrl-w command. The search is NOT case sensitive. After entering the command, you will be prompted for the text for which you want to search. If you press Enter at this point, Pico will repeat the last search. All searches start at the current cursor position and wrap around to the beginning of the file.

To move to the last line in the file, type Ctrl-w (where is), Ctrl-v (last line). To move to the first line of the file type Ctrl-w (Whereis), Ctrl-y (first line).

Justifying text

The justify command, Ctrl-j, will remove extra white space and new lines to make lines as equal in length as possible. It operates on the paragraph where the cursor is currently positioned. Pico defines a paragraph as text separated by a blank line or a line starting with a blank or tab.

By default, Pico 'wraps' lines at 80 characters. It will not break text in the middle of a word, however, but will go back to the most previous white space. This default can be overridden by starting Pico with the -w option. When this is in effect, lines too long to be displayed on the screen will have a '$' in the column furthest to the right.

Spell checking

Pico includes an spell check function which can be invoked with Ctrl-t. It will flag words it cannot find and give you a chance to edit them, but will not suggest a correct spelling or allow you to customize the dictionary. You can also use ispell, a more sophisticated spell checker, on any file. At the command prompt, type ispell filename , where "filename" is the name of the file you want to spell check.

Help

Online help is available with the Ctrl-g (help) command. It invokes a short but fairly complete document that you can page through. The command line options are discussed more thoroughly in the man page. To see the man page for Pico, enter man pico at the command prompt.

Command line options

The following command line options are available for use when Pico is invoked (e.g. pico -w filename):

-w Disables word wrapping
+x (x is an integer) Starts the cursor x lines into the buffer
-nx (x is an integer) Checks your mailbox every x seconds and notifies you if you have new mail.

Miscellaneous

Ctrl-c will report the current cursor position in the buffer by both line number and character at the bottom of the screen.

Read a file into pico with Ctrl-r and write one from pico with Ctrl-o. After either of these commands, you can enter Ctrl-t (list files) to invoke the file browser. The file browser will allow you to step through the directory structure, see a listing of all files in a given directory, copy files, rename files, and delete files.

pico or vi

Pico may seem easier to start, and I guess it is, but if you're going to be using Unix much, in the long run you'll probably want to learn vi.

Last updated: 

September 26, 2012