next up previous
Next: Copying, moving and removing Up: Lab 1: UNIX, Editors, Previous: A

Editors (15 minutes)

This section will discuss several editors that are available in UNIX. We start with two editors, emacs and xemacs working under X-Windows. Be sure the current directory is lab1 in subdirectory cs241. Type

emacs temp1

Emacs is the name of the editor and temp1 is the name of the file to be edited. The editor opens in a new window and the window with emacs command becomes disabled. You will learn how to fix this problem shortly, but for now, enter few lines of text in emacs. Once the file temp1 is finished, it has to be saved. Like with Notepad under Windows95/98 click 'File' in the menu, then 'Save buffer', again 'File' and 'exit'.

To use emacs editor and still have all other windows available for work, type

emacs temp1 &

& "runs your emacs editor in the background". Now you may use both windows: the editor and the window where you originally typed the command. & can be applied to other X-Windows applications such as Netscape. In the recommended book, 'Unix in a nutschell', chapter 7 covers emacs editor with detailed description of all its internal commands.

Another X-Windows editor is xemacs which differs from emacs by buttons similar to Windows95 applications. Type:

xemacs temp1 &

One should be also familiar with editors not based on X-Windows. They can be handy for work from home. When the network at school is busy they may be faster. Pico and vi are two such editors.

Type

pico temp2

Pico opens no additional window. Do not use & because it runs pico in background and the application becomes unavailable! Pico has a menu at the bottom, which makes the use very straightforward. Enter few characters and save and close the file. As you can see on the bottom, CTRL X will do the work.

vi is a powerful, but not user-friendly editor. It is fully described in ch. 8 of Unix in a Nutshell.

To create and edit a file called temp3 using vi editor, type

vi temp3

Nearly each key on the keyboard triggers an action in the editor, hence, do not push any keys without knowing their meaning. Once the vi editor is open, we are in the so called 'command mode'. The editor resists any typing until the `insert mode' is entered, for example, by hitting the `i' key. Hit 'i', switch into the insert mode and enter a new text in the file. Once you are done, use ESC key to exit the insert mode and return into the command mode. To save changes and quit the editor type

:wq (enter)

Many UNIX applications use vi by default. Hence, in Labs we will use vi editor mainly.


next up previous
Next: Copying, moving and removing Up: Lab 1: UNIX, Editors, Previous: A
Instructional Support Group 2008-08-05