On 2/2/07, Ralph Shumaker <[EMAIL PROTECTED]> wrote:
>
Now I want to do a search an replace (with verification) of something
involving mixed case. I tried to figure out the formula, but I'm
hitting a catch-22 with my limited knowledge.
Let's say I want to replace a whole bunch of "the" and "The" with "this"
and "This" respectively. And I need to make sure that "the" and "The"
are not preceded nor followed by alpha. How would I do this? Oh, and
how can I make it so that the highlighted match is always vertically
centered (so I can see context)?
("the" and "The" are not the only sets I want to replace with others, so
I really would like to know a formula. Or am I just better off doing
the replace twice? once for lowercase and again for upper?)
Here is something to try, for starters. Put this in a file, open it
with the vi of your choice,
put the cursor on the line beginning with : and execute the command "qyy
This "yanks" the line into register q. Old-time TECO fans will
understand why I used q.
Then put the cursor on the first line of text and execute the command @q
Watch what happens.
- - - - - - - -
1) The other tithe the other tiThe
2) The other tithe the other tiThe
3) The other tithe the other tiThe
4) The other tithe the other tiThe
:g/\<\([Tt]\)he\>/s//\1his/cg
- - - - - - - -
Parsing the command:
g globally for all lines
/ start of regex to be found
\< beginning of word
\( start of object to be saved
[Tt] upper or lower-case T
\) end of object to be saved
\> end of word
/ end of regex
s/ substitute for what was found
/ beginning of substitution
\1 the saved object
his followed by letters his
/ end of substitution
c confirm before changing
g everywhere in the line
Rest of the magic is to copy this command line into a register "qyy
and execute the contents of that register as a command @q
Nice exercise.
carl
--
carl lowenstein marine physical lab u.c. san diego
[EMAIL PROTECTED]
--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-list