thutt
thutt

Reputation: 650

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.

Upvotes: 0

Views: 669

Answers (2)

thutt
thutt

Reputation: 650

I found Alt+number+dot and Alt+comma in Zsh and Bash which basically answers my question:

In zsh, you can do ALT+0 ALT+.

It is a bit unwieldy to press three buttons for this, but it is built-in and works.

Upvotes: 0

Nahuel Fouilleul
Nahuel Fouilleul

Reputation: 19335

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 + _

Upvotes: 1

Related Questions