FISH-INTERACTIVE(1)
π FISH-INTERACTIVE π
okay so bestie, this is the FISH-INTERACTIVE(1) page from the fish-shell docs, and it's literally the whole reason fish is so nice to actually use β like, interactively, on the daily, not just for writing scripts. fish has a bunch of features that make the command line feel less like a punishment and more like a vibe, and we're gonna walk through them in the next few sections. π«Ά
fish does its thing by taking commands in the fish language β if you need the deets on that, go peek at The fish Language π.
β¨ HELP β¨
fish has an extensive help system, bestie. use the help command to get help on a specific subject or command. for instance, typing help syntax displays the syntax section of this documentation. iconic, right? π
fish also ships man pages for its commands, and it translates the help pages into man pages. so like, man set will show you the documentation for set as a man page. slay. π
you can also get help on a specific builtin with the -h parameter. for example, to obtain help on the fg builtin, either type fg -h or help fg. easy.
the main page can be viewed via help index (or just help) or man fish-doc. and the tutorial? that's help tutorial or man fish-tutorial. you're welcome. πΈ
π¦ AUTOSUGGESTIONS π¦
fish suggests commands as you type, based on command history, completions, and valid file paths. as you type commands, you'll see a suggestion offered after the cursor, in a muted gray color (which can be changed with the fish_color_autosuggestion variable). it's giving psychic but make it shell. π₯
- to accept the autosuggestion (replacing the command line contents), press β (right) or Ctrl+F.
- to accept the first suggested word only, press Alt+β (alt-right) or Alt+F.
if the autosuggestion is not what you want, just ignore it β ngl it won't execute unless you accept it. no pressure. π
autosuggestions are a powerful way to quickly summon frequently entered commands, by typing the first few characters. they're also an efficient technique for navigating through directory hierarchies. main character energy for real. π
if you don't like autosuggestions, you can disable them by setting $fish_autosuggestion_enabled to 0:
set -g fish_autosuggestion_enabled 0
π TAB COMPLETION π
tab completion is a time-saving feature of any modern shell. when you type Tab, fish tries to guess the rest of the word under the cursor. if it finds exactly one possibility, it inserts it β periodt. if it finds more, it inserts the longest unambiguous part and then opens a menu (the "pager") that you can navigate to find what you're looking for. β¨
the pager can be navigated with the arrow keys, PageUp / PageDown, Tab or Shift+Tab. pressing Ctrl+S (the pager-toggle-search binding β / in vi mode) opens up a search menu that you can use to filter the list. lowkey a lifesaver. π
fish provides some general purpose completions, like for commands, variable names, usernames or files.
it also provides a large number of program-specific scripted completions. most of these completions are simple options like the -l option for ls, but a lot are more advanced. for example:
manandwhatisshow the installed manual pages as completions.makeuses targets in theMakefilein the current directory as completions.mountuses mount points specified infstabas completions.apt,rpmandyumshow installed or installable packages.
you can also write your own completions or install some you got from someone else. for that, see Writing your own completions π§.
completion scripts are loaded on demand, like functions are. the difference is the $fish_complete_path list is used instead of $fish_function_path. typically you can drop new completions in ~/.config/fish/completions/<name-of-command>.fish and fish will find them automatically. π
π SYNTAX HIGHLIGHTING π
fish interprets the command line as it's typed and uses syntax highlighting to provide feedback. the most important feedback is the detection of potential errors β by default, errors are marked red. π¨
detected errors include:
- Non-existing commands.
- Reading from or appending to a non-existing file.
- Incorrect use of output redirects.
- Mismatched parenthesis.
to customize the syntax highlighting, you can set the environment variables listed in the Variables for changing highlighting colors section.
fish also provides pre-made color themes you can pick with fish_config. running just fish_config opens a browser interface, or you can use fish_config theme from fish:
# disable nearly all coloring
fish_config theme choose none
# restore fish's default theme
fish_config theme choose default
or, to see all themes, right in your terminal:
fish_config theme show
to update the theme of all shell sessions without restarting them, first have those sessions define an event handler by adding the following to your config.fish and restarting them:
function apply-my-theme --on-variable=my_theme
fish_config theme choose $my_theme
end
then, set the corresponding universal variable from any session:
> set -U my_theme lava
> set -U my_theme snow-day
π Syntax highlighting variables π
the colors used by fish for syntax highlighting can be configured by changing the values of various variables. the value of these variables can be one of the colors accepted by the set_color command. options accepted by set_color like --foreground=, --background=, --bold, --dim, --italics, --reverse, --strikethrough, --underline and --underline-color= are also accepted. so many options, so much power. π
example: to make errors highlighted and red, use:
set fish_color_error red --bold
okay so the following variables are available to change the highlighting colors in fish β and bestie, we are going through every single one, no skips π β¨
fish_color_normalβ default color πfish_color_commandβ commands likeechoβ¨fish_color_builtinβ builtin commands likecdandset- this falls back on the command color if unset π«Άfish_color_functionβ user-defined functions - this falls back on the command color if unset π¦fish_color_keywordβ keywords likeif- this falls back on the command color if unset πΈfish_color_quoteβ quoted text like"abc"πfish_color_redirectionβ IO redirections like>/dev/nullπ₯fish_color_endβ process separators like;and&βfish_color_errorβ syntax errors πfish_color_paramβ ordinary command parameters πfish_color_valid_pathβ parameters and redirection targets that are filenames (if the file exists) πfish_color_optionβ options starting with"-", up to the first"--"parameter πfish_color_commentβ comments like'# important'πfish_color_selectionβ selected text in vi visual mode πfish_color_operatorβ parameter expansion operators like*and~π§fish_color_escapeβ character escapes like\nand\x70πfish_color_autosuggestionβ autosuggestions (the proposed rest of a command) πfish_color_cwdβ the current working directory in the default prompt πfish_color_cwd_rootβ the current working directory in the default prompt for the root user πfish_color_userβ the username in the default prompt π«Άfish_color_hostβ the hostname in the default prompt πΈfish_color_host_remoteβ the hostname in the default prompt for remote sessions (likessh) π¦fish_color_statusβ the last command's nonzero exit code in the default prompt πfish_color_cancelβ the'^C'indicator on a canceled command πfish_color_search_matchβ history search matches and selected pager items (background only) πfish_color_history_currentβ the current position in the history for commands likedirhandcdhπ
If a variable isn't set or is empty after subtracting any --theme=THEME options, fish usually tries $fish_color_normal, except for: π
$fish_color_builtinand$fish_color_function, where they try$fish_color_commandfirst. π$fish_color_keyword, where it tries$fish_color_commandfirst. π$fish_color_option, where it tries$fish_color_paramfirst. π
okay so one last little color rule before we move on, bestie:
- For
$fish_color_valid_path, if that doesn't have a color, but only modifiers, it adds those to the color that would otherwise be used, like$fish_color_param. But if valid paths have a color, it uses that and adds in modifiers from the other color.
π¨ Pager color variables π¨
fish will sometimes present a list of choices in a table, called the pager. Yes, it's giving menu energy. π
Example: to set the background of each pager row, use:
set fish_pager_color_background --background=white
To have black text on alternating white and gray backgrounds:
set fish_pager_color_prefix black
set fish_pager_color_completion black
set fish_pager_color_description black
set fish_pager_color_background --background=white
set fish_pager_color_secondary_background --background=brwhite
Variables affecting the pager colors:
fish_pager_color_progressβ the progress bar at the bottom left cornerfish_pager_color_backgroundβ the background color of a linefish_pager_color_prefixβ the prefix string, i.e. the string that is to be completedfish_pager_color_completionβ the completion itself, i.e. the proposed rest of the stringfish_pager_color_descriptionβ the completion descriptionfish_pager_color_selected_backgroundβ background of the selected completionfish_pager_color_selected_prefixβ prefix of the selected completionfish_pager_color_selected_completionβ suffix of the selected completionfish_pager_color_selected_descriptionβ description of the selected completionfish_pager_color_secondary_backgroundβ background of every second unselected completionfish_pager_color_secondary_prefixβ prefix of every second unselected completionfish_pager_color_secondary_completionβ suffix of every second unselected completionfish_pager_color_secondary_descriptionβ description of every second unselected completion
When the secondary or selected variables aren't set or are empty, the normal variables are used, except for $fish_pager_color_selected_background, where the background of $fish_color_search_match is tried first. That's the whole rule β no cap. β¨
β¨ ABBREVIATIONS β¨
To avoid needless typing, a frequently-run command like git checkout can be abbreviated to gco using the abbr command. Obsessed.
abbr -a gco git checkout
After entering gco and pressing space or enter, a gco in command position will turn into git checkout in the command line. If you want to use a literal gco sometimes, use ctrl-space [1]. Iconic.
Abbreviations are a lot more powerful than just replacing literal strings. For example you can make going up a number of directories easier with this:
function multicd
echo cd (string repeat -n (math (string length -- $argv[1]) - 1) ../)
end
abbr --add dotdot --regex '^\.\.+$' --function multicd
Now, .. transforms to cd ../, while ... turns into cd ../../ and .... expands to cd ../../../. The way that works? Literally magic. β¨
The advantage over aliases is that you can see the actual command before using it, add to it or change it, and the actual command will be stored in history.
[1] Any binding that executes theexpand-abbrorexecutebind function will expand abbreviations. By defaultctrl-spaceis bound to just inserting a space.
π PROGRAMMABLE PROMPT π
When it is fish's turn to ask for input (like after it started or the command ended), it will show a prompt. Often this looks something like:
you@hostname ~>
This prompt is determined by running the fish_prompt and fish_right_prompt functions. Main character energy, honestly.
The output of the former is displayed on the left and the latter's output on the right side of the terminal. For vi mode, the output of fish_mode_prompt will be prepended on the left.
If fish_transient_prompt is set to 1, fish will redraw the prompt with a --final-rendering argument before running a commandline, allowing you to change it before pushing it to the scrollback.
fish ships with a few prompts which you can see with fish_config. If you run just fish_config it will open a web interface [2] where you'll be shown the prompts and can pick which one you want. fish_config prompt show will show you the prompts right in your terminal.
For example fish_config prompt choose disco will temporarily select the "disco" prompt. If you like it and decide to keep it, run fish_config prompt save.
You can also change these functions yourself by running funced fish_prompt and funcsave fish_prompt once you are happy with the result (or fish_right_prompt if you want to change that).
[2] The web interface runs purely locally on your computer and requires python to be installed.
π CONFIGURABLE GREETING π
When it is started interactively, fish tries to run the fish_greeting function. The default fish_greeting prints a simple message. You can change its text by changing the $fish_greeting variable, for instance using a universal variable:
set -U fish_greeting
or you can set it globally in config.fish:
set -g fish_greeting 'Hey, stranger!'
or you can script it by changing the function:
function fish_greeting
random choice "Hello!" "Hi" "G'day" "Howdy"
end
save this in config.fish or a function file. You can also use funced and funcsave to edit it easily. π«Ά
π·οΈ PROGRAMMABLE TITLE π·οΈ
okay so most terminals let you set the text that shows up in the titlebar of the terminal window β and fish does that by running the fish_title function π It gets executed before and after a command, and whatever it outputs is what becomes your titlebar message β¨
The status current-command builtin will always return the name of the job that's about to be put in the foreground (or fish if control is coming back to the shell) whenever fish_title is called. And the first argument? That's the most recently executed foreground command, as a string π«Ά
Default title is lowkey iconic: it shows the hostname if you're connected via ssh, the currently running command (unless it's fish) and your current working directory. All of it gets shortened so your tab doesn't get dummy wide π
Examples:
To show the last command and working directory in the title:
function fish_title
# `prompt_pwd` shortens the title. This helps prevent tabs from becoming very wide.
echo $argv[1] (prompt_pwd)
pwd
end
π COMMAND LINE EDITOR π
The fish editor is giving main character energy fr β copy and paste, a searchable history, and a whole pile of editor functions you can bind to special keyboard shortcuts πΈ
Like bash and other shells, fish ships two sets of keyboard shortcuts (aka key bindings): one inspired by the Emacs text editor, and one inspired by the vi text editor. Default editing mode is Emacs π You can hop to vi mode by running fish_vi_key_bindings and hop back with fish_default_key_bindings. And you can absolutely make your own key bindings by creating a function and setting the fish_key_bindings variable to its name β like this:
function fish_hybrid_key_bindings --description \
"Vi-style bindings that inherit emacs-style bindings in all modes"
for mode in default insert visual
fish_default_key_bindings -M $mode
end
fish_vi_key_bindings --no-erase
end
set -g fish_key_bindings fish_hybrid_key_bindings
Real talk though: the key bindings that come with fish include many of the shortcuts that are popular from the respective text editors, but they are not a complete implementation π They do include a shortcut to open the current command line in your preferred editor (alt-e by default) β so if you need the full power of your editor, that's your girl β¨
Shared bindings
Some bindings are common across Emacs and vi mode, because they're not text editing bindings, or because what vi/Vim does for a particular key just doesn't make sense for a shell π
tabβ completes the current token.shift-tabcompletes the current token and starts the pager's search mode.tabis the same asctrl-i.left(β) andright(β) β move the cursor left or right by one character. If the cursor is already at the end of the line and an autosuggestion is available,right(β) accepts the autosuggestion π¦enterβ executes the current commandline, or inserts a newline if it's not complete yet (e.g. a)orendis missing).alt-enterβ inserts a newline at the cursor position. Super useful for adding a line to a commandline that's already complete.alt-left(β) andalt-right(β) β move the cursor left or right by one word. If the command line is empty, they move forward/backward in the directory history. If the cursor is already at the end of the line and an autosuggestion is available,alt-right(β) (oralt-f) accepts the first word in the suggestion.ctrl-left(β) andctrl-right(β) β move the cursor left or right by one token. These accept one token of the autosuggestion β the part they'd move over πshift-left(β) andshift-right(β) β move the cursor one word left or right, without stopping on punctuation. These accept one big word of the autosuggestion.up(β) anddown(β) (orctrl-pandctrl-nfor the emacs aficionados) β search the command history for the previous/next command containing the string that was specified on the commandline before the search started. If the commandline was empty when the search started, all commands match. See the history section for more on history searching πalt-up(β) andalt-down(β) β search the command history for the previous/next token containing the token under the cursor before the search was started. If the commandline wasn't on a token when the search started, all tokens match. Again, see the history section for more on history searching.ctrl-cβ interrupts/kills whatever is running (SIGINT). the ultimate "nope" button πctrl-dβ deletes one character to the right of the cursor. If the command line is empty,ctrl-dwill exit fish.ctrl-uβ removes contents from the beginning of line to the cursor (moving it to the killring).ctrl-lβ pushes any text above the prompt to the terminal's scrollback, then clears and repaints the screen π§ctrl-wβ removes the previous path component (everything up to the previous"/",":"or"@") (moving it to the Copy and paste (Kill Ring)).ctrl-xβ copies the current buffer to the system's clipboard;ctrl-vinserts the clipboard contents. (seefish_clipboard_copyandfish_clipboard_paste) πalt-dβ moves the next word to the Copy and paste (Kill Ring).ctrl-deleteβ moves the next word (or next argument on macOS) to the Copy and paste (Kill Ring).alt-dβ lists the directory history if the command line is empty.alt-deleteβ moves the next argument (or word on macOS) to the Copy and paste (Kill Ring).shift-deleteβ removes the current history item or autosuggestion from the command history.alt-h(orf1) β shows the manual page for the current command, if one exists πalt-lβ lists the contents of the current directory, unless the cursor is over a directory argument, in which case the contents of that directory get listed.alt-oβ opens the file at the cursor in a pager. If the cursor is in command position and the command is a script, it'll instead open that script in your editor. The editor is chosen from the first available of the$VISUALor$EDITORvariables.alt-pβ adds the string&| less;to the end of the job under the cursor. Result: the output of the command gets paged β¨ If you set thePAGERvariable, its value is used instead ofless.alt-wβ prints a short description of the command under the cursor.alt-eβ edits the current command line in an external editor. The editor is chosen from the first available of the$VISUALor$EDITORvariables.alt-vβ same asalt-e.alt-sβ prependssudoto the current commandline. If the commandline is empty, prependssudoto the last commandline. Ifsudoisn't installed, various similar commands are tried:doas,please, andrun0πctrl-spaceβ inserts a space without expanding an abbreviation. For vi mode, this only applies to insert-mode.
Emacs mode commands
To enable emacs mode, use fish_default_key_bindings β which is also the default, cute π
homeorctrl-aβ moves the cursor to the beginning of the line.endorctrl-eβ moves to the end of line. If the cursor is already at the end of the line and an autosuggestion is available,endorctrl-eaccepts the autosuggestion.ctrl-b,ctrl-fβ move the cursor one character left or right, or accept the autosuggestion, just like theleft(β) andright(β) shared bindings (which are available as well π).alt-b,alt-fβ move the cursor one word left or right, or accept one word of the autosuggestion. If the command line is empty, moves forward/backward in the directory history instead.ctrl-n,ctrl-pβ move the cursor up/down or through history, like theupanddownarrow shared bindings.deleteorbackspaceorctrl-hβ removes one character forwards or backwards respectively.alt-backspaceβ removes one word backwards;ctrl-backspaceremoves one argument backwards.alt-<β moves to the beginning of the commandline;alt->moves to the end.ctrl-kβ deletes from the cursor to the end of line (moving it to the Copy and paste (Kill Ring)).escapeandctrl-gβ cancel the current operation. Immediately after an unambiguous completion, this undoes it.alt-cβ capitalizes the current word.alt-uβ makes the current word uppercase.ctrl-tβ transposes the last two characters.alt-tβ transposes the last two words.ctrl-z,ctrl-_(ctrl-/on some terminals) β undo the most recent edit of the line πalt-/orctrl-shift-zβ reverts the most recent undo.ctrl-rβ opens the history in a pager. This shows history entries matching the search, a few at a time. Pressingctrl-ragain searches older entries; pressingctrl-s(that otherwise toggles pager search) goes to newer entries. The search bar will always be selected β
You can change these key bindings using the bind builtin π
Vi mode commands
Vi mode lets you use vi-like commands right at the prompt π¦ Initially, insert mode is active. escape enters command mode. The commands available in command, insert and visual mode are described below. Vi mode shares some bindings with Emacs mode.
To enable vi mode, use fish_vi_key_bindings. It's also possible to add all Emacs mode bindings to vi mode by using something like:
function fish_user_key_bindings
# Execute this once per mode that emacs bindings should be used in
fish_default_key_bindings -M insert
# Then execute the vi-bindings so they take precedence when there's a conflict.
# Without --no-erase fish_vi_key_bindings will default to
# resetting all bindings.
# The argument specifies the initial mode (insert, "default" or visual).
fish_vi_key_bindings --no-erase insert
end
When in vi mode, the fish_mode_prompt function displays a mode indicator to the left of the prompt π To disable that feature, override it with an empty function. To display the mode somewhere else (like in your right prompt), use the output of the fish_default_mode_prompt function π
When a binding switches the mode, it will repaint the mode-prompt if it exists, and the rest of the prompt only if it doesn't. So if you want a mode-indicator in your fish_prompt, you need to erase fish_mode_prompt β e.g. by adding an empty file at ~/.config/fish/functions/fish_mode_prompt.fish. (Bindings that change the mode are supposed to call the repaint-mode bind function, see bind) π
The fish_vi_cursor function will be used to change the cursor's shape depending on the mode in supported terminals. The following snippet can be used to manually configure cursors after enabling vi mode:
okay so here's the cursor-shape config they're showing you β this is the whole vibe π
# Emulates vim's cursor shape behavior
# Set the normal and visual mode cursors to a block
set fish_cursor_default block
# Set the insert mode cursor to a line
set fish_cursor_insert line
# Set the replace mode cursors to an underscore
set fish_cursor_replace_one underscore
set fish_cursor_replace underscore
# Set the external cursor to a line. The external cursor appears when a command is started.
# The cursor shape takes the value of fish_cursor_default when fish_cursor_external is not specified.
set fish_cursor_external line
# The following variable can be used to configure cursor shape in
# visual mode, but due to fish_cursor_default, is redundant here
set fish_cursor_visual block
Additionally, you can tack blink onto each of those cursor-shape parameters to get a blinking cursor in that shape. fish knows the shapes "block", "line" and "underscore" β anything else just gets ignored, no drama. π«Ά
If the cursor shape does not appear to be changing after setting the above variables, it's likely your terminal emulator does not support the capabilities necessary to do this. not fish being shady, just terminal limitations π
π§ Command mode
Command mode is also known as normal mode, iykyk.
hβ moves the cursor left.lβ moves the cursor right.kandjβ search the command history for the previous/next command containing the string that was specified on the commandline before the search was started. If the commandline was empty when the search started, all commands match. See the history section for more information on history searching. In multi-line commands, they move the cursor up and down respectively.iβ enters insert mode at the current cursor position.Iβ enters insert mode at the beginning of the line.vβ enters visual mode at the current cursor position.aβ enters insert mode after the current cursor position.Aβ enters insert mode at the end of the line.oβ inserts a new line under the current one and enters insert modeO(capital-"o") β inserts a new line above the current one and enters insert mode0(zero) β moves the cursor to beginning of line (remaining in command mode).d,dβ deletes the current line and moves it to the Copy and paste (Kill Ring).Dβ deletes text after the current cursor position and moves it to the Copy and paste (Kill Ring).pβ pastes text from the Copy and paste (Kill Ring).uβ undoes the most recent edit of the command line.ctrl-rβ redoes the most recent edit.[and]β search the command history for the previous/next token containing the token under the cursor before the search was started. See the history section for more information on history searching./β opens the history in a pager. This will show history entries matching the search, a few at a time. Pressing it again will search older entries, pressingctrl-s(that otherwise toggles pager search) will go to newer entries. The search bar will always be selected.backspaceβ moves the cursor left.g,g/Gβ moves the cursor to the beginning/end of the commandline, respectively.~β toggles the case (upper/lower) of the character and moves to the next character.g,uβ lowercases to the end of the word.g,Uβ uppercases to the end of the word.:,qβ exits fish.
β¨ Insert mode
escapeβ enters command mode.backspaceβ removes one character to the left.ctrl-nβ accepts the autosuggestion.
π Visual mode
left(β) andright(β) β extend the selection backward/forward by one character.hβ moves the cursor left.lβ moves the cursor right.kβ moves the cursor up.jβ moves the cursor down.bandwβ extend the selection backward/forward by one word.dandxβ move the selection to the Copy and paste (Kill Ring) and enter command mode.escapeandctrl-cβ enter command mode.candsβ remove the selection and switch to insert mode.Xβ moves the entire line to the Copy and paste (Kill Ring), and enters command mode.yβ copies the selection to the Copy and paste (Kill Ring), and enters command mode.~β toggles the case (upper/lower) on the selection, and enters command mode.g,uβ lowercases the selection, and enters command mode.g,Uβ uppercases the selection, and enters command mode.",*,yβ copies the selection to the clipboard, and enters command mode.
π Custom bindings
In addition to the standard bindings listed here, you can also define your own with the bind command:
# Prints ``^C`` and a new prompt
bind ctrl-c cancel-commandline
Put bind statements into config.fish or a function called fish_user_key_bindings.
If you change your mind on a binding and want to go back to fish's default, you can erase it again:
bind --erase ctrl-c
fish remembers its preset bindings and so it will take effect again. This saves you from having to remember what it was before and add it again yourself. convenient queen behavior π
If you use vi bindings, note that bind will by default bind keys in command mode. To bind something in insert mode:
bind --mode insert ctrl-c 'commandline -r ""'
π¦ Key sequences
To find out the name of a key, you can use fish_key_reader.
> fish_key_reader # Press Alt + right-arrow
Press a key:
bind alt-right 'do something'
Note that the historical way the terminal encodes keys and sends them to the application (fish, in this case) makes a lot of combinations indistinguishable or unbindable. In the usual encoding, ctrl-i is the same as the tab key, and shift cannot be detected when ctrl is also pressed. terminal lore, unfortunately π
There are more powerful encoding schemes, and fish tries to tell the terminal to turn them on, but there are still many terminals that do not support them. When fish_key_reader prints the same sequence for two different keys, then that is because your terminal sends the same sequence for them, and there isn't anything fish can do about it. It is our hope that these schemes will become more widespread, making input more flexible.
In the historical scheme, escape is the same thing as alt in a terminal. To distinguish between pressing escape and then another key, and pressing alt and that key (or an escape sequence the key sends), fish waits for a certain time after seeing an escape character. This is configurable via the fish_escape_delay_ms variable.
If you want to be able to press escape and then a character and have it count as alt+that character, set it to a higher value, e.g.:
set -g fish_escape_delay_ms 100
Similarly, to disambiguate other keypresses where you've bound a subsequence and a longer sequence, fish has fish_sequence_key_delay_ms:
# This binds the sequence j,k to switch to normal mode in vi mode.
# If you kept it like that, every time you press "j",
# fish would wait for a "k" or other key to disambiguate
bind -M insert -m default j,k cancel repaint-mode
# After setting this, fish only waits 200ms for the "k",
# or decides to treat the "j" as a separate sequence, inserting it.
set -g fish_sequence_key_delay_ms 200
π Copy and paste (Kill Ring)
fish uses an Emacs-style kill ring for copy and paste functionality. For example, use ctrl-k (kill-line) to cut from the current cursor position to the end of the line. The string that is cut (a.k.a. killed in emacs-ese) is inserted into a list of kills, called the kill ring. To paste the latest value from the kill ring (emacs calls this "yanking") use ctrl-y (the yank input function). After pasting, use alt-y (yank-pop) to rotate to the previous kill. emacs girlies stay winning πΈ
Copy and paste from outside are also supported, both via the ctrl-x / ctrl-v bindings (the fish_clipboard_copy and fish_clipboard_paste functions [3]) and via the terminal's paste function, for which fish enables "Bracketed Paste Mode", so it can tell a paste from manually entered text. In addition, when pasting inside single quotes, pasted single quotes and backslashes are automatically escaped so that the result can be used as a single token by closing the quote after. Kill ring entries are stored in fish_killring variable.
[3] These rely on external tools. Currentlyxsel,xclip,wl-copy/wl-pasteandpbcopy/pbpasteare supported.
The commands begin-selection and end-selection (unbound by default; used for selection in vi visual mode) control text selection together with cursor movement commands that extend the current selection. The variable fish_cursor_selection_mode can be used to configure if that selection should include the character under the cursor (inclusive) or not (exclusive). The default is exclusive, which works well with any cursor shape. For vi mode, and particularly for the block or underscore cursor shapes you may prefer inclusive.
π§ Multiline editing
The fish commandline editor can be used to work on commands that are several lines long. There are three ways to make a command span more than a single line:
- Pressing the
enterkey while a block of commands is unclosed, such as when one or more block commands such asfor,beginorifdo not have a correspondingendcommand. - Pressing
alt-enterinstead of pressing theenterkey. - By inserting a backslash (
\) character before pressing theenterkey, escaping the newline.
The fish commandline editor works exactly the same in single line mode and in multiline mode. To move between lines use the left and right arrow keys and other such keyboard shortcuts. multi-line main character energy β¨
β Searchable command history
After a command has been executed, it is remembered in the history list. Any duplicate history items are automatically removed. By pressing the up and down keys, you can search forwards and backwards in the history. If the current command line is not empty when starting a history search, only the commands containing the string entered into the command line are shown.
By pressing alt-up (β) and alt-down (β), a history search is also performed, but instead of searching for a complete commandline, each commandline is broken into separate elements like it would be before execution, and the history is searched for an element matching that under the cursor.
For more complicated searches, you can press ctrl-r to open a pager that allows you to search the history. It shows a limited number of entries in one page, press ctrl-r [4] again to move to the next page and ctrl-s [5] to move to the previous page. You can change the text to refine your search.
History searches are case-insensitive unless your search string has an uppercase character in it. And if you wanna bail mid-search and go edit what you're searching for? Just hit escape or pagedown and you're back in business π
Okay bestie, this next one is genuinely iconic: if you start your commandline with a space, the whole line does not get stored in your history. It's still there for you to recall until the next command gets executed β but it never touches the disk. Literally made for when you typo'd something embarrassing and don't want it living in your history forever π
Your command history lives in ~/.local/share/fish/fish_history by default β or $XDG_DATA_HOME/fish/fish_history if that variable is set. But plot twist: you can set the fish_history environment variable to change the name of the history session (which gives you a <session>_history file). You can do this both before starting the shell and while the shell is running. Obsessed with the flexibility tbh β¨
For other history manipulations, go check out the history command, iykyk π«Ά
Examples:
- Wanna search for previous entries containing the word 'make'? Type
makein the console and press the up key. Slay. - If your commandline reads
cd m, put the cursor over themcharacter and pressalt-up(β) to search for previously typed words containing 'm'. Chef's kiss π
[4] Or another binding that triggers thehistory-pagerinput function. Seebindfor a full list. [5] Or another binding that triggers thepager-toggle-searchinput function.
π΅οΈββοΈ PRIVATE MODE π΅οΈββοΈ
fish has a private mode, and in this mode your command history is not written to the history file on disk. To turn it on, either set $fish_private_mode to a non-empty value, or launch with fish --private (short version: fish -P) π
If you launch fish with -P, it both hides your old history and prevents writing history to disk. This is lowkey essential for not leaking personal info (screencasts, bestie β think about the screencasts π) or when you're dealing with sensitive information.
And if you're writing your own fish scripts and wanna respect a user's wish for privacy? You can query the variable, like if test -n "$fish_private_mode" ..., and alter your script's behavior accordingly. Considerate king behavior fr fr π
πΊοΈ NAVIGATING DIRECTORIES πΊοΈ
Usually you navigate directories with the cd command β classic, we love her β but fish also serves up some advanced features on top π¦
Your current working directory can be shown with the pwd command, or with the $PWD special variable. Honestly your prompt probably already does this for you, but now you know β¨
π Directory history π
fish automatically keeps a trail of recently visited directories (via cd) by storing that history in the dirprev and dirnext variables. It's giving main character memory πΈ
Several commands exist to interact with this directory history:
dirhβ prints the history πcdhβ displays a prompt so you can quickly navigate the history π§prevdβ moves backward through the history. Bound toalt-left(β)nextdβ moves forward through the history. Bound toalt-right(β)
π₯ Directory stack π₯
Another set of commands β usually also available in other shells like bash β deals with the directory stack. Heads up though: stack handling is not automatic and needs explicit calls of the following commands:
dirsβ prints the stackpushdβ adds a directory on top of the stack and makes it your current working directorypopdβ removes the directory on top of the stack and changes your current working directory
π Author π
fish-shell developers
Β©οΈ Copyright Β©οΈ
fish-shell developers
π And that's a wrap, bestie! This wasFISH-INTERACTIVE(1), version4.9, datedSep 08, 2026, brought to you by the fish-shell developers. Go forth and have the prettiest, most autosuggested commandline of your life. Periodt. π ππ¦
π¦ 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