How to have Ctrl+[key] modify a full word and Alt+[key] modify a partial word in ZSH?

How to have Ctrl+[key] modify a full word and Alt+[key] modify a partial word in ZSH?

I'm in the process of switching to ZSH as my primary shell and am missing one small configuration option I had in Bash.

I have bash set up so that if I use Ctrl+Left/Right/Backspace/Delete, it will move or delete a full word, and if I use Alt+Left/Right/Backspace/Delete, it will move or delete a partial word.

By a full word, I mean that pressing Ctrl+RightArrow on aaa/bbb/ccc would move the cursor from the start to the end of the string (i.e. whitespace separates). By a partial word, I mean that pressing Alt+RightArrow on the same string would only move the cursor to just before the first / (any non-alphanumeric character separates). A similar principle is applied to the other similar keys.

The issue I have run into is that I can't find commands to assign using bindkey that distinguish between these different kinds of input modifications.

How can I achieve this kind of functionality in my ZSH configuration?

答案1

Zsh unfortunately does not ship with widgets that do exactly that and it’s non-trivial to write your own. However, you can get ready-made versions of these as part of my Zsh Edit plugin.

相关内容