Using The Pico Text Editor


There are several text editors available on most Unix systems: vi, pico, and Emacs. This chapter covers the use of the pico editor. Pico is a simple text editor while vi and Emacs are more powerful. You will need to use some text editor when working on a Unix system; the choice is yours.


Getting Started

Pico is a simple editor to learn and use. It is a general purpose editor that was designed for use with any type of terminal. Therefore, it is limited in what it can do. While some terminals allow the use of the arrow, function and keypad keys, others do not. Thus, you will need to learn several key sequences which control the editing process. To start Pico, enter

   pico filename
at the command-line prompt, where filename is the name of the file you wish to edit. The terminal will look similar to that in Figure 1. The pico screen contains three parts. The top line or header line indicates which file you are currently editing and whether the file has been modified. The bottom two lines contain some of the more common key sequences and corresponding commands. The area between these two parts is the buffer or editing area.


Figure 1.  The pico editor.


Most key sequences used by pico require the use of the control Ctrl prefix key. On the pico screen, the control key will be indicated by a ^ (carrot). When you see a key sequence similar to Ctrl-a, it means to hold down the Ctrl key and then press a.


Basic Editing

Pico is a full screen text editor like Emacs, and Microsoft's (tm) notepad. Like Emacs, pico uses key sequences to move the cursor, perform block commands, and other common operations. The major difference between pico and other full screen editors is that the mouse can not be used with pico. This section describes the commands and corresponding key sequences for the basic editing operations.


Moving Around

While pico is a full screen editor, the movement of the cursor is limited to the area where text (including blanks) currently exists. Thus, you can not move the cursor to the right hand side of the screen unless there is text or blanks in that area.

On many terminals, the arrow keys will move the cursor around the editing area. On others, you will have to use the indicated key sequences.

Key(s) Operation
Ctrl-b or left move back 1 character
Ctrl-f or right move forward 1 character
Ctrl-p move up 1 line
Ctrl-n move down 1 line
Ctrl-y or PgUp move to prev page
Ctrl-v or PgDn move to next page
Ctrl-a beginning of line
Ctrl-e end of line
Ctrl-w Ctrl-y top of file
Ctrl-w Ctrl-v bottom of file


File Operations

Pico only provides two file operations: (1) save the contents of the editor to a file, and (2) insert the contents of a file at the current cursor position. The associated key sequences for these two commands are shown below

Key(s) Operation
Ctrl-o save buffer to a file
Ctrl-r insert contents of a file

Load a New File..  If you want to load a new file into the editor, then you must exit the editor and then restart it indicating the new file.

Renaming the File..  You can save the contents of the buffer to a file with a different name from the one you loaded. Each time you save the file Ctrl-o, you are prompted for the name of the file as illustrated in Figure 2. Thus, change the name of the file at this prompt to save it to a file with a different name. If you want to save it to the same file, simply press Enter.


Figure 2.  Pico prompt when saving a file.


Cancelling an Action..  In most instances, you can cancel the current action by pressing Ctrl-c. The key sequence to cancel an operation will always be displayed at the bottom of the screen.

Browse Directory..  Pico allows you to traverse your directory to find a particular file or to change the directory. You are offered the opportunity to browse your directory when performing a file operation. Look at the list of operations and key sequences provided at the bottom of the screen to activate this option.


Text Manipulation

To insert characters into the editor, simply press the key of the desired key. This is no different from most other editors. Pico also allows you to perform several other manipulation operations as outlined below

Key(s) Operation
Ctrl-k delete the current line
Ctrl-u paste last cut at current position
Ctrl-d delete current character

Pico allows you to format a paragraph by readjusting line breaks so the text in the current paragraph will fit across the entire screen. This is performed by placing the cursor in the paragraph (delimited by blank lines) that you wish to format and pressing Ctrl-j. You can unjustify a paragraph by pressing Ctrl-u.


Block Operations

Pico allows you to delete or cut a region or block of text. You must first mark the text and then cut it. To cut a block of text, perform the following steps

  1. Move the cursor to the beginning of the region and press Ctrl-6.
  2. Move the cursor to the end of the region.
  3. Press Ctrl-k. If you change your mind, you can cancel the operation by pressing Ctrl-c.

Pasting..  You can paste the contents of the region that were cut as outlined above by moving the cursor to the position where the text is to be pasted and pressing Ctrl-u.

Copying a Region..  To copy a region of text from one part of the file to another, you will need to cut the region and then paste it to the new position.


Miscellaneous Commands

Pico provides several other commands and options like spell checking, searching and online help. Each of the remaining commands are listed in the following table.

Key(s) Operation
Ctrl-x exit the editor
Ctrl-g get help
Ctrl-t spell check the buffer
Ctrl-w search for a string of text
Ctrl-c show current line number
Ctrl-l refresh the display