2

I've got zsh 5.8.1 running on Ubuntu 22.04. When I've got some text on the prompt and I type Ctrl+u, it clears the line as expected. However, when I then type Ctrl+y, it only displays

$ ^Y

What could be causing the readline buffer not to be pasted?

Here's my .zshrc:

export ZSH="$HOME/.oh-my-zsh"
ZSH_THEME=""

plugins=(
    colored-man-pages
    colorize
    git
    zsh-autosuggestions
    zsh-interactive-cd
    vi-mode
)

ZSH_AUTOSUGGEST_STRATEGY=(history completion)

source $ZSH/oh-my-zsh.sh
unalias ls
unalias ll
unalias lsa

unalias gst
alias gs='git status'
alias gcob='git checkout -b'

bindkey "^[[1;5C" forward-word
bindkey "^[[1;5D" backward-word
bindkey "^[." insert-last-word

_sig_array=($(kill -l))

_return_status() {
    ret=$?
    if [ $ret -ne 0 ]; then
        if [ $ret -le 128 ]; then
            echo $ret
        else
            sig=$(( $ret - 128 ))
            desc=$_sig_array[sig]
            if [ "$desc" != INT -a "$desc" != TSTP ]; then
                echo SIG$desc
            fi
        fi
    fi
}

_return_status_formatted() {
    out=$(_return_status)
    if [ -n "$out" ]; then
        echo "%F{red}[$out]%f "
    fi
}

_current_branch_formatted() {
    out=$(current_branch)
    if [ -n "$out" ]; then
        if [ -n "$(git status -s | grep -v '^\?')" ]; then
            color=magenta
        else
            color=cyan
        fi
        echo "%F{$color}(git:$out)%f "
    fi
}

export PS1='%F{blue}%n%f@%F{green}%m%f:%F{red}%~%f $ $(_return_status_formatted)$(_current_branch_formatted)'
3
  • The zsh shell does not use Readline, to my knowledge.
    – Kusalananda
    Commented Jan 10, 2023 at 14:43
  • Perhaps I used the wrong term. Is the emacs-style <kbd>Ctrl</kbd>+<kbd>y</kbd> functionality tied to readline? Commented Jan 10, 2023 at 14:44
  • 1
    Are you using the emacs mode? (bindkey -e) Commented Jan 10, 2023 at 15:07

1 Answer 1

3
+50

zsh will use vi key bindings by default if the $EDITOR or $VISUAL variable contains vi (it then assumes you prefer vi).

^Y to paste is an emacs key binding (the vi equivalent would be p/P).

Add a:

bindkey -e

to your ~/.zshrc to indicate that you want emacs key bindings regardless of your editor choice (same as in tcsh). Or set -o emacs (same as in ksh).


Some other notes on your ~/.zshrc:

bindkey "^[." insert-last-word

is already there by default in emacs mode, so you shouldn't need that.

There's already a builtin $signals array (beware it starts at EXIT == 0, so you need $signals[signum+1] to get the name from the number).

Behaviour for grep -v '^\?' is unspecified. Use grep -v '^?' to remove the lines that start with ?, or grep -v '^\\?' to remove the ones that start with \?.

It's a good habit to declare variables local to your functions if they're not intended to be global.

See also [[ $desc = (INT|TSTP) ]] || echo SIG$desc.

Generally, like in other shells, the -a operator of the [ builtin is deprecated.

Here, you could use ((...)) consistently:

_return_status() {
    local sig desc ret="$?"
    if (( ret != 0 )); then
        if (( ret <= 128 )); then
            echo $ret
        else
            (( sig = ret - 128 ))
            desc=$signals[sig+1]
            if [[ $desc != (INT|TSTP) ]] echo SIG$desc
        fi
    fi
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .