0

I'm having strange bevahiour with Vim 9.0

$ ex --version | head -3
VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Sep 30 2022 03:09:54)
macOS version - x86_64
Included patches: 1-270
$ VIM_POSIX='cpoptions' ex --clean -u NONE

Here is my strange session now

Entering Ex mode.  Type "visual" to go to Normal mode.
:i
21 22 23 24 25 26 27  18 19 20 21 22 23 24  22 23 24 25 26 27 28  
.
:s/23/2z/3p
E488: Trailing characters: p
:s/23/2z/3
21 22 2z 24 25 26 27  18 19 20 21 22 23 24  22 23 24 25 26 27 28  
:q!

The expected result of s/23/2z/3 is 21 22 23 24 25 26 27 18 19 20 21 22 23 24 22 2z 24 25 26 27 28. As I'm not sure it's a bug that have been there for years, I'm asking here what option is producing that weird thing.

Regards.

3
  • what exactly are you expecting here? Dec 27, 2022 at 7:26
  • @ChristianBrabandt see my last words, expected result should be 21 22 23 24 25 26 27 18 19 20 21 22 23 24 22 2z 24 25 26 27 28 instead of 21 22 2z 24 25 26 27 18 19 20 21 22 23 24 22 23 24 25 26 27 28
    – gildux
    Dec 27, 2022 at 15:40
  • @ChristianBrabandt also see my comment to accepted answer: I didn't understand the count to be for following lines but third occurrence. Ex is very confusing sometimes.
    – gildux
    Dec 27, 2022 at 16:12

1 Answer 1

1

The count is a way to extend the number of line considered for substitution

E.g:

:1,2s/23/2z/3

It is equivalent to:

:2,4s/23/2z/

In such case the substitution should occurs on the fist occurrence of 23 on the lines 2 to 4 (3 lines) (but not on the third occurrence of 23 on the block of line 1 to 2)

:help substitute

When [count] is given,
replace in [count] lines,
starting with the last line in [range].
6
  • 1
    Thanks. That part of the help (extend the number of line considered for substitution) wasn't clear for me. Plus I was trying to use ex in place of ed in a box that miss the later but has vim installed with no success for that case, then check back on my Mac. I've reread POSIX but that's no clear either about that meaning of the count. Many thanks.
    – gildux
    Dec 27, 2022 at 16:00
  • Thanks for the feedback :-) Dec 27, 2022 at 23:20
  • @gildux perhaps you were thinking of a sed where such a count could be used this way?
    – D. Ben Knoble
    Dec 28, 2022 at 15:27
  • yes @D.BenKnoble (in some way) I've never tried such thing directly with ex/vi before. Even when reading the help, I didn't realised it was that count (I was thinking it's a flag like g) Here, I think Bill Joy messed things up :D
    – gildux
    Dec 28, 2022 at 18:04
  • @gildux ed came first…
    – D. Ben Knoble
    Dec 28, 2022 at 18:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.