ABBR(1)
πΈ ABBR(1) β the fish-shell bestie guide to abbreviations π
ok so real talk: this page is from fish-shell (yes queen, the shell π), and it's all about abbr β the tool that turns your lazy little shorthand into full commands. Buckle up, we're doing this together π«Ά
β¨ NAME β¨
abbr β manage fish abbreviations. that's it. that's the vibe. π
π SYNOPSIS π
ok here's the whole shape of it, no cap:
abbr --add NAME [--position command | anywhere] [-r | --regex PATTERN] [-c | --command COMMAND]
[--set-cursor[=MARKER]] ([-f | --function FUNCTION] | EXPANSION)
abbr --erase [ [-c | --command COMMAND]... ] NAME ...
abbr --rename [ [-c | --command COMMAND]... ] OLD_WORD NEW_WORD
abbr [--show] [--color WHEN]
abbr --list
abbr --query NAME ...
π¦ DESCRIPTION π¦
abbr manages abbreviations β those user-defined words that get swapped out for longer phrases the second you type them. it's giving autocorrect but for geniuses β¨
heads up bestie: only typed-in commands use abbreviations. abbreviations are not expanded in scripts. periodt. π
so like, say you run git checkout approximately four hundred times a day. make an abbreviation gco. after you type gco and hit space or enter, the full text git checkout just appears in the command line. iconic behavior honestly π
and because we're not chaotic (mostly), if you want to expand something that looks like an abbreviation without expanding it, the default Ctrl+space binding inserts a space without expanding. bless. π
an abbreviation can match a literal word, or it can match a pattern given by a regular expression. when an abbreviation matches a word, that word gets replaced by new text β called its expansion. the expansion can be a fixed new phrase, or it can be dynamically created via a fish function. this all happens after pressing space or enter, btw.
combine these features and you can literally build custom syntaxes, where a regex recognizes matching tokens and the expansion function interprets them. see the Examples section, it's a whole journey π
changed in version 3.6.0: previous versions of this allowed saving abbreviations in universal variables. that's no longer possible. existing variables will still be imported andabbr --erasewill also erase the variables. we recommend adding abbreviations toconfig.fish<#configuration> by just adding theabbr --addcommand. when you runabbr, you'll see output like this:
> abbr
abbr -a -- foo bar # imported from a universal variable, see `help abbr`
in that case you should take the part before the # comment and save it in config.fish <#configuration>, then you can run abbr --erase to remove the universal variable:
> abbr >> ~/.config/fish/config.fish
> abbr --erase (abbr --list)
alternatively you can keep them in a separate configuration file <#configuration> by doing something like the following:
> abbr > ~/.config/fish/conf.d/myabbrs.fish
this will save all your abbreviations in "myabbrs.fish", overwriting the whole file so it doesn't leave any duplicates, or restore abbreviations you had erased. of course any functions will have to be saved separately, see funcsave <>. π
π ADD SUBCOMMAND π
abbr [-a | --add] NAME [--position command | anywhere] [-r | --regex PATTERN]
[-c | --command COMMAND] [--set-cursor[=MARKER]] ([-f | --function FUNCTION] | EXPANSION)
abbr --add creates a new abbreviation. with no other options, the string NAME is replaced by EXPANSION. simple, clean, slay. β¨
- with
--position command, the abbreviation will only expand when it's positioned as a command, not as an argument to another command. with--position anywherethe abbreviation may expand anywhere in the command line. the default iscommand. π - with
--command COMMAND, the abbreviation will only expand when it's used as an argument to the givenCOMMAND. multiple--commandcan be used together, and the abbreviation will expand for each. an emptyCOMMANDmeans it will expand only when there is no command.--commandimplies--position anywhereand disallows--position command. even with differentCOMMANDs, theNAMEof the abbreviation needs to be unique. consider using--regexif you want to expand the same word differently for multiple commands. π― - with
--regex, the abbreviation matches using the regular expression given byPATTERN, instead of the literalNAME. the pattern is interpreted using PCRE2 syntax and must match the entire token. if multiple abbreviations match the same token, the last abbreviation added is used. π§ - with
--set-cursor=MARKER, the cursor is moved to the first occurrence ofMARKERin the expansion. theMARKERvalue is erased. theMARKERmay be omitted (i.e. simply--set-cursor), in which case it defaults to%. π±οΈ - with
-f FUNCTIONor--function FUNCTION,FUNCTIONis treated as the name of a fish function instead of a literal replacement. when the abbreviation matches, the function will be called with the matching token as an argument. if the function's exit status is0(success), the token will be replaced by the function's output; otherwise the token will be left unchanged. noEXPANSIONmay be given separately. π₯ - the description set by
--description=DESCRIPTIONwill be added to the completion description in the completion pager. cute AND informative π
πΈ Examples πΈ
abbr --add gco git checkout
add a new abbreviation where gco will be replaced with git checkout. the classic. the blueprint. π
abbr -a --position anywhere -- -C --color
add a new abbreviation where -C will be replaced with --color. the -- allows -C to be treated as the name of the abbreviation, instead of an option. sneaky but legal π
abbr -a L --position anywhere --set-cursor "% | less"
add a new abbreviation where L will be replaced with | less, placing the cursor before the pipe. chef's kiss π
function last_history_item
echo $history[1]
end
abbr -a !! --position anywhere --function last_history_item
this first creates a function last_history_item which outputs the last entered command. it then adds an abbreviation which replaces !! with the result of calling this function. taken together, this is similar to the !! history expansion feature of bash. we love a crossover episode π
function vim_edit
echo vim $argv
end
abbr -a vim_edit_texts --position command --regex ".+\.txt" --function vim_edit
this first creates a function vim_edit which prepends vim before its argument. it then adds an abbreviation which matches commands ending in .txt, and replaces the command with the result of calling this function. this allows text files to be "executed" as a command to open them in vim, similar to the "suffix alias" feature in zsh. genuinely obsessed π¦
abbr 4DIRS --set-cursor=! "$(string join \n -- 'for dir in */' 'cd $dir' '!' 'cd ..' 'end')"
this creates an abbreviation "4DIRS" which expands to a multi-line loop "template." the template enters each directory and then leaves it. the cursor is positioned ready to enter the command to run in each directory, at the location of the !, which is itself erased. big main character energy ngl π
abbr --command git co checkout
turns "co" as an argument to "git" into "checkout". multiple commands are possible, --command={git,hg} would expand "co" to "checkout" for both git and hg. two birds, one abbreviation π¦
β OTHER SUBCOMMANDS β
π rename
abbr --rename [ [-c | --command COMMAND]... ] OLD_NAME NEW_NAME
renames an abbreviation, from OLD_NAME to NEW_NAME. for command-specific abbreviations, the --command options must be provided to disambiguate which abbreviation to rename. yes you have to be specific, no you can't skip it π€
π show
abbr [-s | --show]
show all abbreviations in a manner suitable for import and export. it's giving "look at my collection" β¨
π¦ list
abbr [-l | --list]
prints the names of all abbreviation π
πΈ erase
abbr [-e | --erase] [ [-c | --command COMMAND]... ] NAME ...
erases the abbreviation with the given name. for command-specific abbreviations, the --command options must be provided to disambiguate which abbreviation to rename. (yes, the page really says "rename" there β we're just passing it along, don't come for me π)
π₯ query
abbr -q or --query [NAME...]
return 0 (true) if one of the NAME is an abbreviation. a little true/false moment, very binary of it π
π help
abbr -h or --help
displays help for the abbr command. when in doubt, ask for help bestie π«Ά
π Copyright π
fish-shell developers π
ok that's the whole page, you're officially an abbreviation scholar πβ¨ β this was fish-shell, version 4.9, dated Sep 08, 2026. go forth and abbreviate responsibly, ily ππ¦πΈ
π¦ where this page comes from
- arch rolling: fish 4.9.3-1 Β· GPL-2.0-only AND BSD-3-Clause AND ISC AND MIT AND PSF-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms