On 19/04/11 10:24, googler wrote:
On Apr 18, 9:50 pm, "John Beckett"<[email protected]> wrote:
googler wrote:
This is what I actually used after posting the question. But
I was wondering if there is a better way.
Use Tim's approach but modify the replacement using:
http://vim.wikia.com/wiki/Substitute_with_incrementing_numbers
John
Thanks for the link. It certainly solves my problem. However, I have
one question related to the solution given there.
:let i=1 | g/foo/s//\="blah_".i/ | let i=i+1
When I run the above, I see that it replaces 'foo' (the first
occuerence in a line) with blah_1, blah_2, etc., as the tip claims to
do. But I am not very clear on the three separate steps in the
process. On first looking at the above command, my understanding was
that first we are assigning 1 to i, then running the substitution
command over the entire file and then incrementing i -- which is not
correct because then the file will have all 'foo' replaced only by
'blah_1' and i incremented only once at the end. So looks like the
middle step (substituation) is not an atomic step and rather an
(implicit) iterative step. Can someone explain this behavior of the :g
and :s command in slightly greater detail or point to some explanation
on the same?
Actually, what happens is that the second | does not separate the :g
command from the :let command, but :s and :let _within_ the :g command,
see :help :bar (and notice that :global i.e. :g is in the list of
commands which see | as part of their argument).
Best regards,
Tony.
--
hundred-and-one symptoms of being an internet addict:
66. You create a homepage with the impression to cure the afflicted...but
your hidden agenda is to receive more e-mail.
--
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