Appendix 12.


A 12.0 Introduction

At the writing of a computer program an editor and not a word processor should be used. The difference is that the word processor can use different fonts in the text, and therefore has to add some control information into the file. Most word processors can however, as an alternative, also produce an output file in pure ASCII (pure typewriter text) without this control information, an can therefore be used at the editing of program files.

Usually it is much simpler to use an editor for the creation of a computer program.

A 12.1 Emacs

Within different computer systems there are various traditions with respect to the choice of editor. Among the screen oriented editors in the academic community Emacs has become very popular. It exists in many different versions and for most computer systems. A simplified version for VAX/VMS is AMIS and for MS-DOS there are Epsilon and Micro-Emacs and many others.

At the use of EMACS it is preferably to use an existing emacs-window, or to create a new one with emacs or xemacs.

Useful Emacs-commands

        Control-f      one step forward (to the right)
        Control-b      one step backward (to the left)
        Control-p      one step up
        Control-n      one step down
The arrow keys can also be used for the above operations. Sometimes you can also move to the position of the mouse through clicking.
        Control-v      next page
        'Esc' v        previous page
        Control-a      go to the beginning of the present line
        Control-e      go to the end of the present line
        'Esc' <        go to the beginning of the file
        'Esc' >        go to the end of the file
        Control-d      remove the character
        Control-k      remove the rest of the line
        Control-y      restore what was removed with the latest Control-k
        Control-s      search forwards
        Control-r      search backwards
        Control-x Control-f   switch to the file with the given name
        Control-x Control-s   save the file using the old name
        Control-x Control-w   save the file using the given name
        Control-x Control-c   exit from EMACS (normally not used 
                              in connection with X-Windows)
        Control-g      sounds and cancels incorrect commands
                       (sometime two Control-g are required). 
                       Used when you have done a mistake!
Remark 1. 'Esc' (Escape) is a key which should be pressed before the next key, while Control- is the key marked CTRL or Control, this key should be pressed while the next key is pressed.

Remark 2. Emacs does not work well together with telnet and some communication equipment from Digital Equipment. One problem is that Digital interprets Control-s as a stop-character, which can be canceled by a Control-q. In order to save a file it is therefore necessary to give Control-x Control-w and the file name. For search it is necessary to first go to the end of the file with 'Esc' > and then search backwards with Control-r. Sometimes not even Control-x works, then it is time to use another editor.

Remark 3. At compilation some errors are reported to occur on a certain line, with Emacs you can go directly to that line with the command 'Esc' X goto-line, and then give the line number.


This a very simple screen oriented editor which is part of MS-DOS. I (Bo Einarsson) have found it quite useful, but its documentation is awful, at least for the Swedish version, which is the only one I have had access to.

The following is therefore based on the Swedish version.

If you wish to edit (or create) the file program.f90 you write

        C:\> edit program.f90 
You exit without saving with ALT A A, and with saving with ALT A S, that is you first press the ALT key and then twice the A key, or once the A key and once the S key. MS-DOS EDIT has reasonable features for replacing one character string with another.

When the program is started a menu line appears on the top with the following alternatives

        Arkiv       Redigera      Sök       alternatiV
You get to the selected alternative through pressing the ALT key followed by pressing the indicated letter (A, R, S or V). From Arkiv you can select Open, Save, Print, and Exit. From Redigera you can Cut, Paste, and Remove. From Sök you can Search and Replace, and from alternatiV you can change the display parameters and get help. As usual it is advantageous if you have the mouse installed also under MS-DOS, then you can click on the selected alternative.

It is very simple to input the text directly into the main window. A help line is available at the bottom.

A 12.3 UNIX ex

The very primitive line oriented editor "ex" does not require any fancy communication, and it is therefore useful if you have a connection which does not support windows. It uses the following very simple commands.
a       add new lines (for example when creating a new file)
        (ended with a single dot . first on the last line)
i       add new lines
        (ended with a single dot . first on the last line)
d       delete a whole line
w       write (save) the file
q       exit the editor
With giving the number of a certain line you are moved to that line, which is echoed.

A 12.4 UNIX vi

This is an extension of "ex" which requires that the correct terminal type is set, and it uses the following simple commands. In addition the arrow keys work for moving the cursor. On entry you are in the command mode.
ESCAPE      Switch to the command mode
a           Switch to text mode for input of new text directly after the
            present position
i           Switch to text mode for input of new text directly at the
            present position
dd          Remove a line (both to the left and to the right of the
	    present position, that is a complete line
x           Remove a character
:wq<CR>     Save the file and leave the editor
:q!<CR>     Exit the editor without saving any changes
Please note that when you give ESCAPE the cursor usually moves one step! The notation <CR> above means that you have to give a Carriage return or ENTER here.

Last modified: 19 September 1997