VI Editor

You might also like

You are on page 1of 12

UNIX Text Editors

Editor Concepts
Editing creating a new file and modifying an existing text file. An editor a utility that makes the editing task possible. A text editor differs from a word processor in that it does not perform text formatting, such as bold, center, underline, etc. A line editor a utility that applies changes to a line or group of lines; two common line editors: ex and sed. A screen editor shows a whole screen of text at a time; we can move cursor or select part of text, search for text, etc.
2

The Vi Editor
A screen editor available on most UNIX systems. When invoked, it copies the contents of a file to a memory space know as a work buffer. All editing are applied to the contents in the work buffer. If the file does not exist, an empty buffer is created. When we exit vi, the work buffer is erased. At exit time, we can do two things:
1. Quit without saving the original contents remain unchanged. 2. Save the file the original contents are replaced by the new version in the work buffer.
3

Vi Buffers
Work Buffer
This is where vi performs all editing Vi makes a copy of your file in the work buffer Makes all changes to the copied version Replaces original copy with edited copy when you save (:w)

General Purpose Buffer


Stores recent deleted, or copied text Used by the undo command to restore text

Name Buffers
26 named buffers, each named by a letter of the alphabet Used to store a different block of text to recall later
4

The UNIX vi Text Editor

Command Mode

Esc

Input Mode

Return

Insert (i, I) Append (a, A), Open (o, O) Change (c), Replace (r, R)

Last-Line Mode
5

Vi Mode
In vi, to find out what mode you are in, you need to create a vi start-up file (.exrc) In your home directory or in your cwd directory, create .exrc file with contents:
set showmode

File Names
When naming a file, avoid the following characters:
& $ Space * <> Tab \ () ; | # ^ [] ? ! {} / ~

Commonly Used File Extensions


Extension .a .c .cc .csh .f .sh .bsh .ksh File Type An archive or library C program source C++ program source C shell script FORTRAN program source Bourne shell script Bash shell script Korn Shell script
8

Commonly Used File Extensions


Extension .o .ps .shar .tar .txt .Z File Type Object file of compiled program Postscript source Shell archive Tar archive ASCII text file Compressed file

Recovering Text After a Crash


If the system crashes while you are editing a file using vi, you may be able to recover your text The system sends you an e-mail telling you how to recover your file To recover a file after a system crash:
% vi r filename

10

UNIX Text Editor to Use


Which UNIX text editor should you use for CSCI330 ?
You have the option to use either vi or pico for this class Summary of vi commands
See Course Notes pp. xx-14 through xx-16

11

Vi tutorial
To run vi tutorial session, execute the following command at the command prompt:
/usr/local/bin/vimtutor

To end vi tutorial in the middle of the session, execute the command:


:q

12

You might also like