Command Line editing and Key Binding
The main command prompt in bash also provides the ability to edit command lines and history. The latter remembers each command line so that you can execute them again.
The Edit function allows you to move forward and backward in the currently displayed command line to make changes or correct input errors. In the standard bash format, you can use the cursor key to perform basic moves. More extensive commands (such as moving forward and backward by word) can be controlled through the Readline library, which supports both VI and Emacs binding by default. To set the editing mode, you can specify your preferred mode on the command line or in the boot file: $ set editing-mode Emacs.
For example, if you use the Emacs edit mode, the following key binding takes effect:
Control-A -- this key binding positions the current position at the beginning of the row.
Control-e -- this key binding positions the current position at the end of the row.
Control-k -- this key is bound to delete all content at the end of the row.
Meta-B -- this key is bound to the backend word.
Meta-f -- this key is bound to push forward a word.
Meta-d -- this key is bound to delete the current word.
Using the internal bind bash command, you can actually bind any key or combination to a specific operation as you like. First, you can use the-P option (see Listing 1) to obtain the list of available commands.
Listing 1. Use the-P option to obtain the list of available commands
$ Bind-P
Abort can be found on "\ c-G", "\ c-x \ c-G", "\ m-\ c-g ".
Accept-line can be found on "\ c-J", "\ c-m ".
Alias-expand-line is not bound to any keys
Arrow-key-prefix is not bound to any keys
Backward-byte is not bound to any keys
...
Yank can be found on "\ c-y ".
Yank-last-Arg can be found on "\ m-.", "\ m -_".
Yank-Nth-Arg can be found on "\ m-\ c-y ".
Yank-pop can be found on "\ m-y ".
\ C references the control key. The \ m sequence references the "meta" Key (the dedicated key on some keyboards, or usually the alt or escape key ).
To set binding, you must specify the key sequence and the command to be executed. Separate them with semicolons and escape the key sequence using double quotation marks (in extreme cases, you may need to use single quotes to escape the form again ). For example, to change control-B to move backward word by word, you can use $ bind "\ c-B": backward-word.
You can even use binding to execute shell commands (for example, running an application ). To do this, you must add the-x option, which is an example of escaping twice. For example, to set control-e to run Emacs, run the following command: $ bind-X '"\ c-e"': Emacs.
To enable the bash Key Binding every time, you can set. information in the inputrc file (this file will then affect all applications with Readline enabled), or you can place specific bash bindings in the startup script, which will be described later in this article.
Turn: http://blog.chinaunix.net/uid-10435474-id-2957030.html
···