bind command is Bash shell builtin command. It is used to set Readline key bindings and variables. The keybindings are the keyboard actions that are bound to a function. So it can be used to change how the bash will react to keys or combinations of keys, being pressed on the keyboard.
bind [-lpsvPSVX] [-m keymap] [-q name] [-f filename] [-u name] [-r keyseq] [-x keyseq:shell-command] [keyseq:readline-function or readline-command]
- -m keymap: It uses KEYMAP as the key mapping scheme for the duration of the current command sequence. Acceptable keymap names are as follows : emacs, emacs-standard, emacs-meta, emacs-ctlx, vi, vi-move, vi-command, and vi-insert.
- -l: It list names of functions.
- -P: It list function names and bindings.
- -p: It list functions and bindings in a form that can be reused as input.
- -S: It list key sequences that invoke macros and their values.
- -s: It list key sequences that invoke macros and their values in a form that can be reused as input.
- -V: It list variable names and values.
- -v: It list variable names and values in a form that canbe reused as input.
- -q function-name: It query about which keys invoke the named function.
- -u function-name: It unbind all keys which are bound to the named function.
- -r keyseq: It remove the binding for KEYSEQ.
- -f filename: It read key bindings from FILENAME.
- -x keyseq:shell-command: It cause SHELL-COMMAND to be executed when KEYSEQ is entered.
- -XIt lists key sequences bound with -x and associated commands in a form that can be reused as input.
- -m: It use KEYMAP as the keymap for the duration of this command. Here we are using vi keymapping in bash, which allows us to manipulate text on the command line as you would in vi.
bind -m vi
- -l: List all the readline function names. There are around 150 functions that are available by default in this list.
- -p: It will display both the keybindings and the corresponding function names.
- -P: It will list of all functions along with the bindings where they appear. It is a little bit easier to read when liked to view all the keybindings for a particular function name.
- -f: It read key bindings from FILENAME. First of all, create a file containing keybindings.
cat > bind
and then write the keybinding in it for example “\C-i”: yank. Now to load keybindings from FILENAME.
bind -f bind bind -p | grep yank
- -q: It is used to view keybindings only for a specific function.
bind -q yank
- -r: Remove all bindings for the particular key sequence.
bind -r "\C-y"
- -u: It also unbinds a keybinding. It will remove the key combinations that is assigned to a particular function.
bind -u yank
- -v: It is used to view all the readline variables.
Note:To check the help page of bind command, use the following command:
- df Command in Linux with examples
- cp command in Linux with examples
- gcc command in Linux with examples
- cut command in Linux with examples
- atd command in Linux with examples
- tee command in Linux with examples
- w command in Linux with Examples
- less command in Linux with Examples
- rm command in Linux with examples
- fg command in Linux with examples
- fc Command in Linux with Examples
- help Command in Linux with examples
- rcp Command in Linux with examples
- cmp Command in Linux with examples
- let command in Linux with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.