Discussion on:

3
Comments

Join the conversation!

Follow via:
RSS
Email Alert
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
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!
Keyboard Shortcuts:
Prev
Next
Toggle
Join the conversation
Formatting +
BB Codes - Note: HTML is not supported in forums
  • [b] Bold [/b]
  • [i] Italic [/i]
  • [u] Underline [/u]
  • [s] Strikethrough [/s]
  • [q] "Quote" [/q]
  • [ol][*] 1. Ordered List [/ol]
  • [ul][*] · Unordered List [/ul]
  • [pre] Preformat [/pre]
  • [quote] "Blockquote" [/quote]

Join the TechRepublic Community and join the conversation! Signing-up is free and quick, Do it now, we want to hear your opinion.