> Gosh! The possibilities are endless.
Indeed, the power of global (":g" and ":v") commands along with
the substitute (":s") are two of the things that make vim my
favorite editor. Many hours of my time (and my coworkers' time)
have been saved by them.
> line ends and finishes with two bars:
> || dfjdfjd || dfjdkfjsd || sds ||
> In reality the repeat pattern is longer.
>
> I need to insert some text after the bars:
> ||X dfjdfjd ||X dfjdkfjsd ||X sds ||
> In reality X is fairly long.
>
>
> My substitution:
> :s/^||\(.*\)||\(.*\)||\(.*\)||$/||X \1||X \2||X \3||/
This sounds like "replace every '||' with '|| X' as long as
either (1) it's not the last one or (2) it's got some character
immediately after it (which the last one shouldn't)"
For #1, that would be something like either of these:
s/||\_$\@<!/& X/g
s/||\_$\@<!/|| X/g
Both assert that an end-of-line doesn't happen after the "||"
that gets replaced.
For #2, that would be something like either of these
s/||\ze./& X/g
s/||\(.\)/|| X\1/g
The first form stops the replacement before the "any" (".")
character, while the second one snags the "any" character and
then puts it back in the replacement as "\1"
Both can be thrown off if you have trailing characters (most
likely whitespace) after your last "||" so it might be good
ensure that by pre-processing with
:%s/||\s\+$/||
"replace two pipes followed by one or more whitespace at the EOL,
and replace it with just two pipes (omitting the trailing
whitespace)"
> I have mapped this in nomral mode:
> :nmap :s/ ... / ... /<Enter>
>
> For some reason, I need to escape the bars now.
When used in a mapping command, you need to either escape the
bars or use "<bar>" (5 character) as in
:nnoremap :s/^<bar><bar> ...
I prefer the latter because it's a bit more readable to me, but
that's just my taste. You can read about it at
:help map_bar
Hope this helps,
-tim
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---