Pico --- My First Unix Editor

Pico is the most user friendly unix editor that I've ever come across in unix. Almost everything is so intuitive in pico. As compared to editors like vi or emacs, even exiting from the editor itself involves a combination of a few keys. The topics that I'm covering here are as below:

Writing to a file in pico
Saving in pico
Cutting and pasting in pico
Searching in pico
Using '+n' option in pico
Enabling suspension mode in pico
Reading a file in pico
Using mouse in pico
Using spell check in pico
Setting the right margin in pico
Justifying tabs or spaces in pico
Viewing your pico-ed file when the system crashes
Highlighting in pico
Moving your cursor to the next word in pico
Moving to the first line and last line of a file in pico
Disabling word wrap in pico
Finding the cursor position in pico
Finding online help in pico

Pico


   UW PICO(tm) 2.9                New Buffer





















^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


Writing to a file in pico

To help us in warming up, I've decided to include this writing of file inside this mini-howto. We just need to type pico filename where filename is the actual filename of the file you want to create.

ie:
lukmengs@sununx~ $ pico helloworld

And you are ready to edit your file. Alternatively, you can just type pico in the command line, press Ctrl-R followed by the name of the file you want to edit.

i.e:

  UW PICO(tm) 2.9                         New Buffer








File to insert from home directory: test.c
^G Get Help     ^T To Files
^C Cancel

Return to top


Saving in pico

Saving in pico can be done with or without exiting pico. The latter is often known as writing to a file while I don't know what's the formal name for the former.

To write to a file (saving without exiting pico), we do a Ctrl-O and press "Y" when being prompted to save. The purpose of doing this is to ensure that when you are typing a long document, you can save your work several times without exiting the editor.

On the other hand, to save and exit pico, we do a Ctrl-X and press a "Y" when being prompted to save.

Return to top


Cutting and pasting in pico

I regret to say that I don't know how to do a copy and paste for pico. The closest to that I know of is a cut and paste by a Ctrl-K to cut and Ctrl-V to paste.

To do a "multiple" cut and paste, just do as many times "cut" you want and paste it.

ie: To cut the 3 lines below and paste them twice.

   This is a car.
   This is a car.
   This is a car.

Go to the first line, press Ctrl-K 3 times and do a Ctrl-U twice. You should get the output as below.

   This is a car.
   This is a car.
   This is a car.
   This is a car.
   This is a car.
   This is a car.

Return to top


Searching in pico

To do a search in pico, press Ctrl-W to activate the "where-is" function in pico. Next, you will be prompted for the word you are looking for and simply supply the word will do.

To do a search repeatedly, just do a Ctrl-W and press "Enter". Do note that the search is case-INsensitive here. =)

Return to top


Using '+n' option in pico

The '+n' in this context means to go to the line 'n' where n is the line number where you want to go. This is very useful for debugging complilation error when coding a program. Please take note that following is done at command line.

ie: Complier complains that a parse error occurs in line 10.

lukmengs@sf3:~[17]> gcc test.c
test.c: In function `main':
test.c:10: parse error before `:'
lukmengs@sf3:~[18]> pico +10 test.c

This would bring you to:

#include <stdio.h>

main ()
{
   char c;
   int a = 0;

   printf ("Please enter a character: ");
   scanf ("%c", &c);
   printf ("\n"):

   if (c == 'y') printf ("Thanks\n");
   else printf ("Please follow the instuction closely\n");
}





              [ line 10 of 15 (66%), character 114 of 232 (49%) ]

Return to top


Enabling suspension mode in pico

Suspension of a process comes in handy especially when you are writing some programs that needs only interpretation. To enable suspension in pico, you will supply the 'z' option in command line.

ie:
lukmengs@sununx~ $ pico -z helloworld.lsp

By doing that, the Ctrl-Z suspension signal will work when you are editing your file in pico. To bring the pico-ing back, you need to type fg in the command prompt.

Return to top


Reading a file in pico

