0

In my zsh environment, when I try to delete last word on command line using either Ctrl + W or Opt + Delete, it is always misbehaving, eg

# start with this line below
pg_ctl --help

Trying to delete last word with either Ctrl + W or Opt + Delete, I am hoping to get

pg_ctl

instead I got

pg_ctl --

Trying to delete last word again with either Ctrl + W or Opt + Delete, I'm hoping to get

pg_ctl

but instead I got

pg_

It is so frustrating that I have to post here to seek help. Have you guys seen this and know how to fix it?

I'm running macOS Monterey, iTerms and oh-myzsh. I just tested. This happens in my bash environment too.

Thanks

ssppjj
  • 121
  • Update: Ctrl + W works correctly on my bash, but Opt + Delete is the same bad as zsh – ssppjj May 25 '23 at 17:16
  • Update: I primarily use iTerm2. I just tested on Terminal and see the same. So it's not related to iTerm2. – ssppjj May 25 '23 at 17:17

1 Answers1

1

You and the shell seem to have different ideas on which characters are parts of a word and which aren't.

For zsh, you should read chapter 4.3.4: Words, Regions and Marks of the zsh User Guide. Depending on which editing mode you're using, you might be able to get what you want by manipulating the $WORDCHARS variable (it contains a list of non-alphanumeric characters that should also be considered parts of a word).

(Disclaimer: I don't know much about current versions of zsh and especially not of oh-my-zsh. My job takes me to many systems, often stripped-down to the minimum required, some with fancy configurations; so I've got used to working with "plain vanilla" shell configuration. I have a fairly minimal set of shell customizations I might set up on systems I visit often, but I can live without them if necessary; I understand many professional sysadmins generally end up with shell configurations like that eventually.)

For bash, if your "delete last word" keystroke is associated to readline library function backward-kill-word (as by default), it considers only letters and numbers as word components; any other characters will separate words from each other.

In bash version 4.0 and newer, there should be an alternative readline function named shell-backward-kill-word, which might suit your needs better.See this question for more details.

telcoM
  • 96,466