On 12/03/10 23:17, Jean Johner wrote:
On Mar 12, 3:50 pm, Tony Mechelynck<[email protected]>
wrote:
:'<,'>s/^\ze\a/c/
Bonjour Antoine,
The absolute way to represent an empty string in a substitute command
I was looking for is simply:
\ze
In effect
[range]s/\ze/c
does the job (including empty lines)
No need to add ^ which is implicit and . which restrict the substitute
to non empty lines
The solution of François
[range]s/^\(.*\)$/c\1/
also works. It can be simplified to
[range]s/\(.*\)/c\1/
as ^ and $ are implicit in .*
Best regards
Jean Johner
To add the letter c at the start of a range of lines, there are
different ways:
1) :12,18s/^/c
(replace the start-of-line by "c"). \ze matches anywhere, so in an
otherwise empty pattern and without the g flag, the first place it can
match is at start-of-line.
2) select the first column blockwise, then
Ic<Esc>
(see :help v_b_I ) to insert c before the block on every line.
If you wanted to match the empty string in the middle of the line, let's
say insert a space if there is none between well-defined patterns "foo"
and "bar", you would use
:s/foo\zs\zebar/ /
or
:s/\(foo\)\(bar\)/\1 \2
with flag g if it were "everywhere in the line".
Best regards,
Tony.
--
"One Saturday afternoon, during the campaign to decide whether or not
there should be a Coastal Commission, I took a helicopter ride from Los
Angeles to San Diego. We passed several state beaches, some crowded
and some virtually empty. They had the same facilities, and in some
cases the crowded and the empty beach were within a quarter mile of
each other. Obviously many beach-goers prefer to be crowded together.
Buying more beaches that people won't go to because they prefer to be
crowded together on one beach is a ridiculous waste of our natural
resources and our taxes."
-- Ronald Reagan
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php