Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]w in cw is same as ce #4390

Closed
icyhat opened this issue May 18, 2019 · 11 comments
Closed

[Bug]w in cw is same as ce #4390

icyhat opened this issue May 18, 2019 · 11 comments

Comments

@icyhat
Copy link

icyhat commented May 18, 2019

w in cw is same as ce
When w combine with c, cw behaves same as ce.

They both delete from current cursor to end of current word and insert.

But cw should delete from current cursor to where until next word which contain the blanks between it and next word.

To Reproduce

alpha text:         hello world vim
target word:              world
de:                 hello  vim
dw:                 hello vim
ce:                 hello  vim
cw:                 hello  vim

Expected behavior
cw has two parts, delete and insert. its deletion should be like dw which delete until next word, including blanks.
Environment

  • Vim version [version 8.1.320]
  • OS: [Ubuntu 19.04]
  • Terminal: [GNOME Terminal)
@icyhat icyhat changed the title w in cw is same as ce [Bug]w in cw is same as ce May 18, 2019
@tonymec
Copy link

tonymec commented May 18, 2019

This is documented (under :help WORD):

Special case: "cw" and "cW" are treated like "ce" and "cE" if the cursor is
on a non-blank.  This is because "cw" is interpreted as change-word, and a
word does not include the following white space.

@icyhat
Copy link
Author

icyhat commented May 18, 2019

This is documented (under :help WORD):

Special case: "cw" and "cW" are treated like "ce" and "cE" if the cursor is
on a non-blank.  This is because "cw" is interpreted as change-word, and a
word does not include the following white space.

Thanks. You got a wide range of knowledge.

but since cw could treat as ce, then why the dw is not treated as de due to keeping consistency.

Or, can we exchange w and e as if e is actually end of the word with blanks while w is end of the word, because w is interpreted as word, and a word does not include the following white space.

@chrisbra
Copy link
Member

It's actually a strange vi behaviour:

https://github.com/vim/vim/blob/master/src/normal.c#L8648-L8656

Some time ago I made a patch (and I think Neovim merged that one:
neovim/neovim#6235 and https://github.com/chrisbra/vim-mq-patches/blob/master/cpo_changeword

@icyhat
Copy link
Author

icyhat commented May 18, 2019

It's actually a strange vi behaviour:

https://github.com/vim/vim/blob/master/src/normal.c#L8648-L8656

Some time ago I made a patch (and I think Neovim merged that one:
neovim/neovim#6235 and https://github.com/chrisbra/vim-mq-patches/blob/master/cpo_changeword

I wonder is there a flag that I can easily turn on from different platforms to use corrected version of vim while we can keep default in old vim for compatibility?Why should we keep the garbage in the vim and carry on?

@tonymec
Copy link

tonymec commented May 18, 2019

There is a 'compatible' boolean option, and also a related set-of-one-letter-flags 'cpoptions' option, which allow disabling those legacy-vi established behaviours which Bram regards as bugs. 'compatible' is nowadays usually off except if you invoke Vim as 'vi' or with the -C command-line switch.

But in general, Bram regards backward compatibility as extremely important, and IMHO rightly so: backward compatibility goes hand in hand with the principle of least surprise, or IOW, an application cannot be relied on if you cannot count on using it tomorrow like you used it yesterday.

@icyhat
Copy link
Author

icyhat commented May 19, 2019

There is a 'compatible' boolean option, and also a related set-of-one-letter-flags 'cpoptions' option, which allow disabling those legacy-vi established behaviours which Bram regards as bugs. 'compatible' is nowadays usually off except if you invoke Vim as 'vi' or with the -C command-line switch.

But in general, Bram regards backward compatibility as extremely important, and IMHO rightly so: backward compatibility goes hand in hand with the principle of least surprise, or IOW, an application cannot be relied on if you cannot count on using it tomorrow like you used it yesterday.

Thanks your kindness.

I learned a lot

  1. use :help cw to search whether there is a solution.
  2. use :help cpoptions to check a list of compatible issues.

I checked cpoptions, there is no flag for this bug, but the help manual did give us a solution, :map cw dwi.

As we know that cpoptions is off by default, the only question is that when can we have a flag to enable all better and consistent features while we remain compatibility by default which can be relied on from past to now.

Thanks again, you guys help me so much information.

@icyhat
Copy link
Author

icyhat commented May 20, 2019

Hi there, again.

Since :map cw dwi doesn't work when consistent with ce on the last word of line, which new char waiting for INSERT, I'v turn to use Neovim with single set set cpoptions-=_.

I think compatibility do matters, but self-renewing ability also matters.

Softwares should work as compatibility pattern by default while give a possibility for users to turn on all better and consistent features. Anyway keep a garbage is reasonable due to lacking of time or money or historical issues, but how can we reject growing?

@Roy-Orbison
Copy link
Contributor

@chrisbra can you merge a version of your cpo_changeword patch in a way that doesn't break backwards compatibility? E.g. keep the name z, but omit it from #define CPO_VIM.

I've seen several workarounds, like this one, including the suggested mapping in the help docs, but none work like native support would. The help suggestion can only be multiplied like 2cw instead of the usual c2w, and suffers the same inconsistency at the ends of the lines. There are plenty of people that would appreciate real support for this.

@chrisbra
Copy link
Member

Alright, let me create a new PR for this one then. It needs a test and I must check how if this still applies.

chrisbra added a commit to chrisbra/vim that referenced this issue Jul 14, 2024
Problem:  d{motion} may work different than expected (also cw
          is special cased by POSIX)
Solution: add new cpo-z flag to make the behaviour configurable

There are two special vi compatible behaviours:

1): cw behaves differently than dw. That is, because cw is special cased
    by Vim and is effectively aliased to ce.

    POSIX behaviour:
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/vi.html#tag_20_152_13_81

2): d{motion} may make the whole delete operation linewise, if the start
    and end of the motion are on different lines and there are only
    blanks before the start and after the end of the motion.
    Did not find a related POSIX link that requires this behaviour.

