[vim/vim] Very weird bug in :cdo (Issue #13330)

19 views
Skip to first unread message

trebestie

unread,
Oct 12, 2023, 4:21:42 PM10/12/23
to vim/vim, Subscribed

Steps to reproduce

Consider a simple file cdotest.txt

one two three
one two three
one two three
one two three

run a
:grep three cdotest.txt
then
:cdo s/three/four
:cdo s/three/Sthree
:cdo 2,$s/three/four
work well

while
:cdo 2,$s/three/Sthree or
:cdo 2,3s/three/Sthree
fail

one two three
one two SSSSthree
one two SSSSthree
one two SSSSthree

It looks like the bug occur only if you operate in a range prepend something to the matching pattern
Neovim has the same behaviour

Expected behaviour

The right output

Version of Vim

vim 9.0

Environment

VoidLinux

Logs and stack traces

No response


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/13330@github.com>

Nick Jensen

unread,
Oct 12, 2023, 5:33:51 PM10/12/23
to vim/vim, Subscribed

This isn't a bug. :cdo runs a command on each quickfix entry. You have 4 quickfix entries.

Your first command :cdo s/three/four runs that substitution on each quickfix entry line. The range is not specified so it just runs on the line of the quickfix entry.

The later commands still run for each quickfix entry but you manually set the range to something else, so it runs 4 times on the range you have set.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/13330/1760393128@github.com>

trebestie

unread,
Oct 12, 2023, 5:59:45 PM10/12/23
to vim/vim, Subscribed

Thanks,
but...

  1. why :cdo 2,$s/three/four replaces three with four from the second line to the end as expected?
  2. is :cdo' the right command to perform such kind of replacement? can't :cdo` work in a range?


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/13330/1760428155@github.com>

EdwardMG

unread,
Oct 12, 2023, 7:50:40 PM10/12/23
to vim/vim, Subscribed

why :cdo 2,$s/three/four replaces three with four from the second line to the end as expected?

In this case, three no longer exists in the buffer, so the next 3 times it runs nothing happens because no three exists to substitute. In your surprise case, you substitution itself contains the expression you searched for, so it happens 3 more times three -> Sthree -> SSthree etc.

Hope that helps you :)


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/13330/1760546097@github.com>

trebestie

unread,
Oct 13, 2023, 3:33:48 AM10/13/23
to vim/vim, Subscribed

It helps,
thank you all

Il giorno ven 13 ott 2023 alle ore 01:50 EdwardMG ***@***.***>
ha scritto:

> why :cdo 2,$s/three/four replaces three with four from the second line to
> the end as expected?
>
> In this case, three no longer exists in the buffer, so the next 3 times
> it runs nothing happens because no three exists to substitute. In your
> surprise case, you substitution itself contains the expression you searched
> for, so it happens 3 more times three -> Sthree -> SSthree etc..
>
> Hope that helps you :)
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/vim/vim/issues/13330#issuecomment-1760546097>, or
> unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AEHYK27YYZNNCV5U7UPTZVLX7B63BAVCNFSM6AAAAAA56ES3RKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONRQGU2DMMBZG4>
> .
> You are receiving this because you authored the thread.Message ID:
> ***@***.***>
>


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/13330/1761044579@github.com>

Christian Brabandt

unread,
Oct 13, 2023, 4:11:02 AM10/13/23
to vim/vim, Subscribed

this seems to be no issue, so let me close it


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/13330/1761091478@github.com>

Christian Brabandt

unread,
Oct 13, 2023, 4:11:04 AM10/13/23
to vim/vim, Subscribed

Closed #13330 as not planned.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issue/13330/issue_event/10641277975@github.com>

Reply all
Reply to author
Forward
0 new messages