zsh-edit
zsh-edit copied to clipboard
One character subwords are treated differently from two+ character subwords
Describe the bug
I'm not sure if this is intentional, but subword operations depend on the length and look inconsistent.
Steps To Reproduce
Example 1
# Given this behavior:
% ee foo
# _ <- cursor is at `e`
# Type M-x forward-subword
% ee foo
# _ <- cursor stops at the space
# I'd expect the same if it was a one character subword:
% e foo
# _ <- cursor is at `e`
# Type M-x forward-subword
Example 2
# Given this behavior:
% anHour 60
# _ <- cursor is at `a`
# Type M-x kill-subword
% Hour 60
# _ <- Only `an` is deleted as one subword
# I'd expect the same if it was a one character subword:
% aMinute 60
# _ <- cursor is at `a`
# Type M-x kill-subword
Expected behavior
Example 1
% e foo
# _ <- cursor is at `e`
# M-x forward-subword
% e foo
# _ <- cursor should stop at the space
Example 2
% aMinute 60
# _ <- cursor is at `a`
# M-x kill-subword
% Minute 60
# _ <- Only `a` should be deleted as one subword
Observed behavior
Example 1
% e foo
# _ <- cursor is at `e`
# M-x forward-subword
% e foo
# _ <- cursor jumps over the space
Example 2
% aMinute 60
# _ <- cursor is at `a`
# M-x kill-subword
% 60
# _ <- `aMinute` is deleted as one subword
Environment:
- OS: macOS
- Terminal: iTerm
- Zsh version: 5.9
- Repo version: * main 4a8fa59 Improve "insert word" cycling logic
Additional context
WORDCHARS=''
Yes, it's intentional. If you want to move just one character, you can already do that with other keystrokes. 🙂
Is there a particular reason why you'd want it to work this way? Why would you invoke word movement, if you wanted to move just one character?
I could add a setting, though, that lets you specify what should be the minimum length of a word.
Oh yeah, please. 🙏 Example 1 above often hits me hard because I use a lot of one or two letter aliases. Every time I want to run "command2 file.ext" right after running "command1 file.ext", I'm quite used to typing C-p C-a M-d (kill-subword) command2 RET in the Emacs-like keymap. But when the command1 happens to be a one-letter word, it will fail because of the lack of space removed by kill-subword and that bugs me. All I want is remove a (sub-)word and replace it with another, so I'm not ready to think about the space at all. I hope you see what I mean.
@knu I ended up completely rewriting the word movement logic. Please try it out.
@marlonrichert I just gave it a try and it was exactly what I had hoped for. Thank you for the hard work!
Thanks, I got back from a five-day holiday, I tried it even further and noticed backward movements radically changed. It's indeed consistent, but it's not what I'm used to. Maybe there could be an option to make a backward movement always land at the beginning of each subword instead of the end of the previous word, I guess?