VIM Q again

Cameron Simpson cs at zip.com.au
Mon Jun 2 01:38:47 UTC 2008


On 01Jun2008 21:26, Gene Heskett <gene.heskett at verizon.net> wrote:
| On Sunday 01 June 2008, Cameron Simpson wrote:
| >On 01Jun2008 20:19, Gene Heskett <gene.heskett at verizon.net> wrote:
| >| So what am I doing wrong when in the command mode, I type
| >| /s/L1BAE/isspace/&g, or :s/L1BAE/isspace/&g
| >
| >What do you think each of the "&" and the "g" do in your line?
| >
| >Next. What does:
| >  :s/L1BAE/isspace/g
| >do? That's for a single line.
| 
| which has not done anything here even to a single instance of L1A8E

Um, I should have mentioned that that does only the "current" line.
Move your cursor to a line with L1BAE and retry.

And it seems I typed "L1BAE" and you typed "L1A8E". Sorry, that will
have wasted your time. Corrected in the examples below.

| Every line:
| >  :%s/L1BAE/isspace/g
| The use of the % sign doesn't seem to be mentioned in the :help I have been able 
| to get to.

Maybe not. It's a shorthand for "1,$" i.e. from the first line to the
last line. I see someone else has suggested:

  :g/L1A8E/s//isspace/g

which in this case is semanticly equivalent but internally different.

It says "for each line (g) that contains L1A8E (/L1A8E/) replace that
(L1A8E, or more generally: what was matched in the first //) with isspace,
globally (g: every time it occurs on the line)".

For your task these two things are the same. There are other circumstances
where the "g/ptn/something" idiom has specific advantages.

| When I figure out what a piece of code is doing, I would like to be able to 
| globally replace the L1A8E label it now carries as an entry point,  as found 
| and labeled by our disassembler, with something more in line with what the 
| routine actually does, like "s/L1A8E/printerr/g" which with another editor I 
| use on that machine will globally replace every instance of L1A8E with 
| printerr.

Ok. You might also want to beef up the regexp, thus:

  :%s/\<L1A8E\>/isspace/g

The causes the L1A8E to have "word boundaries" at each end, so that
FOOL1A8EBAR will not match the regexp. It looks like your disassembler
generated labels won't have this trouble, but I like to be cautious.

Cheers,
-- 
Cameron Simpson <cs at zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/

C makes it easy for you to shoot yourself in the foot.  C++ makes that
harder, but when you do, it blows away your whole leg.
- Bjarne Stroustrup




More information about the users mailing list