Search code examples
zsh

Insert first word of previous command in ZSH command line


In zsh (and bash), I can do ALT+. to insert the last argument of the previous command into the command line.

Is there something similar for the first word?

Example: After running /bin/ls -l /tmp, I want it to insert /bin/ls.


Solution

  • found this in a .zshrc

    insert-first-word () { zle insert-last-word -- -1 1 }
    zle -N insert-first-word
    bindkey '^[_' insert-first-word
    

    then alt + _