chrisgrieser / nvim-spider

Use the w, e, b motions like a spider. Move by subwords and skip insignificant punctuation.
MIT License
667 stars 13 forks source link

[Bug]: Unexpected behavior with cw command #10

Closed Seth-Buchanan closed 1 year ago

Seth-Buchanan commented 1 year ago

Bug Description

I found and issue with the cw command. The default vim behavior when entering cw on a word in sentence is to preserve the post space which allows you to type a word and not have to add a space. This is in contrast to the dw command that deletes the post word space to make that word seem like it was never there.

Another unexpected behavior is that pressing cw on the last word in the line deletes the newline character as well. This makes the next line append to what is left of the current line.

ciw does work as expected and is recommended to use over cw but I thought I would raise it to your attention.

Relevant Screenshot

No response

To Reproduce

Type text, go to the begining of a word, and use the cw command. Type multiple lines and use cw command on any line but the last.

neovim version

0.8.3

Make sure you have done the following

s-cassidy commented 1 year ago

To add to this, dw/cw also doesn't work on the last word in the file.

Seems like dw/cw in this plugin is looking ahead for a space followed by another character. If we are at the last word of line, it ends up finding this on the next line (not expected). If we are at the last word of the file, it can't find this at all so doesn't do anything (not expected).

I like the idea of this plugin but can't really use it until this is fixed.

chrisgrieser commented 1 year ago

The default vim behavior when entering cw on a word in sentence is to preserve the post space which allows you to type a word and not have to add a space. This is in contrast to the dw command that deletes the post word space to make that word seem like it was never there.

Yeah, vim's original web motions work quite inconsistent in this regard. I deliberately not implemented the same for this plugin, since with subword motions and punctuation skipping, you get a lot of other unexpected before if you introduce vim's behavior here. Same thing for dw and cw not working at the end of a file: When you are at the last word of a file, there literally is not next word, so not doing anything is actually the intended behavior.

In my view, original vim actually taught many people a bad habit here of treating cw differently, when people should actually be using ce instead. If you really want to, you can map cw to ce though, which should get you your desired behavior.

I added some info on this to the docs though.

ciw does work as expected

that's cause this plugin does not change the iw text object at all ;)