[Novalug] vi question
Jon Sime
jsime at mediamatters.org
Tue Dec 4 14:13:24 EST 2007
Charles M Howe wrote:
> How do I change all instances up to the end of a file of a single letter
> with another letter?
This is for vim, but I think the syntax is the same for other vi clones,
too. If you only want to change occurrences from your current position
in the file to the end of the file:
:,$s/<orig>/<new>/g
If you want to change everywhere in the file, regardless of your current
position:
:%s/<orig>/<new>/g
And if you wanted to change from the beginning of the buffer to your
current position (basically the opposite of the first command above):
:0,s/<orig>/<new>/g
The ",$", "%" and "0," are the movement modifiers to the "s" (search and
replace) command. The first means, in vi-speak, "from here to EOF" while
the "%" means "entire buffer" and "0," means "from beginning of buffer
to here."
The rest is whatever flavor of regular expressions you have available in
your vi or vi clone.
-Jon
--
Senior Systems Developer
Media Matters for America
http://mediamatters.org/
More information about the Novalug
mailing list