Discussion on:
View:
Show:
Search and replace is one of the first things a vi user ends up butting his or her head against, and every tutorial I ever saw waits to discuss it as an advanced subject IF AT ALL! You might want to touch on this in another article...
Actually, it's not that difficult... the following string will replace the first occurrence of foo with bar on the current line: :s/foo/bar
To replace all occurrences of foo with bar on the current line: :s/foo/bar/g
To replace foo with bar globally in the document: :%s/foo/bar/g
To replace foo with bar in lines 5 through 25: :5,25s/foo/bar/g
vi is a HECKUVA powerful editor. Just as with anything else, it takes time and practice to harness its power.
Cheers!
Steve
To replace all occurrences of foo with bar on the current line: :s/foo/bar/g
To replace foo with bar globally in the document: :%s/foo/bar/g
To replace foo with bar in lines 5 through 25: :5,25s/foo/bar/g
vi is a HECKUVA powerful editor. Just as with anything else, it takes time and practice to harness its power.
Cheers!
Steve
Just to qualify...
My remarks I *know* work in Solaris. Other flavors of UNIX may vary, although I have also done this in HP-UX...
Cheers!
My remarks I *know* work in Solaris. Other flavors of UNIX may vary, although I have also done this in HP-UX...
Cheers!
- Keyboard Shortcuts:
- Prev
- Next
- Toggle









































