1

I'm using answers from this question so that I can cut longer/shorter parts of text when I press Ctrl+W or Alt+Backspace respectively. Specifically I have this in my .zshrc to add the Alt+Backspace behavior (Ctrl+W is built-in)

backward-kill-dir () {
    local WORDCHARS=''
    zle backward-kill-word
}
zle -N backward-kill-dir
bindkey '^[^?' backward-kill-dir

This works fine for killing text, but then pasting it doesn't work as expected. Let's say I have this text:

A quick brown fox

If I press Ctrl+W four times and then press Ctrl+Y, the entire text will be cut and then pasted back. But if I have this text:

a-quick-brown-fox

and I press Alt+Backspace four times and then Ctrl+Y, it will cut the text as expected but only paste

a-

How can I make the latter also paste the entire text?

AdminBee
  • 22,803
Rafał G.
  • 125

1 Answers1

3

Built-in kill widgets replace the previous content of the internal clipboard unless the previous command was also a kill action. You need to indicate that your custom widget is a kill action by calling the zle builtin to set the kill flag.

backward-kill-dir () {
    local WORDCHARS=''
    zle backward-kill-word
    zle -f kill
}
zle -N backward-kill-dir
bindkey '^[^?' backward-kill-dir