Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 8 Feb 2008 14:20:09 +0300
From:      Eygene Ryabinkin <rea-fbsd@codelabs.ru>
To:        Dag-Erling Sm??rgrav <des@des.no>
Cc:        hackers@freebsd.org
Subject:   Re: nvi strangeness
Message-ID:  <YUJ/3Pqrii4HUH/mrJ9gqroFKBU@DFbaqoiVkklixLmZdm82EYt/QrU>
In-Reply-To: <86prv7agit.fsf@ds4.des.no>
References:  <86prv7agit.fsf@ds4.des.no>

next in thread | previous in thread | raw e-mail | index | archive | help
Dag-Erling, good day.

Speaking for the system's nvi (not the ports one -- not using it).

Fri, Feb 08, 2008 at 11:28:42AM +0100, Dag-Erling Sm??rgrav wrote:
> As everybody knows, the ex/vi command for regexp substitution is
> 
>        [range] s[ubstitute] [/pattern/replace/] [options] [count] [flags]
> 
> The man page does not document the syntax for ranges (nor for offsets or
> counts for that matter)
> 
> Assuming the syntax is the same as for ed / sed, the following should
> replace every occurrence of the word wait with the word delta:
> 
> :,s/\<wait\>/delta/g
> 
> where "," means "the entire file"

Nope, "," means "from the current line to the current line".

So
:,s/anything/the other thing/g
is equal to plain
:s/anything/the other thing/g

> That doesn't work, however, and neither does "1,"; only "X,Y" works, so
> if you want to substitute in the entire file, you first have to find out
> how long it is, then manually type in that number.
> 
> ...or you could use the following (courtesy of roberto@):
> 
> :%s/\<wait\>/delta/g

:1,$s/anything/the other thing/
will be the same as the ':%s...'.  But ':%s...' is shorter to type ;))

Moreover, "1," will select lines from the first one to the current
one.  And, for example, ",+3" will select four lines, counting from
the current and going down; "-2," will select three lines, counting
from the current and going up.

> None of this is documented anywhere.

$ zcat /usr/share/doc/usd/13.viref/paper.ascii.gz | less
and search for the 'percent sign'.
-- 
Eygene



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?YUJ/3Pqrii4HUH/mrJ9gqroFKBU>