Introduction to UNIX - PowerPoint PPT Presentation

1 / 22
About This Presentation
Title:

Introduction to UNIX

Description:

Introduction to UNIX C. Vi Editor – PowerPoint PPT presentation

Number of Views:100
Avg rating:3.0/5.0
Slides: 23
Provided by: cic120
Category:

less

Transcript and Presenter's Notes

Title: Introduction to UNIX


1
Introduction to UNIX
  • C. Vi Editor

2
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
UNIX Family of editors
  • ex line editor
  • ed subset of ex
  • vi screen editor

4
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
Some Conventions
  • vi commands do not require a ltCRgt.
  • vi commands not echoed.
  • ex commands begin with / ?
  • ex commands are echoed and ended with a ltCRgt
  • The character represents the ltctrlgt key.

6
Vi Modes
  • COMMAND mode
  • The default mode on entering vi.
  • Anything typed is interpreted as a command.
  • INSERT mode
  • Enter INSERT mode by typing one of several
    commands.
  • Anything typed is interpreted as data.
  • Exit INSERT mode by typing the ltESCgt key.

7
Vi Modes
UNIX Shell
vi filename
ZZ or wq
Command Mode
i a o
ltESCgt
Input Mode
8
vi Window Display
Line one Line two Line three Line
n Command line

File text
Null lines
EX cmd line
9
Vi Window Positioning
vi window
f Display Next segment
File
10
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
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

Perm File
Temp File
w
12
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
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
Search For a Pattern
  • Search forward to pattern / ... /
  • Search backward to pattern ? ... ?
  • Advance to next pattern n
    (forward or reverse)

15
Replace A Pattern
  • Replace string with another s/.../.../
    (only on same line)
  • Replace string (global) 1,s/.../.../g

16
Moving Text
  • ma mark the starting position with a
  • d'a delete text into a buffer
  • p put buffer contents after cursor

ma
Area to be moved
da
Insert location
p
17
Copying Text
  • ma mark the starting position with a
  • y'a yank text into a buffer
  • p put buffer contents after cursor

ma
Area to be copied
ya
Insert location
p
18
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
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
Tailoring the Environment
  • For current session set optionsltcrgt
  • Example set nu ltcrgt will set line numbers
  • To view possible settings
  • set all
  • noautoindent nonumber noslowopen
  • autoprint nonovice tabstop8
  • noautowrite nooptimize
    taglength0
  • nobeautify paragraphs tagstags
    /usr/lib/tags
  • directory/tmp prompt termvt100
  • noedcompatible noreadonly noterse
  • noerrorbells redraw timeout
  • flash remap
    ttytypevt100
  • hardtabs8 report5 warn
  • noignorecase scroll11 window23
  • nolisp sections wrapscan
  • nolist shell/bin/csh
    wrapmargin0
  • magic shiftwidth8 nowriteany
  • mesg noshowmatch
  • nomodelines noshowmode

21
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
End of Module
Complete VI Editor Exercises
Write a Comment
User Comments (0)
About PowerShow.com