Join David D. Levine for an in-depth discussion in this video Searching and replacing text, part of Learning vi.
…Now, we'll talk about search and replace.…Search and replace in VI is a little bit more complicated.…Search and replace in VI uses a colon command, :s.…The way that you specify a search and…replace is you type colon s, a slash, the old string that you're looking for,…another slash, the new string that you want to replace it with, and…then a final slash to end the command, then you enter return to execute it.…That command :s/ old / new / replaces the first occurrence of…the string old on the current line with new.…
If you want to replace all occurrences of old with new on the current line,…you append a g after the closing slash, :s / old / new.…If you want to make that search and replace on every line of the file,…you put a percent sign between the colon and the s, :%s/ old / new /,…that replaces the first occurrence of old with new on every line of the file.…You can combine both of those options, :%s/ old / new,…replaces every occurrence of old, with new, on every line of the file.…
Now here's a few notes about this.…
AuthorDavid D. Levine
- Entering and leaving vi
- Understanding the Command, Insert, and Colon modes
- Moving around in files
- Editing text
- Moving content with delete, yank, and put
- Searching with regular expressions
- Customizing vi
- Filtering text through shell commands
Skill Level Beginner
1. Exploring vi
What is vi?2m 26s
2. Getting Started with vi
3. Moving Around within a File
4. Basic Text Editing
5. Undo, Repeat, Yank, and Put
6. Search and Replace
7. Advanced Editing Features
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.