Consider punctuation when moving forward#51
Conversation
Adding these two entries to forward_to_next_list should cause forward motion to additionally stop at punctuation. This prevents the occasional undesired behavior of consuming punctuation when using dw or cw. Tested using Neovim v0.11.4
Ensure that dw deletes the last character of the last word of the line without touching the next line. CamelCaseMotion was inconsistently grabbing the next line when deleting the last word of the line but this should prevent that from happening.
|
Added another commit that improves handling of the last word of a line. This still doesn't fix deleting the very last word of the file but that's a rare case. |
|
It turns out that it still crosses over to the next line if there is whitespace at the beginning of the line. I haven't figured out how to prevent this. |
When on the last word of the current line, interrupt the 'dw' command and replace it with a 'd$' to ensure the motion does not cross over the new line
Replace 'dw' with 'd$' also at the last word of the last line of the file.
Also replace de with d$ only when at the last word of the file. This fixes de not deleting the last character as it should.
|
Several months later, I finally got around to looking at this again. I'm not sure if this is the most elegant fix but dw and de should be exhibiting normal behavior. Meaning:
During my testing, I noticed that using de at the last character of a line deletes all blank lines up until the first non-blank line and then also deletes the first word of that line. But, if that line only has one word on it, it doesn't delete the last character! 🤷 I rarely, if ever, use de at the last character so it won't affect me but it is something to keep in mind. |
Instead of just dw, also make sure cw and yw don't cross the new line when on the last word of the current line.
Refactor dw, cw, and yw to intercept the w motion before it gets executed. Instead of cancel/replaying the motion, if the final step involves crossing a newline, use a visual end-of-line selection instead. Otherwise, it should behave like normal camelcasemotion.
|
Okay, hopefully, this is the last change.
I did get a decent amount of help from ChatGPT so I don't fully understand why this works. I haven't found any bugs in my testing yet but please let me know if you find any. Something tells me this could have been solved in a simpler way like, adding a newline character to the |
Adding these two entries to
forward_to_next_listshould cause forward motion to additionally stop at punctuation just like vim default behavior. This prevents the occasional undesired behavior of consuming punctuation when usingdworcw.Tested using Neovim v0.11.4.
I am not good with regex so I asked ChatGPT to create these two lines for me. It seems to be working but I'm sure there are cases I haven't tested.