Linux command
bind 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
List all Readline key bindings
bind -P
List key bindings in reusable format
bind -p
Bind a key sequence to a Readline function
bind '"\e[24~": end-of-line'
Bind a key sequence to execute a shell command
bind -x '"\C-l": clear'
Remove binding for a key sequence
bind -r '\e[24~'
Read key bindings from a file
bind -f [~/.inputrc]
Query which keys invoke a specific function
bind -q [complete]
说明
bind is a Bash shell builtin that sets Readline key bindings and variables. It controls how Bash responds to keyboard input by mapping key sequences to Readline functions, macros, or shell commands. By default, Bash uses Emacs-style key bindings, but bind allows customization to any preferred scheme. Key bindings can be set interactively or loaded from configuration files like ~/.inputrc. To discover the escape sequence for a key, press Ctrl+v at the command line followed by the key, or use the read builtin and press the desired key combination.
参数
- -l
- List names of all Readline functions
- -P
- List function names and their current bindings
- -p
- List bindings in a format suitable for reuse as input
- -S
- List key sequences that invoke macros and their values
- -s
- List macro bindings in reusable format
- -V
- List Readline variable names and values
- -v
- List Readline variables in reusable format
- -X
- List key sequences bound to shell commands in reusable format
- -m _keymap_
- Use specified keymap: emacs, emacs-standard, emacs-meta, emacs-ctlx, vi, vi-move, vi-command, vi-insert
- -f _filename_
- Read key bindings from file
- -q _function_
- Query which keys invoke the named function
- -u _function_
- Unbind all keys bound to the named function
- -r _keyseq_
- Remove binding for key sequence
- -x _keyseq:shell-command_
- Execute shell command when key sequence is entered
FAQ
What is the bind command used for?
bind is a Bash shell builtin that sets Readline key bindings and variables. It controls how Bash responds to keyboard input by mapping key sequences to Readline functions, macros, or shell commands. By default, Bash uses Emacs-style key bindings, but bind allows customization to any preferred scheme. Key bindings can be set interactively or loaded from configuration files like ~/.inputrc. To discover the escape sequence for a key, press Ctrl+v at the command line followed by the key, or use the read builtin and press the desired key combination.
How do I run a basic bind example?
Run `bind -P` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -l do in bind?
List names of all Readline functions