Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Find and replace text in VI?

4 views
Skip to first unread message

cenit

unread,
Jun 6, 2003, 10:19:42 AM6/6/03
to
Hi everyone, I was wondering if anyone knows how to do a find/replace in
the vi editor.
TIA

ramsesrh

unread,
Jun 6, 2003, 10:04:11 AM6/6/03
to
try

1,$s / searchstring / replacestring /g

starts from the first byte until eof en does a global search

or

g/ searchstring / s// replacestring / g

Watch out for searching single words or space-containing strings

<cat...@hotmail.com> schreef in bericht
news:3c1Ea.4721...@fe04.atl2.webusenet.com...

Anne Tuchscherer

unread,
Jun 6, 2003, 11:07:43 AM6/6/03
to
If you are wanting to do a global replace of a certain string then the
command is

:1,$s/string1/string2/g

If you want to be selective in your replaces then doing the following:

/string1
cw
string2
<ESC>
n
.

Use the next to last line to keep finding occurences of string1 and the last
line to do a replacement.

Anne Tuchscherer
Medstar Health

Dwivian

unread,
Jun 9, 2003, 11:28:30 AM6/9/03
to
Anne Tuchscherer <anntuch...@comcast.net> wrote in message news:<f2c7d55236de7f2a...@free.teranews.com>...

> If you are wanting to do a global replace of a certain string then the
> command is
>
> :1,$s/string1/string2/g

The short form for "The Entire Address Space" is %. % matches 1,$,
which is read "start, finish" so you can also do fun things like 1,.
(top of file to current line), .,$ (current line to end of file), and
.-5,.+4 (five lines before here, four lines after here).

The address space area is often overlooked, or people write it as 1,$
without knowing what it means or how it can be used. No slight
intended, but I wanted others to see how versatile it could be.

For the whole file, use %, eg: :%s/string1/string2/g

-dwiv, CATE/AIX

0 new messages