history expansion by complete first word

156 Views Asked by At

Consider that I've successfully run these two commands in this order (but perhaps many commands ago):

~% ssh localhost echo
~% sshfs localhost:/ /media/copy-of-root

Now I would like to rerun the ssh command. My first instinct is to use !ssh, but this will match the sshfs command instead.

Is there a version of history expansion which will match entire first words instead of prefixes of commands? If not, is there some other robust way to choose the ssh command over the sshfs one?

1

There are 1 best solutions below

0
On

well, if you search for ssh (with a trailing space) it will find it. IMO the best alternative is to bind up and down to up-line-or-search and down-line-or-search.

bindkey '^[[A' up-line-or-search # check the exact code for your UP key...

Then you would just use:

% ssh [UP]

which would search for ssh in your history. If that is not the history instance you want, just keep searching (i.e. hitting "UP").