
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Create Key Binds in Linux Using the Terminal
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.
Syntax
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 |
---|---|
1 |
-I Display the list names of functions |
2 |
-P Display the list names of functions and bindings |
3 |
-p Display list functions and bindings in a form that can be reused as input |
4 |
-S Display the list of key sequences that invoke macros and their values in a form that can be reused as input |
5 |
-V Display variable names and values |
6 |
-v Display variable names and values in a form that can be reused as input |
7 |
-q function-name Query about which keys invoke the named functions |
8 |
-r KEYSEQ Remove the binding for KEYSEQ |
9 |
-f FILENAME Read key bindings form FILENAME |
10 |
--help Displays a help message and then exits. |
11 |
--version 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