| Shortcut | Description |
| --- | --- |
+| `^A ←` _/_ `^E →` | Move to line beginning/end |
| `Alt ←` _/_ `Alt →` | Move word |
| `^U` | Delete to beginning |
| `^W` | Delete to previous `/` |
| `Alt L` | List directory on cursor |
{: .-shortcuts}
-## Function
+## Variables
-### Writing functions
+### Defining and erasing
```fish
-function my_function --description "My description"
- ···
-end
+set my_variable "Hello from Fish!"
```
-### Conditional
-
```fish
-if test -f foo.txt
- ···
-else if test -f bar.txt
- ···
-else
- ···
-end
+set --erase my_variable
```
-### Combining tests
+### Incrementing and decrementing
```fish
-if test -f foo.txt && test -f bar.txt
+set my_variable (math $my_variable + 1)
+set my_variable (math $my_variable - 1)
```
+### Slicing
+
```fish
-if test -f foo.txt -a -f bar.txt
+set my_variable $another_variable[1..10]
+set my_variable $another_variable[2..]
+set my_variable $another_variable[..-2]
```
+## Arithmetic
+
```fish
-if test \( -f foo.txt \) -a -f \( bar.txt \)
+math 1 + 2
```
-### Events
+| Operator | Performs |
+| --- | --- |
+| `+` | Addition |
+| `-` | Subtraction |
+| `*` | Multiplication |
+| `/` | Division |
+| `%` | Modulo |
+| `^` | Exponentiation |
+{: .-shortcuts}
-#### Emitting
+## String manipulation
```fish
-emit my_event
+string match --regex --entire 'Fish' 'Hello from Fish!'
```
-#### Listening
-
```fish
-function myhook --on-event my_event
- ···
-end
+string replace --regex 'Fish' 'fish' 'Hello from Fish!'
```
-This lets you hook onto events, such as `fish_prompt`.
-
-## Completions
+| Pattern | Matches |
+| --- | --- |
+| `x?` | Zero or one `x` chars |
+| `x*` | Any count `x` chars |
+| `x+` | One or more `x` chars |
+| `x{n}` | n times `x` chars |
+| `x{n,m}` | n to m times `x` chars |
+| `x{n,}` | n or more times `x` chars |
+| `x{n,}` | n or more times `x` chars |
+| `[xy] ` | `x` or y char |
+| `[^xy]` | not `x` or y char |
+{: .-shortcuts}
-### Creating completions
+| Class | Description |
+| --- | --- |
+| `\w` | Word character |
+| `\d` | Digit character |
+| `\W` | Not word character |
+| `\D` | Not digit character |
+{: .-shortcuts}
-#### ~/.fish/completions/mycommand.fish
+### Conditionals
```fish
-complete -c mycommand ...
-complete -c mycommand ...
-complete -c mycommand ...
+if test $my_variable -lt $another_variable
+ ···
+else if test $my_variable -eq $another_variable
+ ···
+else
+ ···
+end
```
-### Options
+| Operator | Meaning |
+| --- | --- |
+| `-lt` | [L]ess [t]han |
+| `-eq` | [Eq]ual |
+| `-gt` | [G]reater [t]han |
+| `-le` | [L]ess than or [e]qual to |
+| `-ge` | [G]reater than or [e]qual to |
+| `-f` | [F]ile exists |
+| `-d` | [D]irectory exists |
+| `-r` | File or directory exists and [r]eadable |
+| `-w` | File or directory exists and [w]ritable |
+| `-x` | File or directory exists and e[x]ecutable |
+{: .-shortcuts}
+
+## Loops
```fish
-complete \
- -c # command
- -s # short option
- -l # long option
- -r, --require-parameter
- -f, --no-files
- -x # exclusive (-r -f)
- -n '__fish_use_subcommand' # condition
- --description ".."
+for i in (seq 1 10)
+ ...
+end
```
-#### Example
+## Command substitution
```fish
- complete -c $cmd \
--n '__fish_use_subcommand' \
--x -a hello \
---description 'lol'
+set my_variable (math $my_variable + 1)
```
-### Conditions
-
-| Condition | Description
-| --- | ---
-| `-n __fish_complete_directories STRING DESCRIPTION` | performs path completion on STRING, allowing only directories, and giving them the description DESCRIPTION.
-| `-n __fish_complete_path STRING DESCRIPTION` | performs path completion on STRING, giving them the description DESCRIPTION.
-| `-n __fish_complete_groups` | prints a list of all user groups with the groups members as description.
-| `-n __fish_complete_pids` | prints a list of all processes IDs with the command name as description.
-| `-n __fish_complete_suffix SUFFIX` | performs file completion allowing only files ending in SUFFIX. The mimetype database is used to find a suitable description.
-| `-n __fish_complete_users` | prints a list of all users with their full name as description.
-| `-n __fish_print_filesystems` | prints a list of all known file systems. Currently, this is a static list, and not dependent on what file systems the host operating system actually understands.
-| `-n __fish_print_hostnames` | prints a list of all known hostnames. This functions searches the fstab for nfs servers, ssh for known hosts and checks the /etc/hosts file.
-| `-n __fish_print_interfaces` | prints a list of all known network interfaces.
-| `-n __fish_print_packages` | prints a list of all installed packages. This function currently handles Debian, rpm and Gentoo packages.
-| `-n __fish_use_subcommand` |
-| `-n __fish_seen_subcommand_from init` |
+## Functions
-#### Example
+### Defining and erasing
```fish
-complete -c ruby -s X -x -a '(__fish_complete_directories (commandline -ct))' --description 'Directory'
+function my_function --description "My description"
+ ···
+end
```
-### Examples
+```fish
+functions --erase my_function
+```
-Start each example with `complete -c cmdname`
+### Event handling
```fish
--x
- # no filename completion
+function my_hook --on-event my_event
+ ···
+end
```
+## Events
+
+### Emitting
+
```fish
--s d -x -a "read skip"
- # -d {read|skip}
+emit my_event
```
+
+## Abbreviations
+
+### Defining and erasing
+
```fish
--s d -x
- # -d <something>
+abbr --add my_abbreviation echo "Hello from Fish!"
```
```fish
--s f -r
- # -f FILE
+abbr --erase my_abbreviation
```
+## Completions
+
+### Defining and erasing
+
```fish
--s f -l force
- # -f, --force
+complete --command mycommand --arguments 'install uninstall'
+complete --command mycommand --short-option 'h' --long-option 'help' --description 'Display help'
```
```fish
--a "(cat /etc/passwd | cut -d : -f 1)"
- # first argument as filename
+complete --command mycommand --erase
```
+
+| Option | Description |
+| --- | --- |
+| `--arguments` | Arguments to command itself or option |
+| `--short-option` | Short option |
+| `--long-option` | Long option |
+| `--no-files` | Don't suggest files |
+| `--force-files` | Suggest files |
+| `--condition` | Display hint only when condition is true |
+| `--description` | Description |
+{: .-shortcuts}
+
+## Useful built-in functions
+
+| Condition | Description
+| --- | ---
+| `-n __fish_complete_directories STRING DESCRIPTION` | performs path completion on STRING, allowing only directories, and giving them the description DESCRIPTION.
+| `-n __fish_complete_path STRING DESCRIPTION` | performs path completion on STRING, giving them the description DESCRIPTION.
+| `-n __fish_complete_groups` | prints a list of all user groups with the groups members as description.
+| `-n __fish_complete_pids` | prints a list of all processes IDs with the command name as description.
+| `-n __fish_complete_suffix SUFFIX` | performs file completion allowing only files ending in SUFFIX. The mimetype database is used to find a suitable description.
+| `-n __fish_complete_users` | prints a list of all users with their full name as description.
+| `-n __fish_print_filesystems` | prints a list of all known file systems. Currently, this is a static list, and not dependent on what file systems the host operating system actually understands.
+| `-n __fish_print_hostnames` | prints a list of all known hostnames. This functions searches the fstab for nfs servers, ssh for known hosts and checks the /etc/hosts file.
+| `-n __fish_print_interfaces` | prints a list of all known network interfaces.
+| `-n __fish_print_packages` | prints a list of all installed packages. This function currently handles Debian, rpm and Gentoo packages.
+| `-n __fish_use_subcommand` |
+| `-n __fish_seen_subcommand_from init` |
### Mobile
-| Resolution | DPPX | Actual resolution | DPPI | Actual PPI | Size | Devices |
-| --- | --- | --- | --- | --- | --- | --- |
-| 320 x 480 | @1x | 320 x 480 | 163 ppi | 163 ppi | 3.5" | iPhone 2G/3G/3GS |
-| 320 x 480 | @2x | 640 x 960 | 163 ppi | 326 ppi | 3.5" | iPhone 4/4S |
-| 320 x 568 | @2x | 640 x 1136 | 163 ppi | 326 ppi | 4" | iPhone 5/5C/5S |
-| 320 x 568 | @2x | 640 x 1136 | 163 ppi | 326 ppi | 4" | iPhone SE |
-| 375 x 667 | @2x | 750 x 1334 | 163 ppi | 326 ppi | 4.7" | iPhone 6/6S/7/8/SE2 |
-| 414 x 736 | @3x | 1242 x 2208 | 133 ppi | 401 ppi | 5.5" | iPhone 6+/6S+/7+/8+ |
-| 414 x 896 | @2x | 828 x 1792 | 162 ppi | 326 ppi | 6.1" | iPhone Xr/11 |
-| 375 x 812 | @3x | 1125 x 2436 | 152 ppi | 458 ppi | 5.8" | iPhone X/Xs/11 Pro |
-| 414 x 896 | @3x | 1242 x 2688 | 162 ppi | 458 ppi | 6.5" | iPhone Xs Max/11 Pro Max |
-| --- | --- | --- | ---- | --- | --- | --- |
-| 360 x 640 | @2x | 720 x 1280 | 153 ppi | 306 ppi | 4.8" | Galaxy S3 |
-| 360 x 640 | @3x | 1080 x 1920 | 147 ppi | 441 ppi | 5" | Galaxy S4 |
-| 360 x 640 | @3x | 1080 x 1920 | 144 ppi | 432 ppi | 5.1" | Galaxy S5 |
-| 360 x 640 | @4x | 1440 x 2560 | 144 ppi | 577 ppi | 5.1" | Galaxy S6/Edge |
+| Resolution | DPPX | Actual resolution | DPPI | Actual PPI | Size | Devices |
+| --- | --- | --- | --- | --- | --- | --- |
+| 320 x 480 | @1x | 320 x 480 | 163 ppi | 163 ppi | 3.5" | iPhone 2G/3G/3GS |
+| 320 x 480 | @2x | 640 x 960 | 163 ppi | 326 ppi | 3.5" | iPhone 4/4S |
+| 320 x 568 | @2x | 640 x 1136 | 163 ppi | 326 ppi | 4" | iPhone 5/5C/5S |
+| 320 x 568 | @2x | 640 x 1136 | 163 ppi | 326 ppi | 4" | iPhone SE |
+| 375 x 667 | @2x | 750 x 1334 | 163 ppi | 326 ppi | 4.7" | iPhone 6/6S/7/8/SE2 |
+| 414 x 736 | @3x | 1242 x 2208 | 133 ppi | 401 ppi | 5.5" | iPhone 6+/6S+/7+/8+ |
+| 414 x 896 | @2x | 828 x 1792 | 163 ppi | 326 ppi | 6.1" | iPhone Xr/11 |
+| 375 x 812 | @3x | 1125 x 2436 | 152 ppi | 458 ppi | 5.8" | iPhone X/Xs/11 Pro |
+| 414 x 896 | @3x | 1242 x 2688 | 162 ppi | 458 ppi | 6.5" | iPhone Xs Max/11 Pro Max |
+| 390 x 844 | @3x | 1170 x 2532 | 153 ppi | 460 ppi | 6.1" | iPhone 12/12 Pro/13/13 Pro |
+| 428 x 926 | @3x | 1284 x 2778 | 152 ppi | 458 ppi | 6.7" | iPhone 12 Pro Max/13 Pro Max |
+| 375 x 812 | @3x | 1080 x 2540 | 158 ppi | 476 ppi | 5.4" | iPhone 13 Mini |
+| --- | --- | --- | ---- | --- | --- | --- |
+| 320 x 533 | @1.5x | 480 x 800 | 155 ppi | 233 ppi | | Galaxy S |
+| 320 x 533 | @1.5x | 480 x 800 | 145 ppi | 217 ppi | | Galaxy S2 |
+| 360 x 640 | @2x | 720 x 1280 | 153 ppi | 306 ppi | 4.8" | Galaxy S3 |
+| 320 x 533 | @1.5x | 480 x 1200 | 155 ppi | 233 ppi | | Galaxy S3 Mini |
+| 360 x 640 | @3x | 1080 x 1920 | 147 ppi | 441 ppi | 5" | Galaxy S4 |
+| 360 x 640 | @3x | 1080 x 1920 | 144 ppi | 432 ppi | 5.1" | Galaxy S5 |
+| 360 x 640 | @4x | 1440 x 2560 | 144 ppi | 577 ppi | 5.1" | Galaxy S6/Edge |
+| 360 x 640 | @4x | 1440 x 2560 | 144 ppi | 576 ppi | 5.1" | Galaxy S7 |
+| 360 x 640 | @4x | 1440 x 2560 | 134 ppi | 534 ppi | 5.5" | Galaxy S7 Edge |
+| 360 x 740 | @4x | 1440 x 2960 | 142 ppi | 568 ppi | 5.8" | Galaxy S8 |
+| 412 x 846 | @4x | 1440 x 2960 | 133 ppi | 531 ppi | 6.2" | Galaxy S8 Plus |
+| 360 x 740 | @4x | 1440 x 2960 | 142 ppi | 568 ppi | 5.8" | Galaxy S9 |
+| 412 x 846 | @4x | 1440 x 2960 | 133 ppi | 531 ppi | 6.2" | Galaxy S9 Plus |
{: .-headers}
### Tablet