I wanted to understand the behavior of the lookaround in vim so for that I tried to mark the positions of assertion. Let's suppose I have the content of this file:
foobar
By executing this command :s/\(foo\)\@<!/♠ /g
I got:
♠ f♠ o♠ ob♠ a♠ r
Why I don't have ♠
at the end of line ? Is the $
anchor not considered as a position in this case ?
Instead if I execute this command :%s/\(bar\)\@<=/♠ /g
I got:
foobar♠
Any Explanation ? and Can someone please confirm this behavior ?
Vim 7.4 Ubuntu 16.04 LTS
In both of your cases, you're effectively matching nothing, and just do assertions around that.
The behavior of
:s/\(foo\)\@<!/♠ /g
is consistent with the simpler:s/\zs/♠ /g
A match only starts at an existing character; the implicit newline after each line does not count (according to Vim's implementation).
With your second
:%s/\(bar\)\@<=/♠ /g
command, the assertion effectively acts like the simpler$
atom. Like:s/$/♠ /g
, it therefore inserts after the assertion match, even though there's only the (implicit) trailing newline after it.So, though maybe surprising and inconsistent with other regular expression engines, you see that inside Vim, this is all consistent with the internal workings of its regular expression engine and buffer representation. I therefore would think that this is not a bug. If you still feel strongly about this, you could raise an issue at the bug tracker, or directly discuss this on the vim_dev mailing list.