Return to Manual Contents Astronomy Computer Manual

Editors

vi: Introduction
vi: Inserting Text
vi: Changing Text
vi: Deleting Text
vi: Moving Around
vi: Undoing Mistakes
emacs: Introduction
emacs: Basics
emacs: Editing
Emacs Reference Card

vi: Introduction

The editor, vi has two modes of operation: command mode and the insert mode. In the command mode you can move the cursor around the text, and make changes to existing text. To enter new text you must use the insert mode. You can get into insert mode with the I or i (insert), A or a (append), and O or o (open) commands. To exit from the insert mode hit the ESC (escape) key.

To edit a file type vi filename If you are creating a new file, then use the same format. The screen will then clear and at the bottom of the screen there will be the status line:

``filename'' [new file]

Top of Page

vi: Inserting Text

As stated before type an a while in 'vi' to insert text. The a will not appear on the screen for it is an instruction to 'vi'. When you are finished writing text hit the ESC key to exit the insert mode. If you would like to save your work, so that when you access the file again the text you added will still be there, type :w . To quit the 'vi' program type :q . You cannot exit 'vi' after making changes with just a :q , you must type :w first. If for some reason you wish not to save the addition to your file, type :q! . This command tells 'vi' to exit without making any changes to the file.

Top of Page

vi: Changing Text

There are several commands for changing a portion of the text at a time. You must be in ESC mode to do this. The most common are:

s to substitute the character under the cursor by any number of characters.
cw to substitute a string for the portion of a word under and after the cursor.
cc to change an entire line, substituting it with a string that you type.

For each one of these commands you must type ESC when you have finished making the changes.

Top of Page

vi: Deleting Text

To delete text there are three basic commands:

x to delete the character under the cursor
dw to delete the portion of a word under the cursor and to the right of it.
dd to delete the line that the cursor is on.

Top of Page

vi: Moving Around

If you wish to move around the text of a file you may use the arrow keys or the keys h,j,k and l. They correspond to the directions left, down, up and right respectively.

An easy way to move around in the file is to use cntl-D (^D) which moves the cursor down half the screen and cntl-U (^U) which moves the cursor up half the screen. Note, when a key is coupled with the control key it does not matter which case you type the key in. ^F and ^B will move forward or backward a screen (respectively).

Another way to position yourself in the file is to give 'vi' a string to look for. Type a / followed by the string and a [return]. 'vi' will position the cursor at the first occurrence of the string. If you want to go to the next occurrence type n If you want to go in the reverse order, type N

If your screen and cursor location become scrambled, or someone sends you a message in the middle of it, use ^L to redraw the screen.

Top of Page

vi: Undoing Mistakes

If you execute a command you wish you hadn't, 'vi' provides a command to undo the last change you made: just type u The undo command only lets you reverse a single change. To restore a complete line type U this will only work if you do not move off the line.

To get a basic idea of how to run the editor see the manual ``Getting Started with Unix: Beginner's Guide''. 'vi' has a vast number of commands. The man pages or the ``Command Reference Manual'' will help you with more advanced items.

Top of Page

emacs: Introduction

Emacs is very different from vi. It has an extensive interactive help facility and works well under an X environment. Various commands are entered using Control (^) and Escape sequences.

Top of Page

emacs: Basics

To begin emacs, type emacs filename There are many options that can go with emacs, especially with respect to the X window environment. Man pages will explain these options. You can begin to enter text just by typing. Arrow keys will move you around: up and down one line, and left and right by one character. To save a file and exit emacs, type ^x^c and answer y to save the file.

To invoke the on-line help type ^h and for an on-line tutorial type ^h t

Top of Page

emacs: Editing

Here are some basic editing commands: To delete the character before the cursor use the DEL key. To delete the character under the cursor, use ^d To delete a word use ESC-DEL and ESC d for backwards and forwards respectively. Use ^k to delete to the end of the line. A ^y will ``yank'' back the last thing deleted.

If you want to replace a text string (ie. search and replace) use ESC % You will be prompted to type the string you want replaced, and what to replace it with. Emacs will then search for the string to replace and will prompt you to take an action, ie. press the space bar to replace it and go on to the next, press DEL to skip this one and go on to the next, or ! to replace all remaining matches.

Top of Page

Emacs Reference Card

The Emacs Reference Card, which is supplied with this manual, gives many more commands, whose use should now be self evident. Click for the emacs reference card

Top of Page