[Israel.pm] OT: how can you limit your search to a block in vi or emacs?

Oron Peled oron at actcom.co.il
Sun Sep 7 12:27:52 PDT 2008

On Sunday, 7 בSeptember 2008, Gabor Szabo wrote:
> I often need to find (and maybe rename) all the ocurances of a variable.

Referring to vim:

> The problem is
> 1) if the same name is used in multiple places then my search keeps
>      going to the other places as well an does not stay within the scope.

Substitute, like any ':' command, may be prefixed with a line range.
  :1,$s/all lines/every line/
  :/from/,/to/s/all lines in range/including from and to/

If you mark the start/end of your range with arbitrary letters
(using the 'm' operator -- e.g: 'ma' and 'mb')
than you may refer these marks as well with the apostrophe:
  :'a,'bs/from mark a/to mark b included/

> 2) how can I easily locate both @x and $x[2]  but not $x nor $x{name}?

How about a proper regexp? Tested in vim:

(the end part -- [0-9]*\] -- is not important for finding it, but
 only if you want to substitute including the indexing part)

> Gabor

Vim... the editor of the GNU generation ;-)

Oron Peled                             Voice/Fax: +972-4-8228492
oron at actcom.co.il                  http://www.actcom.co.il/~oron
... Complex problems have simple, easy to understand wrong answers.

More information about the Perl mailing list