2019-03-31 17:05:09 +08:00
.. _cmd-bind:
2018-12-17 09:39:33 +08:00
bind - handle fish key bindings
2019-01-03 12:10:47 +08:00
===============================
2018-12-18 09:58:24 +08:00
Synopsis
--------
2018-12-17 05:08:41 +08:00
docs synopsis: add HTML highlighing and automate manpage markup
Recent synopsis changes move from literal code blocks to
[RST line blocks]. This does not translate well to HTML: it's not
rendered in monospace, so aligment is lost. Additionally, we don't
get syntax highlighting in HTML, which adds differences to our code
samples which are highlighted.
We hard-wrap synopsis lines (like code blocks). To align continuation
lines in manpages we need [backslashes in weird places]. Combined with
the **, *, and `` markup, it's a bit hard to get the alignment right.
Fix these by moving synopsis sources back to code blocks and compute
HTML syntax highlighting and manpage markup with a custom Sphinx
extension.
The new Pygments lexer can tokenize a synopsis and assign the various
highlighting roles, which closely matches fish's syntax highlighing:
- command/keyword (dark blue)
- parameter (light blue)
- operator like and/or/not/&&/|| (cyan)
- grammar metacharacter (black)
For manpage output, we don't project the fish syntax highlighting
but follow the markup convention in GNU's man(1):
bold text type exactly as shown.
italic text replace with appropriate argument.
To make it easy to separate these two automatically, formalize that
(italic) placeholders must be uppercase; while all lowercase text is
interpreted literally (so rendered bold).
This makes manpages more consistent, see string-join(1) and and(1).
Implementation notes:
Since we want manpage formatting but Sphinx's Pygments highlighing
plugin does not support manpage output, add our custom "synopsis"
directive. This directive parses differently when manpage output is
specified. This means that the HTML and manpage build processes must
not share a cache, because the parsed doctrees are cached. Work around
this by using separate cache locations for build targets "sphinx-docs"
(which creates HTML) and "sphinx-manpages". A better solution would
be to only override Sphinx's ManualPageBuilder but that would take a
bit more code (ideally we could override ManualPageWriter but Sphinx
4.3.2 doesn't really support that).
---
Alternative solution: stick with line blocks but use roles like
:command: or :option: (or custom ones). While this would make it
possible to produce HTML that is consistent with code blocks (by adding
a bit of CSS), the source would look uglier and is harder to maintain.
(Let's say we want to add custom formatting to the [|] metacharacters
in HTML. This is much easier with the proposed patch.)
---
[RST line blocks]: https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#line-blocks
[backslashes in weird places]: https://github.com/fish-shell/fish-shell/pull/8626#discussion_r782837750
2022-01-09 22:09:46 +08:00
.. synopsis ::
2024-03-30 23:10:12 +08:00
bind [(-M | --mode) MODE] [(-m | --sets-mode) NEW_MODE] [--preset | --user] [-s | --silent] KEYS COMMAND ...
bind [(-M | --mode) MODE] [--preset] [--user] [KEYS]
bind [-a | --all] [--preset] [--user]
docs synopsis: add HTML highlighing and automate manpage markup
Recent synopsis changes move from literal code blocks to
[RST line blocks]. This does not translate well to HTML: it's not
rendered in monospace, so aligment is lost. Additionally, we don't
get syntax highlighting in HTML, which adds differences to our code
samples which are highlighted.
We hard-wrap synopsis lines (like code blocks). To align continuation
lines in manpages we need [backslashes in weird places]. Combined with
the **, *, and `` markup, it's a bit hard to get the alignment right.
Fix these by moving synopsis sources back to code blocks and compute
HTML syntax highlighting and manpage markup with a custom Sphinx
extension.
The new Pygments lexer can tokenize a synopsis and assign the various
highlighting roles, which closely matches fish's syntax highlighing:
- command/keyword (dark blue)
- parameter (light blue)
- operator like and/or/not/&&/|| (cyan)
- grammar metacharacter (black)
For manpage output, we don't project the fish syntax highlighting
but follow the markup convention in GNU's man(1):
bold text type exactly as shown.
italic text replace with appropriate argument.
To make it easy to separate these two automatically, formalize that
(italic) placeholders must be uppercase; while all lowercase text is
interpreted literally (so rendered bold).
This makes manpages more consistent, see string-join(1) and and(1).
Implementation notes:
Since we want manpage formatting but Sphinx's Pygments highlighing
plugin does not support manpage output, add our custom "synopsis"
directive. This directive parses differently when manpage output is
specified. This means that the HTML and manpage build processes must
not share a cache, because the parsed doctrees are cached. Work around
this by using separate cache locations for build targets "sphinx-docs"
(which creates HTML) and "sphinx-manpages". A better solution would
be to only override Sphinx's ManualPageBuilder but that would take a
bit more code (ideally we could override ManualPageWriter but Sphinx
4.3.2 doesn't really support that).
---
Alternative solution: stick with line blocks but use roles like
:command: or :option: (or custom ones). While this would make it
possible to produce HTML that is consistent with code blocks (by adding
a bit of CSS), the source would look uglier and is harder to maintain.
(Let's say we want to add custom formatting to the [|] metacharacters
in HTML. This is much easier with the proposed patch.)
---
[RST line blocks]: https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#line-blocks
[backslashes in weird places]: https://github.com/fish-shell/fish-shell/pull/8626#discussion_r782837750
2022-01-09 22:09:46 +08:00
bind (-f | --function-names)
bind (-L | --list-modes)
2024-03-30 23:10:12 +08:00
bind (-e | --erase) [(-M | --mode) MODE] [--preset] [--user] [-a | --all] | KEYS ...
2018-12-17 05:08:41 +08:00
2018-12-19 10:44:30 +08:00
Description
2019-01-03 12:10:47 +08:00
-----------
2018-12-17 05:08:41 +08:00
2024-03-30 23:10:12 +08:00
`` bind `` manages key bindings.
2018-12-17 05:08:41 +08:00
2024-03-30 23:10:12 +08:00
If both `` KEYS `` and `` COMMAND `` are given, `` bind `` adds (or replaces) a binding in `` MODE `` .
If only `` KEYS `` is given, any existing binding in the given `` MODE `` will be printed.
2018-12-17 05:08:41 +08:00
2024-03-30 23:10:12 +08:00
`` KEYS `` is a comma-separated list of key names.
2024-04-08 00:03:49 +08:00
Modifier keys can be specified by prefixing a key name with a combination of `` ctrl- `` /`` c- `` , `` alt- `` /`` a- `` and `` shift- `` .
2024-04-14 02:30:07 +08:00
For example, pressing :kbd: `w` while holding the Alt modifier is written as `` alt-w `` .
2024-03-30 23:10:12 +08:00
Key names are case-sensitive; for example `` alt-W `` is the same as `` alt-shift-w `` .
2024-04-20 22:59:28 +08:00
`` ctrl-x,ctrl-e `` would mean pressing :kbd: `ctrl-x` followed by :kbd: `ctrl-e` .
2018-12-17 05:08:41 +08:00
2024-03-30 23:10:12 +08:00
Some keys have names, usually because they don't have an obvious printable character representation.
They are:
2020-05-19 02:48:27 +08:00
2024-04-20 22:59:28 +08:00
- the arrow keys `` up `` , `` down `` , `` left `` and `` right `` ,
- `` backspace `` ,
- `` comma `` (`` , `` ),
- `` delete `` ,
- `` end `` ,
- `` enter `` ,
- `` escape `` ,
- `` F1 `` through `` F12 `` .
- `` home `` ,
- `` insert `` ,
- `` minus `` (`` - `` ),
- `` pageup `` ,
- `` pagedown `` ,
- `` space `` and
- `` tab `` ,
These names are case-sensitive.
An empty value (`` '' `` ) for `` KEYS `` designates the generic binding that will be used if nothing else matches. For most bind modes, it makes sense to bind this to the `` self-insert `` function (i.e. `` bind '' self-insert `` ). This will insert any keystrokes that have no bindings otherwise. Non-printable characters are ignored by the editor, so this will not result in control sequences being inserted.
2024-03-30 23:10:12 +08:00
To find the name of a key combination you can use :doc: `fish_key_reader <fish_key_reader>` .
2021-01-09 20:13:48 +08:00
2023-05-18 16:11:17 +08:00
`` COMMAND `` can be any fish command, but it can also be one of a set of special input functions. These include functions for moving the cursor, operating on the kill-ring, performing tab completion, etc. Use `` bind --function-names `` or :ref: `see below <special-input-functions>` for a list of these input functions.
2018-12-17 05:08:41 +08:00
2022-12-17 03:41:36 +08:00
.. note ::
2024-03-02 14:58:01 +08:00
If a script changes the commandline, it should finish by calling the `` repaint `` special input function.
2018-12-17 05:08:41 +08:00
2024-03-30 23:10:12 +08:00
If no `` KEYS `` argument is provided, all bindings (in the given `` MODE `` ) are printed. If `` KEYS `` is provided but no `` COMMAND `` , just the binding matching that sequence is printed.
2018-12-17 05:08:41 +08:00
2023-12-17 17:40:45 +08:00
Key bindings may use "modes", which mimics vi's modal input behavior. The default mode is "default". Every key binding applies to a single mode; you can specify which one with `` -M MODE `` . If the key binding should change the mode, you can specify the new mode with `` -m NEW_MODE `` . The mode can be viewed and changed via the `` $fish_bind_mode `` variable. If you want to change the mode from inside a fish function, use `` set fish_bind_mode MODE `` .
2018-12-17 05:08:41 +08:00
2023-05-18 16:11:17 +08:00
To save custom key bindings, put the `` bind `` statements into :ref: `config.fish <configuration>` . Alternatively, fish also automatically executes a function called `` fish_user_key_bindings `` if it exists.
2020-05-19 02:48:27 +08:00
Options
-------
The following options are available:
2018-12-17 05:08:41 +08:00
2021-12-09 19:53:13 +08:00
**-f** or **--function-names**
2021-12-09 19:33:33 +08:00
Display a list of available input functions
2018-12-17 05:08:41 +08:00
2021-12-09 19:53:13 +08:00
**-L** or **--list-modes**
2021-12-09 19:33:33 +08:00
Display a list of defined bind modes
2018-12-17 05:08:41 +08:00
2021-12-09 19:53:13 +08:00
**-M MODE** or **--mode** *MODE*
2021-12-09 19:33:33 +08:00
Specify a bind mode that the bind is used in. Defaults to "default"
2018-12-17 05:08:41 +08:00
2021-12-09 19:53:13 +08:00
**-m NEW_MODE** or **--sets-mode** *NEW_MODE*
Change the current mode to *NEW_MODE* after this binding is executed
2018-12-17 05:08:41 +08:00
2021-12-09 19:53:13 +08:00
**-e** or **--erase**
2021-12-09 19:33:33 +08:00
Erase the binding with the given sequence and mode instead of defining a new one.
Multiple sequences can be specified with this flag.
2021-12-09 19:53:13 +08:00
Specifying **-a** or **--all** with **-M** or **--mode** erases all binds in the given mode regardless of sequence.
Specifying **-a** or **--all** without **-M** or **--mode** erases all binds in all modes regardless of sequence.
2018-12-17 05:08:41 +08:00
2021-12-09 19:53:13 +08:00
**-a** or **--all**
2024-03-30 23:10:12 +08:00
See **--erase**
2018-12-17 05:08:41 +08:00
2021-12-09 19:53:13 +08:00
**--preset** and **--user**
2021-12-09 19:33:33 +08:00
Specify if bind should operate on user or preset bindings.
User bindings take precedence over preset bindings when fish looks up mappings.
By default, all `` bind `` invocations work on the "user" level except for listing, which will show both levels.
2021-12-09 19:53:13 +08:00
All invocations except for inserting new bindings can operate on both levels at the same time (if both **--preset** and **--user** are given).
**--preset** should only be used in full binding sets (like when working on `` fish_vi_key_bindings `` ).
2018-12-17 05:08:41 +08:00
2022-07-02 02:46:52 +08:00
**-s** or **--silent**
Silences some of the error messages, including for unknown key names and unbound sequences.
2022-03-12 00:18:41 +08:00
**-h** or **--help**
Displays help about using this command.
2023-05-18 16:11:17 +08:00
.. _special-input-functions:
2018-12-19 10:44:30 +08:00
Special input functions
2019-01-03 12:10:47 +08:00
-----------------------
2018-12-17 05:08:41 +08:00
The following special input functions are available:
2021-12-09 19:33:33 +08:00
`` and ``
only execute the next function if the previous succeeded (note: only some functions report success)
2019-12-25 17:46:46 +08:00
2021-12-09 19:33:33 +08:00
`` accept-autosuggestion ``
2022-02-28 04:09:27 +08:00
accept the current autosuggestion
2018-12-17 05:08:41 +08:00
2021-12-09 19:33:33 +08:00
`` backward-char ``
2022-02-28 04:09:27 +08:00
move one character to the left.
If the completion pager is active, select the previous completion instead.
2018-12-17 05:08:41 +08:00
2024-03-30 03:12:21 +08:00
`` backward-char-passive ``
move one character to the left, but do not trigger any non-movement-related operations. If the cursor is at the start of
the commandline, does nothing. Does not change the selected item in the completion pager UI when shown.
2021-12-09 19:33:33 +08:00
`` backward-bigword ``
move one whitespace-delimited word to the left
2018-12-17 05:08:41 +08:00
2021-12-09 19:33:33 +08:00
`` backward-delete-char ``
deletes one character of input to the left of the cursor
2018-12-17 05:08:41 +08:00
2021-12-09 19:33:33 +08:00
`` backward-kill-bigword ``
move the whitespace-delimited word to the left of the cursor to the killring
2018-12-17 05:08:41 +08:00
2021-12-09 19:33:33 +08:00
`` backward-kill-line ``
move everything from the beginning of the line to the cursor to the killring
2018-12-17 05:08:41 +08:00
2021-12-09 19:33:33 +08:00
`` backward-kill-path-component ``
move one path component to the left of the cursor to the killring. A path component is everything likely to belong to a path component, i.e. not any of the following: `/={,}'\":@ |;<>&` , plus newlines and tabs.
2018-12-17 05:08:41 +08:00
2021-12-09 19:33:33 +08:00
`` backward-kill-word ``
move the word to the left of the cursor to the killring. The "word" here is everything up to punctuation or whitespace.
2018-12-17 05:08:41 +08:00
2021-12-09 19:33:33 +08:00
`` backward-word ``
move one word to the left
2018-12-17 05:08:41 +08:00
2021-12-09 19:33:33 +08:00
`` beginning-of-buffer ``
moves to the beginning of the buffer, i.e. the start of the first line
2018-12-17 05:08:41 +08:00
2021-12-09 19:33:33 +08:00
`` beginning-of-history ``
move to the beginning of the history
2018-12-17 05:08:41 +08:00
2021-12-09 19:33:33 +08:00
`` beginning-of-line ``
move to the beginning of the line
2018-12-17 05:08:41 +08:00
2021-12-09 19:33:33 +08:00
`` begin-selection ``
start selecting text
2018-12-17 05:08:41 +08:00
2021-12-09 19:33:33 +08:00
`` cancel ``
cancel the current commandline and replace it with a new empty one
2019-12-25 17:26:03 +08:00
2021-12-09 19:33:33 +08:00
`` cancel-commandline ``
cancel the current commandline and replace it with a new empty one, leaving the old one in place with a marker to show that it was cancelled
2020-07-02 02:54:13 +08:00
2021-12-09 19:33:33 +08:00
`` capitalize-word ``
make the current word begin with a capital letter
2018-12-17 05:08:41 +08:00
2023-10-08 17:41:30 +08:00
`` clear-screen ``
clears the screen and redraws the prompt. if the terminal doesn't support clearing the screen it is the same as `` repaint `` .
2021-12-09 19:33:33 +08:00
`` complete ``
guess the remainder of the current token
2018-12-17 05:08:41 +08:00
2021-12-09 19:33:33 +08:00
`` complete-and-search ``
invoke the searchable pager on completion options (for convenience, this also moves backwards in the completion pager)
2018-12-17 05:08:41 +08:00
2021-12-09 19:33:33 +08:00
`` delete-char ``
delete one character to the right of the cursor
2018-12-17 05:08:41 +08:00
2021-12-09 19:33:33 +08:00
`` delete-or-exit ``
2021-12-09 00:29:52 +08:00
delete one character to the right of the cursor, or exit the shell if the commandline is empty
2019-07-03 17:44:08 +08:00
2021-12-09 19:33:33 +08:00
`` down-line ``
move down one line
2019-10-09 00:01:32 +08:00
2021-12-09 19:33:33 +08:00
`` downcase-word ``
make the current word lowercase
2018-12-17 05:08:41 +08:00
2021-12-09 19:33:33 +08:00
`` end-of-buffer ``
moves to the end of the buffer, i.e. the end of the first line
2018-12-17 05:08:41 +08:00
2021-12-09 19:33:33 +08:00
`` end-of-history ``
move to the end of the history
2018-12-17 05:08:41 +08:00
2021-12-09 19:33:33 +08:00
`` end-of-line ``
move to the end of the line
2018-12-17 05:08:41 +08:00
2021-12-09 19:33:33 +08:00
`` end-selection ``
end selecting text
2018-12-17 05:08:41 +08:00
2021-12-09 19:33:33 +08:00
`` expand-abbr ``
expands any abbreviation currently under the cursor
2019-04-01 21:59:15 +08:00
2021-12-09 19:33:33 +08:00
`` execute ``
run the current commandline
2019-12-25 17:26:03 +08:00
2021-12-09 19:33:33 +08:00
`` exit ``
exit the shell
2021-01-04 16:45:34 +08:00
2021-12-09 19:33:33 +08:00
`` forward-bigword ``
move one whitespace-delimited word to the right
2018-12-17 05:08:41 +08:00
2021-12-09 19:33:33 +08:00
`` forward-char ``
2022-02-28 04:09:27 +08:00
move one character to the right; or if at the end of the commandline, accept the current autosuggestion.
If the completion pager is active, select the next completion instead.
2018-12-17 05:08:41 +08:00
2024-03-28 13:18:24 +08:00
`` forward-char-passive ``
move one character to the right, but do not trigger any non-movement-related operations. If the cursor is at the end of the
2024-03-30 03:12:21 +08:00
commandline, does not accept the current autosuggestion (if any). Does not change the selected item in the completion pager,
if shown.
2024-03-28 13:18:24 +08:00
2021-12-09 19:33:33 +08:00
`` forward-single-char ``
2022-02-28 04:09:27 +08:00
move one character to the right; or if at the end of the commandline, accept a single char from the current autosuggestion.
2020-07-21 21:08:38 +08:00
2021-12-09 19:33:33 +08:00
`` forward-word ``
2022-02-28 04:09:27 +08:00
move one word to the right; or if at the end of the commandline, accept one word
from the current autosuggestion.
2018-12-17 05:08:41 +08:00
2022-07-18 02:23:54 +08:00
`` history-pager ``
2022-07-28 15:44:48 +08:00
invoke the searchable pager on history (incremental search); or if the history pager is already active, search further backwards in time.
2022-07-18 02:23:54 +08:00
2023-01-10 08:25:06 +08:00
`` history-pager-delete ``
2024-04-14 02:08:12 +08:00
permanently delete the current history item, either from the history pager or from an active up-arrow history search
2023-01-10 08:25:06 +08:00
2021-12-09 19:33:33 +08:00
`` history-search-backward ``
search the history for the previous match
2018-12-17 05:08:41 +08:00
2021-12-09 19:33:33 +08:00
`` history-search-forward ``
search the history for the next match
2018-12-17 05:08:41 +08:00
2021-12-09 19:33:33 +08:00
`` history-prefix-search-backward ``
search the history for the previous prefix match
2019-10-06 04:50:20 +08:00
2021-12-09 19:33:33 +08:00
`` history-prefix-search-forward ``
search the history for the next prefix match
2019-10-06 04:50:20 +08:00
2021-12-09 19:33:33 +08:00
`` history-token-search-backward ``
search the history for the previous matching argument
2019-07-28 16:33:54 +08:00
2021-12-09 19:33:33 +08:00
`` history-token-search-forward ``
search the history for the next matching argument
2019-07-28 16:33:54 +08:00
2021-12-09 19:33:33 +08:00
`` forward-jump `` and `` backward-jump ``
read another character and jump to its next occurence after/before the cursor
2019-12-25 17:26:03 +08:00
2021-12-09 19:33:33 +08:00
`` forward-jump-till `` and `` backward-jump-till ``
jump to right *before* the next occurence
2019-12-25 17:26:03 +08:00
2021-12-09 19:33:33 +08:00
`` repeat-jump `` and `` repeat-jump-reverse ``
redo the last jump in the same/opposite direction
2019-12-25 17:26:03 +08:00
2021-12-09 19:33:33 +08:00
`` kill-bigword ``
move the next whitespace-delimited word to the killring
2018-12-17 05:08:41 +08:00
2021-12-09 19:33:33 +08:00
`` kill-line ``
move everything from the cursor to the end of the line to the killring
2018-12-17 05:08:41 +08:00
2021-12-09 19:33:33 +08:00
`` kill-selection ``
move the selected text to the killring
2018-12-17 05:08:41 +08:00
2021-12-09 19:33:33 +08:00
`` kill-whole-line ``
2022-05-31 11:12:24 +08:00
move the line (including the following newline) to the killring. If the line is the last line, its preceeding newline is also removed
`` kill-inner-line ``
move the line (without the following newline) to the killring
2018-12-17 05:08:41 +08:00
2021-12-09 19:33:33 +08:00
`` kill-word ``
move the next word to the killring
2018-12-17 05:08:41 +08:00
2021-12-09 00:34:38 +08:00
`` nextd-or-forward-word ``
2022-02-28 04:09:27 +08:00
if the commandline is empty, then move forward in the directory history, otherwise move one word to the right;
or if at the end of the commandline, accept one word from the current autosuggestion.
2021-12-09 00:34:38 +08:00
2021-12-09 19:33:33 +08:00
`` or ``
2022-08-05 23:32:18 +08:00
only execute the next function if the previous did not succeed (note: only some functions report failure)
2020-07-23 01:18:24 +08:00
2021-12-09 19:33:33 +08:00
`` pager-toggle-search ``
2022-07-28 15:44:48 +08:00
toggles the search field if the completions pager is visible; or if used after `` history-pager `` , search forwards in time.
2018-12-17 05:08:41 +08:00
2021-12-09 00:34:38 +08:00
`` prevd-or-backward-word ``
if the commandline is empty, then move backward in the directory history, otherwise move one word to the left
2021-12-09 19:33:33 +08:00
`` repaint ``
reexecutes the prompt functions and redraws the prompt (also `` force-repaint `` for backwards-compatibility)
2019-04-01 21:52:21 +08:00
2021-12-09 19:33:33 +08:00
`` repaint-mode ``
2023-12-17 17:40:45 +08:00
reexecutes the :doc: `fish_mode_prompt <fish_mode_prompt>` and redraws the prompt. This is useful for vi mode. If no `` fish_mode_prompt `` exists or it prints nothing, it acts like a normal repaint.
2019-04-01 21:52:21 +08:00
2021-12-09 19:33:33 +08:00
`` self-insert ``
inserts the matching sequence into the command line
2020-03-05 06:10:24 +08:00
2021-12-09 19:33:33 +08:00
`` self-insert-notfirst ``
inserts the matching sequence into the command line, unless the cursor is at the beginning
2020-03-05 06:10:24 +08:00
2021-12-09 19:33:33 +08:00
`` suppress-autosuggestion ``
remove the current autosuggestion. Returns true if there was a suggestion to remove.
2018-12-17 05:08:41 +08:00
2021-12-09 19:33:33 +08:00
`` swap-selection-start-stop ``
go to the other end of the highlighted text without changing the selection
2018-12-17 05:08:41 +08:00
2021-12-09 19:33:33 +08:00
`` transpose-chars ``
transpose two characters to the left of the cursor
2018-12-17 05:08:41 +08:00
2021-12-09 19:33:33 +08:00
`` transpose-words ``
transpose two words to the left of the cursor
2018-12-17 05:08:41 +08:00
2021-12-09 19:33:33 +08:00
`` togglecase-char ``
toggle the capitalisation (case) of the character under the cursor
2021-03-31 10:41:10 +08:00
2021-12-09 19:33:33 +08:00
`` togglecase-selection ``
toggle the capitalisation (case) of the selection
2021-03-31 10:41:10 +08:00
2021-12-09 19:33:33 +08:00
`` insert-line-under ``
add a new line under the current line
2020-12-20 06:32:17 +08:00
2021-12-09 19:33:33 +08:00
`` insert-line-over ``
add a new line over the current line
2020-12-20 06:32:17 +08:00
2021-12-09 19:33:33 +08:00
`` up-line ``
move up one line
2019-10-09 00:01:32 +08:00
2021-12-09 19:33:33 +08:00
`` undo `` and `` redo ``
revert or redo the most recent edits on the command line
2020-02-04 19:47:44 +08:00
2021-12-09 19:33:33 +08:00
`` upcase-word ``
make the current word uppercase
2018-12-17 05:08:41 +08:00
2021-12-09 19:33:33 +08:00
`` yank ``
insert the latest entry of the killring into the buffer
2018-12-17 05:08:41 +08:00
2021-12-09 19:33:33 +08:00
`` yank-pop ``
rotate to the previous entry of the killring
2018-12-17 05:08:41 +08:00
2021-03-31 10:41:10 +08:00
Additional functions
--------------------
The following functions are included as normal functions, but are particularly useful for input editing:
2021-12-09 19:33:33 +08:00
`` up-or-search `` and `` down-or-search ``
move the cursor or search the history depending on the cursor position and current mode
2021-03-31 10:41:10 +08:00
2021-12-09 19:33:33 +08:00
`` edit_command_buffer ``
2021-12-09 19:53:13 +08:00
open the visual editor (controlled by the :envvar: `VISUAL` or :envvar: `EDITOR` environment variables) with the current command-line contents
2021-03-31 10:41:10 +08:00
2021-12-09 19:33:33 +08:00
`` fish_clipboard_copy ``
copy the current selection to the system clipboard
2021-03-31 10:41:10 +08:00
2021-12-09 19:33:33 +08:00
`` fish_clipboard_paste ``
paste the current selection from the system clipboard before the cursor
2021-03-31 10:41:10 +08:00
2021-12-09 19:33:33 +08:00
`` fish_commandline_append ``
append the argument to the command-line. If the command-line already ends with the argument, this removes the suffix instead. Starts with the last command from history if the command-line is empty.
2021-06-23 14:55:33 +08:00
2021-12-09 19:33:33 +08:00
`` fish_commandline_prepend ``
prepend the argument to the command-line. If the command-line already starts with the argument, this removes the prefix instead. Starts with the last command from history if the command-line is empty.
2021-06-23 14:55:33 +08:00
2018-12-19 10:44:30 +08:00
Examples
2019-01-03 12:10:47 +08:00
--------
2018-12-17 05:08:41 +08:00
2024-04-14 02:30:07 +08:00
Exit the shell when :kbd: `ctrl-d` is pressed::
2018-12-19 11:14:04 +08:00
2024-03-30 23:10:12 +08:00
bind ctrl-d 'exit'
2018-12-19 11:14:04 +08:00
2024-04-14 02:30:07 +08:00
Perform a history search when :kbd: `pageup` is pressed::
2018-12-19 11:14:04 +08:00
2024-04-14 02:30:07 +08:00
bind pageup history-search-backward
2018-12-19 11:14:04 +08:00
2024-04-14 02:30:07 +08:00
Turn on :ref: `vi key bindings <vi-mode>` and rebind :kbd: `ctrl-c` to clear the input line::
2018-12-19 11:14:04 +08:00
set -g fish_key_bindings fish_vi_key_bindings
2024-04-14 02:30:07 +08:00
bind -M insert ctrl-c kill-whole-line repaint
2018-12-19 11:14:04 +08:00
2024-04-14 02:30:07 +08:00
Launch `` git diff `` and repaint the commandline afterwards when :kbd: `ctrl-g` is pressed::
2018-12-17 05:08:41 +08:00
2024-04-14 02:30:07 +08:00
bind ctrl-g 'git diff' repaint
2020-05-19 02:48:27 +08:00
.. _cmd-bind-termlimits:
Terminal Limitations
--------------------
Unix terminals, like the ones fish operates in, are at heart 70s technology. They have some limitations that applications running inside them can't workaround.
2024-04-20 22:59:28 +08:00
For instance, historically the control key modifies a character by setting the top three bits to 0. This means:
2020-05-19 02:48:27 +08:00
2024-04-14 02:30:07 +08:00
- Many characters + control are indistinguishable from other keys: :kbd: `ctrl-i` *is* :kbd: `tab` , :kbd: `ctrl-j` *is* newline (`` \n `` ).
2024-04-20 22:59:28 +08:00
- Control and shift don't work simultaneously - :kbd: `ctrl-X` is the same as :kbd: `ctrl-x` .
Other keys don't have a direct encoding, and are sent as escape sequences. For example :kbd: `right` (`` → `` ) usually sends `` \e\[C `` .
Some modern terminals support newer encodings for keys, that allow distinguishing more characters and modifiers, and fish enables as many of these as it can, automatically.
2020-05-19 02:48:27 +08:00
2024-04-20 22:59:28 +08:00
When in doubt, run :doc: `fish_key_reader` . If that tells you that pressing :kbd: `ctrl-i` sends tab, your terminal does not support these better encodings, and so fish is limited to what it sends.
2020-05-19 02:48:27 +08:00
2019-10-31 21:12:57 +08:00
.. _cmd-bind-escape:
2018-12-17 05:08:41 +08:00
2023-08-31 05:02:28 +08:00
Key timeout
-----------
When you've bound a sequence of multiple characters, there is always the possibility that fish has only seen a part of it, and then it needs to disambiguate between the full sequence and part of it.
For example::
2024-04-20 22:59:28 +08:00
bind j,k 'commandline -i foo'
# or `bind jk`
2023-08-31 05:02:28 +08:00
will bind the sequence `` jk `` to insert "foo" into the commandline. When you've only pressed "j", fish doesn't know if it should insert the "j" (because of the default self-insert), or wait for the "k".
You can enable a timeout for this, by setting the :envvar: `fish_sequence_key_delay_ms` variable to the timeout in milliseconds. If the timeout elapses, fish will no longer wait for the sequence to be completed, and do what it can with the characters it already has.
2018-12-17 05:08:41 +08:00
2024-04-20 22:59:28 +08:00
The escape key is a special case, because it can be used standalone as a real key or as part of a longer escape sequence, like function or arrow keys. Holding alt and something else also typically sends escape, for example holding alt+a will send an escape character and then an "a". So the escape character has its own timeout configured with :envvar: `fish_escape_delay_ms` .
2023-10-25 00:24:51 +08:00
2023-10-27 03:26:42 +08:00
See also :ref: `Key sequences <interactive-key-sequences>` .