chrisgrieser / nvim-spider

Use the w, e, b motions like a spider. Move by subwords and skip insignificant punctuation.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

roycrippen4 opened this issue · comments

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:

  • Spider will do nothing when you use dw on the last word of the last line.

Expected Behavior:

  • Spider should remove the word up to, but not including, the punctuation when using dw on the last word of the last line.

Example - dw on the last word of last line:

  • Current: Sample (t)ext\n. => Sample (t)ext.\n
  • Expected: Sample (t)ext\n. => Sample ().\n

Behavior:

  • Spider will only put the cursor into insert mode when using cw on the last word of the last line.

Expected Behavior:

  • Spider should remove the word up to, but not including, the punctuation when using cw on the last word of the last line.

Example - cw on the last word of last line:

  • Current: Sample (t)ext\n. => Sample |text.\n
  • Expected: Sample (t)ext\n. => Sample |.\n

Behavior:

  • Spider will remove newlines and punctuation when using dw on the last word of a line.

Expected Behavior:

  • Spider should remove the word up to, but not including, the punctuation when using dw on the last word of a line.

Example - dw on the last word of a line:

  • Current: Sample (t)ext\n. => Sample ()
  • Expected: Sample (t)ext\n. => Sample ().\n

Behavior:

  • Spider will remove newlines and punctuation when using cw on the last word of a line.

Expected Behavior:

  • Spider should remove the word up to, but not including, the punctuation when using cw on the last word of a line.

Example - cw on the last word of last line:

  • Current: Sample (t)ext\n. => Sample |
  • Expected: Sample (t)ext\n. => Sample |.\n

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

  • The feature would be useful to more users than just me.

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

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.)

Thank you for the explanation!