bind
Associate names with network addresses
TLDR
List all bound commands and their hotkeys
Query a command for its hotkey
Bind a key
List user defined bindings
Display help
SYNOPSIS
bind [-m keymap] [-lpsvPSV] [-f filename] [-q name] [-u name] [-r keyseq] [-x keyseq:shell-command] [keyseq:readline-function or keyseq:"text"]
PARAMETERS
-m keymap
Use keymap as the keymap to be affected by subsequent bindings.
-l
List the names of all readline functions.
-p
Display readline function names and bindings in a format suitable for reading by bind.
-P
List current readline function names and bindings.
-s
Display key sequences that invoke a readline function or macro, along with the function name or macro contents in a format suitable for reading by bind.
-S
Display key sequences that invoke a readline function or macro, along with the function name or macro contents.
-v
Display readline variable names and values in a format suitable for reading by bind.
-V
List current readline variable names and values.
-f filename
Read keybindings from filename.
-q name
Query about which keys invoke the named function.
-u name
Unbind all keys invoking the named function.
-r keyseq
Remove a keybinding.
-x keyseq:shell-command
Cause shell-command to be executed whenever keyseq is entered. Note that shell-command is executed when keyseq is entered, *not* when the function that keyseq is bound to is executed.
keyseq:readline-function
Bind keyseq to readline-function.
keyseq:"text"
Bind keyseq to insert text.
DESCRIPTION
The bind command in Linux is used to display or change readline key bindings. Readline is a library that provides line editing and history capabilities for programs, most notably the Bash shell. Bind allows users to customize how readline responds to keystrokes, mapping specific keys or key sequences to readline functions. This enables users to create custom shortcuts and improve their command-line workflow.
Without any arguments, bind displays the current readline key bindings. With arguments, you can create new bindings, unbind existing ones, or execute readline commands. Changes made using bind typically only affect the current shell session unless saved to a readline initialization file (typically ~/.inputrc). The command's flexibility makes it a powerful tool for experienced users seeking to optimize their command-line experience.
CAVEATS
Changes made with bind only persist for the current shell session unless saved to the ~/.inputrc file.
Complex bindings may require a deeper understanding of readline's functionality.
SAVING BINDINGS
To make your keybindings permanent, add the bind commands to your ~/.inputrc file. Readline reads this file on startup, applying your custom bindings to each new shell session.
KEY SEQUENCES
Key sequences can include control characters (e.g., Ctrl-a, written as "\C-a") and meta characters (e.g., Alt-a, written as "\M-a"). You can use tab completion to find the readline functions you wish to bind. Example: bind '\C-a:beginning-of-line'
HISTORY
The bind command is inherently linked to the development and usage of the readline library. As readline became a standard component in interactive command-line tools (especially the bash shell), bind emerged as the primary mechanism for users to customize and personalize their command-line experience. Its evolution has been tightly coupled with the ongoing development of readline, ensuring that users can leverage new readline features and options through customizable keybindings. Its continuous usage shows importance for developers and advanced users.
SEE ALSO
bash(1), readline(3)