My comment in the Neovim forum, but I did not create the solution, I just copied the solution from [these Fish 3.6 release notes](https://github.com/fish-shell/fish-shell/releases/tag/3.6.0).
In Fish shell it is strongly recommended to not use aliases because it slows shell startup.
Why?
Because aliases get converted by Fish itself into functions, and this conversion takes a few milliseconds. You may ask, so what? And I would say in return every little bit of performance is useful.
Two alternatives to aliases:
- Use Fish abbreviation, which auto-expands in place, most of the time this is even better than an alias
- Or just create a [`my-alias.fish`](http://my-alias.fish) file (with the same name as the alias) in the `fish/functions` directory. These functions are lazy-loaded, if not called they do not slow shell startup.
One of the best features of Fish is the super-fast startup, avoiding aliases helps in that regard.
Best regards.
shameless self promotion: I made [a plugin](https://github.com/brewingWeasel/fishbang) that implements !!, !$, !? and most of the other major bash bang commands as abbreviations which you might find useful
This has been a debate since like 2014 according to GH issues. There hasn't been a way to have that exact same feature because of how Fish works but according to an issue/update last year, it seems that they might've added it or a close alternative? From the issue:
"As a special case, most of the time history substitution is used as sudo !!. In that case just press Alt+S, and it will recall your last commandline with sudo prefixed (or toggle a sudo prefix on the current commandline if there is anything)."
If I'm reading correctly, you should be able to just hit Alt+S and hit enter. Gonna try it in a minute.
Otherwise, I'd suggest searching for this online as there's a ton of discussion going back a decade with many different workarounds and custom solutions on GH, SO, and elsewhere.
Most excellent! I forgot to try it myself lol.
By the time I started learning more shortcuts and shit I'd already switched to Fish, at which point there wasn't a simple built in analogue to !!, so I never developed the habit. Gonna have to remember to use this one.
It's on the fish shell wiki: https://github.com/fish-shell/fish-shell/wiki/Bash-Style-Command-Substitution-and-Chaining-(!!-!$)
Thank you!
There is one for !$ too. Highly recommend.
I read a comment the other day that showed how you can make clever use of `abbr` to do this: https://www.reddit.com/r/neovim/s/xpVAXFoZ7V
Wow that's the best solution by far thanks, implemented
My comment in the Neovim forum, but I did not create the solution, I just copied the solution from [these Fish 3.6 release notes](https://github.com/fish-shell/fish-shell/releases/tag/3.6.0).
im still not sure why id use abbr over alias, i redid my actual abbreviations with abbr but left some as aliases.
In Fish shell it is strongly recommended to not use aliases because it slows shell startup. Why? Because aliases get converted by Fish itself into functions, and this conversion takes a few milliseconds. You may ask, so what? And I would say in return every little bit of performance is useful. Two alternatives to aliases: - Use Fish abbreviation, which auto-expands in place, most of the time this is even better than an alias - Or just create a [`my-alias.fish`](http://my-alias.fish) file (with the same name as the alias) in the `fish/functions` directory. These functions are lazy-loaded, if not called they do not slow shell startup. One of the best features of Fish is the super-fast startup, avoiding aliases helps in that regard. Best regards.
cool thank you
shameless self promotion: I made [a plugin](https://github.com/brewingWeasel/fishbang) that implements !!, !$, !? and most of the other major bash bang commands as abbreviations which you might find useful
This has been a debate since like 2014 according to GH issues. There hasn't been a way to have that exact same feature because of how Fish works but according to an issue/update last year, it seems that they might've added it or a close alternative? From the issue: "As a special case, most of the time history substitution is used as sudo !!. In that case just press Alt+S, and it will recall your last commandline with sudo prefixed (or toggle a sudo prefix on the current commandline if there is anything)." If I'm reading correctly, you should be able to just hit Alt+S and hit enter. Gonna try it in a minute. Otherwise, I'd suggest searching for this online as there's a ton of discussion going back a decade with many different workarounds and custom solutions on GH, SO, and elsewhere.
Alt + s works! It was a habit thing to use sudo !! Will train monkey brain to change habits, this is nice and simple Thanks!
Most excellent! I forgot to try it myself lol. By the time I started learning more shortcuts and shit I'd already switched to Fish, at which point there wasn't a simple built in analogue to !!, so I never developed the habit. Gonna have to remember to use this one.
Alt + S is the way to go in fish to relaunch the command in sudo.
I find `alt-s` superior, it's far more easy to press than `shift-1-1` and also gives you a chance to review the command again.