chrisgrieser / nvim-spider

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

Feature Request/Bug? - Strange behavior on the last word of lines #39

Closed roycrippen4 closed 6 months ago

roycrippen4 commented 9 months ago

Feature Requested

The Problem:

While spider is more consistent than vim's default w, e, and b motions in most cases, one case where spider falls short, in my opinion, is at the end of lines.

Below are several examples that show the differences between the current behaviors and expected behaviors.

Examples:

Legend: Letters encased in () show the cursor position in normal mode. | represents the position of the cursor in insert mode. \n represents the existence of a newline in the examples (This is the easiest way to visualize a newline being deleted).

Behavior:

Expected Behavior:

Example - dw on the last word of last line:


Behavior:

Expected Behavior:

Example - cw on the last word of last line:

Behavior:

Expected Behavior:

Example - dw on the last word of a line:


Behavior:

Expected Behavior:

Example - cw on the last word of last line:

The Solution:

There are two possible solutions to this problem.

  1. Do nothing. This is the most simple option because users have the ability to make their own custom patterns.
  2. Make spider end-of-line aware. If spider is aware of the the end of a line then there are two possible ways to solve this problem. a. Spider falls back to the default vim binding to avoid deleting newlines and punctuation. Maybe the more simple option? Not sure. b. Introduce a new built-in pattern to use when the end-of-line condition is met. Again, might be really simple as well. Needs investigation.

These solutions can be made opt-in or default behavior - I don't mind implementing either.

Final Thoughts:

This may be a problem that is completely unique to me. But, I do find it frustrating that punctuation and newlines get removed when I use dw or cw at the end of a line. I wanted extra input before forking/solving/submitting a PR if this is a problem that nobody else cares about besides me.

Relevant Screenshot

No response

Checklist

kevintraver commented 6 months ago

I also experience the same issues using cw and dw on the last word of a line.

chrisgrieser commented 6 months ago

This is pretty much the issue I described here: https://github.com/chrisgrieser/nvim-spider?tab=readme-ov-file#operator-pending-mode-the-case-of-cw

cw and dw behave as intended, since they move to the start of the next (sub)word. What you really want to do is use de and ce respectively. As described in the link above, you can also remap w to e in operator-pending mode, if you really prefer to use w (even though it is in my view very inconsistent.)

kevintraver commented 6 months ago

Thank you for the explanation!