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?

1 Answer 1

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
1
  • Works perfectly, thank you!
    – Rafał G.
    Jul 20, 2021 at 19:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.