1 / 8

CS 497C – Introduction to UNIX Lecture 10: The vi/vim Editor

CS 497C – Introduction to UNIX Lecture 10: The vi/vim Editor. Chin-Chih Chang chang@cs.twsu.edu. 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 :

Download Presentation

CS 497C – Introduction to UNIX Lecture 10: The vi/vim Editor

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS 497C – Introduction to UNIXLecture 10: The vi/vim Editor Chin-Chih Changchang@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. • \<pat – matches pattern pat at beginning of a word. • pat\> - 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-w][Ctrl-w] – moves between windows.

More Related