Carl Lowenstein wrote:
On Jan 25, 2008 3:28 PM, Ralph Shumaker <[EMAIL PROTECTED]> wrote:
Carl Lowenstein wrote:
On Jan 25, 2008 2:40 PM, James G. Sack (jim) <[EMAIL PROTECTED]> wrote:
Carl Lowenstein wrote:
Perhaps the command you are looking for is "g!" global exclude.
:%g!/pattern/action # perform action on all lines not
matching pattern
# action can include another
substitution match
# and other specifications
like g)lobal and c)onfirm
:%g!/pattern/s/pattern2/new thing/gc
Wow another vim capability I never encountered.
Now, I wonder if there is any way to get more occurrences of the adj/adv
"global" into a vim command. This one has 3 does it not?
There are only two. The first g is "global within the specified
range", the second one is "global within the line". Vi/Ex have been
like this since forever. Actually I find this usage in 6th Edition
Unix ed(I) dated 1973. So blame it on Ken Thompson not Bill Joy.
Well, OK the "%" also states that the specified range is the whole file.
carl
I had to fuss with it a little, but ended up with:
:%g!/<br>$\|^[$%]$/s/$/<br>/gc
That worked perfectly. And with command history, I don't even have to
re-type it.
What I tried first was:
:%g!/<br>$/g!/^[$%]$/s/$/<br>/gc
Apparently, you can't use the g! twice (or I didn't format it right).
Yes. Unfortunately, the historical development of this editor left it
with two different "g" commands.
"g" select lines globally within the range. This one can be negated.
"g" perform operations globally within the line.
As sort of pointed out by Jim Sack, if the region of interest is all
lines, you don't need both the initial "%" and the "g" since "%" ==
all lines is implied by an otherwise unspecified "g".
I don't know if you are referring to the "g" at the end of the command,
but you are the one (IIRC) that pointed out that the command would only
work on the first item on a given line without that "g". But given that
I am only looking at patterns that include $ (EOL), that "g" does seem
redundant in this situation. :-?
But if you are referring to my second implementation of "g!", I was
thinking of "g!/<br>$/g!/^[$%]$/" as ~"not <br>$ *and* not ^[$%]$"~.
But since that didn't work, I opted for a vague memory of how to say
"or" in regex-speak. Sometimes, I tend to shy away from fuzzy memory
since I often sink too much time when I can't seem to recall it ~quite~
right.
The "g!" inversion of the selection was originally "v" but this seems
to have been redefined to be something else in vim. At least
according to my quick look through the _Vi Improved_ book.
carl
You are a true guru. :)
--
Ralph
--------------------
If you pick your philosophy to excuse your actions, you demean your
philosophy.
--Stewart Stremler
--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-list