Both behaviours can be considered inconsistent, but we cannot easily
change it, because it would be a backward incompatible change and also
incompatible to how classic vi behaved.

So let's add the new cpo flag "w", which when not included fixes both
behaviours and make them more consistent to what users would expect.

This has been requested several times:
https://groups.google.com/d/msg/vim_use/aaBqT6ECkA4/ALf4odKzEDgJ
https://groups.google.com/d/msg/vim_dev/Dpn3xtUF16I/T6JcOPKN6usJ
http://www.reddit.com/r/vim/comments/26nut8/why_does_cw_work_like_ce/
https://groups.google.com/d/msg/vim_use/vunNWLFWfQg/MmJh_ZGaAgAJ
vim#4390

So in summary, if you want to have the w motion work more consistent,
remove the 'z' from the cpo settings.

related: vim#4390

Signed-off-by: Christian Brabandt <cb@256bit.org>
@chrisbra
Copy link
Member

I made #15263 but Note: change change to CPO_VIM is required, exactly to stay backwards compatible.

@Roy-Orbison
Copy link
Contributor

Much appreciated, @chrisbra.

chrisbra added a commit to chrisbra/vim that referenced this issue Jul 15, 2024
Problem:  d{motion} may work differently than expected (also cw
          is special cased by POSIX)
Solution: add new cpo-z flag to make the behaviour configurable

There are two special vi compatible behaviours:

1): cw behaves differently than dw. That is, because cw is special cased
    by Vim and is effectively aliased to ce.
    POSIX behaviour is documented here:
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/vi.html#tag_20_152_13_81

2): d{motion} may make the whole delete operation linewise, if the start
    and end of the motion are on different lines and there are only
    blanks before the start and after the end of the motion.
    Did not find a related POSIX link that requires this behaviour.

Both behaviours can be considered inconsistent, but we cannot easily
change it, because it would be a backward incompatible change and also
incompatible to how classic vi behaved.

So let's add the new cpo flag "z", which when not included fixes both
behaviours and make them more consistent to what users would expect.

This has been requested several times:
https://groups.google.com/d/msg/vim_use/aaBqT6ECkA4/ALf4odKzEDgJ
https://groups.google.com/d/msg/vim_dev/Dpn3xtUF16I/T6JcOPKN6usJ
http://www.reddit.com/r/vim/comments/26nut8/why_does_cw_work_like_ce/
https://groups.google.com/d/msg/vim_use/vunNWLFWfQg/MmJh_ZGaAgAJ
vim#4390

So in summary, if you want to have the w motion work more consistent,
remove the 'z' from the cpo settings.

related: vim#4390

Signed-off-by: Christian Brabandt <cb@256bit.org>
chrisbra added a commit that referenced this issue Jul 15, 2024
Problem:  vi: d{motion} and cw command work differently than expected
Solution: add new cpo-z flag to make the behaviour configurable

There are two special vi compatible behaviours (or should I say bugs?):

1): cw behaves differently than dw. That is, because cw is special cased
    by Vim and is effectively aliased to ce.
    POSIX behaviour is documented here:
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/vi.html#tag_20_152_13_81

2): d{motion} may make the whole delete operation linewise, if the start
    and end of the motion are on different lines and there are only
    blanks before the start and after the end of the motion.
    Did not find a related POSIX link that requires this behaviour.

Both behaviours can be considered inconsistent, but we cannot easily
change it, because it would be a backward incompatible change and also
incompatible to how classic vi behaved.

So let's add the new cpo flag "z", which when not included fixes both
behaviours and make them more consistent to what users would expect.

This has been requested several times:
https://groups.google.com/d/msg/vim_use/aaBqT6ECkA4/ALf4odKzEDgJ
https://groups.google.com/d/msg/vim_dev/Dpn3xtUF16I/T6JcOPKN6usJ
http://www.reddit.com/r/vim/comments/26nut8/why_does_cw_work_like_ce/
https://groups.google.com/d/msg/vim_use/vunNWLFWfQg/MmJh_ZGaAgAJ
#4390

So in summary, if you want to have the w motion work more consistent,
remove the 'z' from the cpo settings.

related: #4390
closes: #15263

Signed-off-by: Christian Brabandt <cb@256bit.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants