Presentation is loading. Please wait.

Presentation is loading. Please wait.

June 1, 1999Vi Editor1 Introduction to UNIX C. Vi Editor.

Similar presentations


Presentation on theme: "June 1, 1999Vi Editor1 Introduction to UNIX C. Vi Editor."— Presentation transcript:

1 June 1, 1999Vi Editor1 Introduction to UNIX C. Vi Editor

2 June 1, 1999Vi Editor2 Overview of vi Performance Objectives 1. Start/End VI (vi, ESC, :wq) 2. Move the Cursor and Window (h,j,k,l, ^f, ^b) 3. Insert, Change, Delete Text (i, a, x, dd) 4. Search and Replace text (/.../, :n, $s/.../.../g) 5. Move/Copy Text (ma, d'a, p) 6. Write and Read Files (:w file, :r file) 7. Tailor the VI Environment (:set)

3 June 1, 1999Vi Editor3 UNIX Family of editors ex line editor ed subset of ex vi screen editor

4 June 1, 1999Vi Editor4 Why learn vi/ex? Available on most UNIX systems. Works with a variety of terminals. Needs no special keyboard definition files. Allows the use of ex commands from vi. Provides for a customized editing environment.

5 June 1, 1999Vi Editor5 Some Conventions vi commands do not require a. vi commands not echoed. ex commands begin with : / ? ex commands are echoed and ended with a The character ^ represents the key.

6 June 1, 1999Vi Editor6 Vi Modes: COMMAND mode n The default mode on entering vi. n Anything typed is interpreted as a command. INSERT mode n Enter INSERT mode by typing one of several commands. n Anything typed is interpreted as data. n Exit INSERT mode by typing the key.

7 June 1, 1999Vi Editor7 Vi Modes UNIX Shell vi filename Command Mode i a o Input Mode ZZ or :wq

8 June 1, 1999Vi Editor8 vi Window Display Line one Line two Line three ~ ~ Line n Command line File text Null lines EX cmd line

9 June 1, 1999Vi Editor9 Vi Window Positioning File vi window ^f Display Next segment

10 June 1, 1999Vi Editor10 Basic Window Positioning Move window forward 32 lines ^f Move window backward 32 lines ^b Move window forward one line ^e Move window to line n of file :n Move window to end of file G Move cursor up/dn left/rt or h j k l

11 June 1, 1999Vi Editor11 Making Changes Permanent vi uses a temp file for changes: Write file and quit editor :wq Undo last command: u or U Recovery: vi -r filename Temp File Perm File :w

12 June 1, 1999Vi Editor12 Insert/Delete Functions Del current line dd Del current char x Insert before current char i... Insert after current char a... Insert after current line o... (opens file at a line)

13 June 1, 1999Vi Editor13 More Vi Functions Open several files vi file1 file2... End editor :q (does not save changes) Redraw screen ^l (L) Join this line with next J

14 June 1, 1999Vi Editor14 Search For a Pattern Search forward to pattern /... / Search backward to pattern ?... ? Advance to next pattern n (forward or reverse)

15 June 1, 1999Vi Editor15 Replace A Pattern Replace string with another :s/.../.../ (only on same line) Replace string (global) :1,$s/.../.../g

16 June 1, 1999Vi Editor16 Moving Text ma mark the starting position with a d'a delete text into a buffer p put buffer contents after cursor Area to be moved ma d’a Insert locationp

17 June 1, 1999Vi Editor17 Copying Text ma mark the starting position with a y'a yank text into a buffer p put buffer contents after cursor Area to be copied ma y’a Insert locationp

18 June 1, 1999Vi Editor18 Writing to a file write current file :w write named file :w filename overwrite named file :w! write lines m - n to named file m,nw file

19 June 1, 1999Vi Editor19 Useful Functions Re-edit current file, discard changes :e Edit named file :e file Read in and insert file at cursor :r file Execute command and return to vi :!cmd

20 June 1, 1999Vi Editor20 Tailoring the Environment For current session :set options Example: :set nu will set line numbers To view possible settings: :set all noautoindent nonumber noslowopen autoprint nonovice tabstop=8 noautowrite nooptimize taglength=0 nobeautify paragraphs= tags=tags /usr/lib/tags directory=/tmp prompt term=vt100 noedcompatible noreadonly noterse noerrorbells redraw timeout flash remap ttytype=vt100 hardtabs=8 report=5 warn noignorecase scroll=11 window=23 nolisp sections= wrapscan nolist shell=/bin/csh wrapmargin=0 magic shiftwidth=8 nowriteany mesg noshowmatch nomodelines noshowmode

21 June 1, 1999Vi Editor21 Order of Evaluation On startup, vi sets options defined by EXINIT variable. Then options defined in ~/.exrc file. Settings in ~/.exrc take precedence. Setting in.exrc file in CWD take precedence over ~/.exrc file and EXINIT. Finally, :set options of current session take precedence during that session.

22 June 1, 1999Vi Editor22 End of Module Complete VI Editor Exercises


Download ppt "June 1, 1999Vi Editor1 Introduction to UNIX C. Vi Editor."

Similar presentations


Ads by Google