To set Readline key bindings and variables in the Linux system, we use the bind command.
The bind is used to assign functions and macros to a key. It allows to create hotkeys instead of typing the entire command. The bind command available in the shell built-in command.
The syntax of the bind command is as follows.
bind [-lpsvPSVX] [-m KEYMAP] [-f FILENAME] [-q NAME] [-u NAME] [-r KEYSEQ] [-x KEYSEQ:shell-command]
The general syntax of the bind command seems so complicated, but the bind command is simple to use and we can easily create macros.
Brief description of options available in the bind command.
|Sr.No.||Option & Description|
Display the list names of functions
Display the list names of functions and bindings
Display list functions and bindings in a form that can be reused as input
Display the list of key sequences that invoke macros and their values in a form that can be reused as input
Display variable names and values
Display variable names and values in a form that can be reused as input
Query about which keys invoke the named functions
Remove the binding for KEYSEQ
Read key bindings form FILENAME
Displays a help message and then exits.
It gives info about the version and then exits.
To list all the readline functions names, we use -l option with the bind command in the Linux system as shown below.
$ bind -l
To list the keybindings and the corresponding function names, we use -p option with the bind command in the Linux system as shown below.
$ bind -p
Here, we will create a custom key bind in the Linux system. To pint “Hey, welcome to tutorialspoint!” we will use CTRL + v to print this message on the terminal.
$ bind ‘” \C-v”:” Hey, Welcome to tutorialspoint!”’
After executing the above command, a new custom key bind will be created. To print “Hey, welcome to tutorialspoint!” just have to enter CTRL + v instead of typing the whole message. To list the all-custom key bindings, we use the -x option with the bind command as shown below
$ bind -x
To remove an existing key binding in the Linux system, we use -r option with the bind command as shown below
$ bind -r “\C-v”
To display more information about the bind command, we use the --help option with the bind command as shown below.
$ bind --help