zsh-edit icon indicating copy to clipboard operation
zsh-edit copied to clipboard

One character subwords are treated differently from two+ character subwords

Open knu opened this issue 2 years ago • 3 comments

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=''

knu avatar Sep 12 '22 09:09 knu

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?

marlonrichert avatar Sep 19 '22 05:09 marlonrichert

I could add a setting, though, that lets you specify what should be the minimum length of a word.

marlonrichert avatar Sep 19 '22 05:09 marlonrichert

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 avatar Sep 19 '22 07:09 knu

@knu I ended up completely rewriting the word movement logic. Please try it out.

marlonrichert avatar May 05 '23 09:05 marlonrichert

@marlonrichert I just gave it a try and it was exactly what I had hoped for. Thank you for the hard work!

knu avatar May 05 '23 11:05 knu

@knu Glad to hear! 🥳

PS: If you enjoy using my software, please consider sponsoring me. 🙂

marlonrichert avatar May 05 '23 20:05 marlonrichert

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?

knu avatar May 08 '23 15:05 knu