Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've been using bash for a decade or so and have gotten used to being able to type !$ to repeat the last argument, e.g.:

$ mkdir foo
$ cd !$
cd foo

(That last line is printed by the shell to tell you what your command evaluated to). Likewise I often to the following:

$ make_sandwich
-bash: make_sandwich: Permission denied
$ sudo !!
sudo make_sandwich

I'm really liking the fish shell, but my muscle memory is pretty established. Is there an equivalent in fish? Can I configure fish to use the same commands?

share|improve this question
up vote 12 down vote accepted

Alt-Up arrow gives you the last argument from the previous command. Subsequent pushes cycle throught prior arguments.

I haven't found a satisfactory equivalent to !!, except Up then Ctrl-A

share|improve this answer

sudo !! (or sudo bang bang) is one of my most oft used commands. I'm still using just plain old bash that has it just fine. Sorry to hear that fish doesn't implement it correctly. A little googling and I found this:

function sudo
    if test "$argv" = !!
        eval command sudo $history[1]
        command sudo $argv

There are a lot more options over on the thread here:

share|improve this answer

I found this perfect answer on the fish-users mailing list:

function bind_bang
    switch (commandline -t)[-1]
        case "!"
            commandline -t $history[1]; commandline -f repaint
        case "*"
            commandline -i !

function bind_dollar
    switch (commandline -t)[-1]
        case "!"
            commandline -t ""
            commandline -f history-token-search-backward
        case "*"
            commandline -i '$'

function fish_user_key_bindings
    bind ! bind_bang
    bind '$' bind_dollar
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.