Reading a file in unix can be done by opening a file while enabling the 'readonly' flag. The purpose of enabling the 'readonly' flag is to ensure that nothing is accidentally being edited during the inspection of the file. This is done by supplying the argument 'v' in the command line.

ie:
lukmengs@sununx~ $ pico -v helloworld

After doing so, you can then make use of the functionalities in pico to help you to do a search, showing the number of lines and so-on.

Return to top


Using mouse in pico

Enabling of the mouse can only be done in X environment such as a X-Window only. For the benefit of those who do not know how to configure the X-Window, you can refer to https://www.comp.nus.edu.sg/cf/x/index.html for details. Simply type pico -m in the command prompt in the X-window will enable your mouse in it.

Return to top


Using spell check in pico

Although I personally feel that the spell check in pico is not as good as that of the Microsoft Word Processor, but it does give me some convenience in editing.

ie:

This is a ca
This is a ca
This is a ca

Let "ca" be the mispelled word for "car" in the aboved example. Press Ctrl-T for a spell check and type "car" to replace the "ca". Eventually, pico will prompt you to replace the remaining of the "ca".

This is a car
This is a car
This is a car

Return to top


Setting the right margin in pico

This can be done by supplying the rn where n is the margin number you want to set. Margin number here simply means the number of words that you want it to be.

ie: I want to set the right margin to 72 words, in the command prompt, i type

lukmengs@sununx~ $ pico -r72 helloworld

Return to top


Justifying tabs or spaces in pico

Sometimes when we have ftped a file from windows to unix, the indentation of the file may goes wrong because of the difference in the tabs set in the windows editor and pico. One of the way to solve this problem is to remove the tabs or spaces by using the command "justify" in pico by Ctrl-J.

Return to top


Viewing your pico-ed file when the system crashes

Sometimes when we do our work in unix, our telnet session may crash due to some reasons. Pico will save your file as ".filename.save" whenever this happens while you are pico-ing your file. To recover the file you have edited earlier on, simply do a "pico .filename.save" while filename is the name of your file.

Return to top


Highlighting in pico

Highlighting comes in handy if you want to select a section of text for copying and pasting. The key combination to do a highlite is Ctrl-Shift-^. You can move your arrow keys and get ready to perform operations like deletion and copying on this section of text.

i.e:

Besides the command "man pico", you can always do a Ctrl-G whenever you
are in doubt. The difference is that the former explains to you what
arguments pico takes in the command line whereas the latter explains
commands such as "Ctrl-W" in more details 

Welcome to the Unix section of my web-page. I've always encountered
numerous amount of problems when I was a freshman in School of

Return to top


Moving your cursor to the next word in pico

You can move your cursor to the next word by press Ctrl-<Spacebar>.

Return to top


Moving to the first line and last line of a file in pico

To move to the first line, press Ctrl-W Ctrl-Y.
To move to the last line, press Ctrl-W Ctrl-V.

Return to top


Disabling word-wrap in pico

The ugliest thing in pico is that you'll get a '$' (and some lines appear below that '$' but they are actually supposed to be on the same line as '$') whenever your line exceeds the buffer of the screen. This may hinder you from editing adversely.

What I would recommend you to do is to supply the option '-w' to pico.

lukmengs@sununx~ $ pico -w helloworld

Do note that several arguments can be supplied to pico at the same time.
For instance, you might like to do this:

lukmengs@sununx~ $ alias pico='pico -w -m -z -r72'

Then put this alias into your ~/.profile and run it by ". ~/.profile".

return to top


Finding the cursor position in pico

This is useful if you are editing a large file. The combination key to do this is a Ctrl-C.

return to top


finding online help in pico

Besides the command "man pico", you can always do a ctrl-g whenever you are in doubt. the difference is that the former explains to you what arguments pico takes in the command line whereas the latter explains commands such as "ctrl-w" in more details.

return to top



Do take note of the following shorthands:

Ctrl-A: move the cursor to the beginning of a line
Ctrl-E: move the cursor to the end of a line.
Ctrl-Space: move the cursor to the next word.

Hosted by www.Geocities.ws

1