`cw` edge cases: cursor on a space, support `cpo-z` (Vim), `cpo-_` (Neovim)
Resolves: #69 Resolves: #84
It looks quite trivial to add support for:
Doing that next on a separate commit
This is now completed
a82ad9a: nonfunctional change but makes it much easier to understand the code.
Small change on comment:
Made it clearer that what was previously a dw edge case is in fact an edge case for operator-pending w in general
Now there's nothing I want to add further
I've learned now that removing cpo-z in Vim also gets rid of some special case called d-special,
in vim's helpfiles:
:h cpo-z
*cpo-z*
z Special casing the "cw" and "d" command (see |cw| and
|d-special|).
:h d-special
*d-special*
An exception for the d{motion} command: If the motion is not linewise, the
start and end of the motion are not in the same line, and there are only
blanks before the start and there are no non-blanks after the end of the
motion, the delete becomes linewise. This means that the delete also removes
the line of blanks that you might expect to remain. Use the |o_v| operator to
force the motion to be characterwise or remove the "z" flag from 'cpoptions'
(see |cpo-z|) to disable this peculiarity.
Trying to delete an empty region of text (e.g., "d0" in the first column)
is an error when 'cpoptions' includes the 'E' flag.
~~Neovim has completely removed the d-special "peculiarity"~~ (corrected: https://github.com/chaoren/vim-wordmotion/pull/85#issuecomment-3530574122), and also all "POSIX flags" from cpoptions, from nvim's :h nvim-removed:
- 'cpoptions' (gjpkHw<*- and all POSIX flags were removed)
I'll have to investigate:
- How to test
d-specialfor Vim, and if it's even something relevant to vim-wordmotion - How to skip
cpo-wandcpo-<tests in Vader if `has('nvim')
By the way, hope it's okay to add these (very minimal) nvim compatibility checks: the few cpo flags seems all that is necessary, most of them just to tests.
Regarding skipping cpo-w and cpo-< tests if has('nvim'):
Looks like Vader has no mechanism to conditionally skip tests
https://github.com/junegunn/vader.vim/pull/201
So I don't know, maybe just let them fail on Neovim, at least there's no guessing for the reason they fail:
To reproduce d-special on Vim:
foo
bar
baz
d2ep (cursor on line 1, col 1)
With cpo-z (default), or in nvim (corrected: https://github.com/chaoren/vim-wordmotion/pull/85#issuecomment-3530574122):
baz
foo
bar
Without cpo-z, ~~or in nvim~~ (corrected: https://github.com/chaoren/vim-wordmotion/pull/85#issuecomment-3530574122):
foo
bar
baz
Tested with vim-wordmotion plugin installed on Vim, the d-special peculiarity is not reproduced in vim-wordmotion to begin with, and I think that's a good thing. Too complex just to replicate some strange Vi bug that no one has been missing.
(I don't oppose replicating it for Vim to be absolutely faithful to the source, but at least not in the scope of this PR)
I'd say this PR is finished.
Thanks for the PR! Apologies for the delay. I don't have access to my PC at the moment, so I can't review or test this in detail right now. Thank you so much for the detailed research and testing!
I only added the cw behavior because people asked for it. I'm not going to bother with that special d behavior since no one ever asked.
Great to know you're interested in this!
No hurry at all
Thank you so much for the detailed research and testing!
It started off simple but ended with a whole rabbit hole :smile: like usual
I only added the
cwbehavior because people asked for it. I'm not going to bother with that special d behavior since no one ever asked.
Yeah sounds good, also related to this plugin the cpo options for the cw special case are very new (added about a year ago), I think the choice to be as close to native as possible was nice but now we can reasonably have both!
Correction on d-special not being in nvim:
Actually it's the opposite: there is only d-special in nvim, just the help tag has been removed. This is surprising, but I've confirmed it: at first I thought the docs were wrong and considered sending a PR to neovim, but that's not the case.
Meaning, this section is still in nvim :h deleting, and it's still accurate:
An exception for the d{motion} command: If the motion is not linewise, the
start and end of the motion are not in the same line, and there are only
blanks before the start and there are no non-blanks after the end of the
motion, the delete becomes linewise. This means that the delete also removes
the line of blanks that you might expect to remain. Use the |o_v| operator to
force the motion to be charwise.
ref: https://github.com/chaoren/vim-wordmotion/pull/85#issuecomment-3494322423