Block oriented search and replace across multiple files.

Ray Parrish crp at cmc.net
Sat Nov 28 18:25:54 UTC 2009


Brian McKee wrote:
> On Sat, Nov 28, 2009 at 10:10 AM, Ray Parrish <crp at cmc.net> wrote:
>>>> I am searching for a programmer's editor that does block oriented
>>>> search, and replace across multiple files.
>
>>>> What I want to be able to do is replace several lines of text with
>>>> several other lines of text in all open files all at one go.
>
>>> Emacs and Eclipse both support multi-line regex expressions.  I'm rusty
>>> on Emacs, but with Eclipse just use "(?ms)StartPhrase.*StopPhrase" to
>>> match the paragraph, then replace with whatever you want.  Add anchors
>>> as needed.
>
>> I have Eclipse on here, but it is a bit over the top for what I want to
>> do, which is make broadcast changes to my web site's pages. I'm going to
>> forego the learning curve, and the necessity to remember regular
>> expressions by writing my own multi document, block oriented search, and
>> replace program that will allow me to paste in what I want to replace,
>> and paste in what I want it replaced with, and the program will take
>> care of searching, and replacing for me.
>
> That's the easy way? :-)
>
> vim will certainly do that, and you almost certainly have it already.
> Be happy to help if you give a little more example so I get it right 
> for you...
>
> Brian
OK, I've install gvim, and have been trying to get it to do a block 
replace, but it can''t even find the block I copied from the currently 
opened file.

What I want to do is take the following block of text -

  <link rel="stylesheet" type="text/css" media="all" id="Skin" 
title="PeachSkin" href="peach.css">
  <link rel="alternate stylesheet" type="text/css" media="all"  
title="BlueSkin" href="blue.css">
  <link rel="alternate stylesheet" type="text/css" media="all"  
title="BlueonWhiteSkin" href="blueonwhite.css">
  <link rel="alternate stylesheet" type="text/css" media="all"  
title="BlackMarbleSkin" href="blackmarble.css">
  <link rel="alternate stylesheet" type="text/css" media="all"  
title="BlackSkin" href="black.css">
  <link rel="alternate stylesheet" type="text/css" media="all"  
title="WhiteSkin" href="white.css">
  <link rel="alternate stylesheet" type="text/css" media="all"  
title="MarbleSkin" href="marble.css">
  <link rel="alternate stylesheet" type="text/css" media="all"  
title="GreenMarbleSkin" href="greenmarble.css">

And replace it with the following =

  <link rel="stylesheet" type="text/css" media="all" id="Skin" 
title="GreenMarbleSkin" href="greenmarble.css">
  <link rel="alternate stylesheet" type="text/css" media="all"  
title="BlueSkin" href="blue.css">
  <link rel="alternate stylesheet" type="text/css" media="all"  
title="BlueonWhiteSkin" href="blueonwhite.css">
  <link rel="alternate stylesheet" type="text/css" media="all"  
title="BlackMarbleSkin" href="blackmarble.css">
  <link rel="alternate stylesheet" type="text/css" media="all"  
title="BlackSkin" href="black.css">
  <link rel="alternate stylesheet" type="text/css" media="all"  
title="WhiteSkin" href="white.css">
  <link rel="alternate stylesheet" type="text/css" media="all"  
title="MarbleSkin" href="marble.css">
  <link rel="alternate stylesheet" type="text/css" media="all"  
title="PeachSkin" href="peach.css">

Notice how the first line of the first block became the last line of the 
second block, and the last line of the first block becomes the first 
line of the second block. Gvim is not cooperating, and refuses to 
replace the text block with the second version above.

Also, I do not see any indication that Vim can do search, and replace 
across multiple files simultaneously, so I'm back to writing my program, 
which is coming along nicely.

Later, Ray Parrish

-- 
The Future of Technology.
http://www.rayslinks.com/The%20Future%20of%20Technology.html
Ray's Links, a variety of links to usefull things, and articles by Ray.
http://www.rayslinks.com
Writings of "The" Schizophrenic, what it's like to be a schizo, and other
things, including my poetry.
http://www.writingsoftheschizophrenic.com






More information about the ubuntu-users mailing list