0

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.

thutt
  • 640
  • 5
  • 18

2 Answers2

1

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

Nahuel Fouilleul
  • 18,726
  • 2
  • 31
  • 36
  • This can be found in my .zshrc now, too ;) I only changed the shortcut to Alt+, as comma is left to the dot key, which made a bit more sense to me. I choose this as the accepted answer as it is more convenient than the [built-in solution](https://stackoverflow.com/a/48230185/3449673) I found... and it encouraged me to learn some [ZLE](http://zsh.sourceforge.net/Guide/zshguide04.html). Thanks! – thutt Jan 16 '18 at 09:25
0

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

In zsh, you can do ALT+0+.

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

thutt
  • 640
  • 5
  • 18