CS 497C - PowerPoint PPT Presentation

1 / 8
About This Presentation
Title:

CS 497C

Description:

CS 497C Introduction to UNIX Lecture 10: The vi/vim Editor Chin-Chih Chang chang_at_cs.twsu.edu String Search vi supports two forms of searches: Search for a string ... – PowerPoint PPT presentation

Number of Views:46
Avg rating:3.0/5.0
Slides: 9
Provided by: Kindy
Category:
Tags: 497c

less

Transcript and Presenter's Notes

Title: CS 497C


1
CS 497C Introduction to UNIXLecture 10 The
vi/vim Editor
  • Chin-Chih Changchang_at_cs.twsu.edu

2
String Search
  • vi supports two forms of searches
  • Search for a string or a regular expression in
    the entire file.
  • Search for a single character in the current
    line.
  • Search commands in vi
  • /str searches forward for pattern str.
  • ?str searches backward for pattern str.
  • n repeats search in the same direction.
  • N repeats search in the opposite direction.
  • fch moves cursor forward to first occurrence of
    character ch in the current line.

3
String Search
  • Fch moves cursor backward to first occurrence
    of character ch in the current line.
  • tch moves cursor forward onto but before first
    occurrence of character ch in the current line.
  • Tch moves cursor backward onto but before first
    occurrence of character ch in the current line.
  • - repeats search in the same direction made
    with f, F, t, or T.
  • , - repeats search in a direction opposite to
    that made with f, F, t, or T.

4
Searching with Regular Expressions
  • vi accepts a generalized pattern containing some
    special characters (metacharacters) as the search
    expression.
  • This pattern is called a regular expression and
    is used to match a group of similar strings.
  • The regular expression characters used by vi

5
Searching with Regular Expressions
  • - matches zero or more occurrences of the
    previous character.
  • pqr matches a single character which is
    either a p, q, or r.
  • pqr matches a single character which is not
    a p, q, or r.
  • . matches a single character.
  • pat matches pattern pat at beginning of line.
  • \ltpat matches pattern pat at beginning of a
    word.
  • pat\gt - matches pattern pat at end of a word.

6
Search and Replace (s)
  • Search and replace commands in vi
  • n1,n2s/s1/s2 replaces first occurrence of
    string or regular expression s1 with string s2 in
    lines n1 to n2.
  • 1,10s/find/look/g replaces all occurrences of
    find with look in lines 1 to 10.
  • .,s/find/look/gc interactively replaces find
    with look from current line through the end.
  • s repeats the last substitution on the current
    line (Linux only).

7
Handling Multiple Files
  • vi uses the Last Line Mode to handle multiple
    files and buffers.
  • These are advanced file handling commands
  • r note reads file note below current line.
  • r !date reads output of date between current
    line.
  • e note stops editing current fine, and edits
    file note.
  • e! note stops editing, but after abandoning
    changes made to current file.

8
Handling Multiple Files
  • e! loads last saved edition of current file.
  • Ctrl- returns to most recently edited file.
  • e returns to most recently edited file.
  • n edits next file (when vi is invoked with
    multiple filenames).
  • rew rewinds file list to start editing first
    file (when vi is invoked with multiple
    filenames).
  • You can split the screen into multiple windows in
    vim.
  • sp splits the window.
  • Ctrl-wCtrl-w moves between windows.
Write a Comment
User Comments (0)
About PowerShow.com