bind command in Linux with Examples - GeeksforGeeks

18 Apr, 2019
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.
Syntax:
bind [-lpsvPSVX] [-m keymap] [-q name] [-f filename] [-u name] [-r keyseq]
     [-x keyseq:shell-command] [keyseq:readline-function or readline-command]

Options:
-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.
Examples:
-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
bind -m vi
-l: List all the readline function names. There are around 150 functions that are available by default in this list.bind -l
bind -l
-p: It will display both the keybindings and the corresponding function names.bind -p
bind -p
-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.bind -P
bind -P
-f: It read key bindings from FILENAME. First of all, create a file containing keybindings.cat > bindand then write the keybinding in it for example “\C-i”: yank. Now to load keybindings from FILENAME.bind -f bind
bind -p | grep yank 

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
bind -q yank
-r: Remove all bindings for the particular key sequence.bind -r "\C-y"
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
bind -u yank
-v: It is used to view all the readline variables.bind -v
bind -v
Note:To check the help page of bind command, use the following command:
bind --help
linux-command
Linux-misc-commands
Picked
Linux-Unix
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
scp command in Linux with Examples
Docker - COPY Instruction
mv command in Linux with examples
SED command in Linux | Set 2
chown command in Linux with Examples
nohup Command in Linux with Examples
Named Pipe or FIFO with example C program
Thread functions in C/C++
uniq Command in LINUX with examples
Start/Stop/Restart Services Using Systemctl in Linux