In Bash, we can use Alt+number+. to select the nth argument of previous commands, and Alt+, to select the previous commands. They cycles through the history.
For example:
$ ls 1 2
$ echo 10 20
Now press and hold Alt, and press 0 then dot, it will show "echo". Without releasing Alt, press . again, it will show "ls". Use 1 in the same operation will show 10 and 1, etc. Pressing Alt and comma shows the whole command line in the history. Also Alt and . show the last argument of the commands in history.
Note that all of these operations just insert the argument (or whole command line) to the current cursor. They don't change what's already there in the current command line.
I am using Zsh and the latest Oh-My-Zsh package but it seems the behavior is different:
Zsh has the Alt+, to show the last argument of commands.
The Alt+0+. is the same as Bash (shows the comman), but Alt+number+. shows the last nth argument, i.e., Alt+1+. in above case shows 20 and 2.
The Alt+, doesn't display the whole commands in history.
How to do the same thing in Zsh? Thanks.
Looking for this feature I came across this blogpost by Christian Neukirchen:
In this text,
M
is referring to theMeta
key, akaAlt
. So in theory this should work out of the box, as Christian says. So I went to try this and yes, it did work out of the box.The zle widgets in charge of this behavior are
insert-last-word
─which isALT
+.
─ anddigit-argument
─which isALT
+Number
.Here's the relevant
bindkey
output:so check that those appear and try again. You can update your original question with the output of the shown
bindkey
command to help narrow down the issue, or open one directly in oh-my-zsh with the details.