On 2/2/07, Ralph Shumaker <[EMAIL PROTECTED]> wrote:
Carl Lowenstein wrote:
> 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
\< and \> was just what I needed. Thanks Carl. (The rest is about 5
levels above me.) My new formula:
:%s/\(\<[Tt]\)he\>/\1is/cg
I must have confirmation because context sometimes needs a different
substitution.
What you were spelling out above, is that a macro in vi?
I guess it is the vi equivalent of a macro. Has the advantage over
command substitution that you can see what command you created, and
edit it as needed. Of course after all is done you should remove the
prototype command line from the file.
Also, I mispoke about l (lower-case L) as a motion command. Everyone
knows that l means move right. Which it does except apparently in the
vi "confirm" context where it means "move to the next line." Steve
Oualine, in _VI Improved VIM_ does not seem to mention all of these
options for the c)onfirm option.
(y/n/a/q/l/^E/^Y)?
My experimentation shows the following meanings: (Vim 6.3)
yes, no, all of this line, quit, do this one and then go to next line,
scroll display up, scroll display down.
vim help says: Confirm each substitution.
You can type:
'y' to substitute this match
'l' to substitute this match and then quit ("last")
'n' to skip this match
<Esc> to quit substituting
'a' to substitute this and all remaining matches {not in Vi}
'q' to quit substituting {not in Vi}
CTRL-E to scroll the screen up {not in Vi, not available when
compiled without the +insert_expand feature}
CTRL-Y to scroll the screen down {not in Vi, not available when
compiled without the +insert_expand feature}
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