预计阅读本页时间:-
Key Bindings Using bind
If you want to try out key bindings or you want to see what the current settings are, you can do it from the bash command line by using the bind command. The binding syntax is the same as that of the .inputrc file, but you have to surround each binding in quotes so that it is taken as one argument.
To bind a string to CTRL-T, we could type bind `"\C-t<">: <">Curiouser and curiouser!"'. This would bind the given string to CTRL-T just as in the .inputrc, except that the binding will apply only to the current shell and will cease once you log out.
广告:个人专属 VPN,独立 IP,无限流量,多机房切换,还可以屏蔽广告和恶意软件,每月最低仅 5 美元
bind also allows you to print out the bindings currently in effect by typing bind -P.[11] If you do so, you'll see things like:
abort can be found on "\C-g", "\C-x\C-g", "\e\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-char can be found on "\C-b", "\eOD", "\e[D".
...
If you just want to see the names of the readline functions, you can use bind -l.
You can also unbind a function by using bind -u along with the name of the function; all keys for that function will then be unbound. Unbinding a key sequence can be done with bind -r followed by the sequence.
bind -x is useful if you want to bind a shell command to a key sequence. For example, bind -x `"\C-l":ls' binds CTRL-L to the ls command. Hitting CTRL-L would then give a directory listing.
Another option you might find useful is -p. This prints out the bindings to standard output in a format that can be re-read by bind, or used as a .inputrc file. So, to create a complete .inputrc file that you can then edit, you could type bind -p > .inputrc.
To read the file back in again you can use another option, -f. This option takes a filename as its argument and reads the key bindings from that file. You can also use it to update the key bindings if you've just modified your .inputrc.
[10] The variables disable-completion, enable-keypad, input-meta, mark-directories, and visible-stats are not available in versions of bash prior to 2.0.
[11] Versions of bash prior to 2.0 use -d instead of -p, and -v instead of -P. Also, the -r, -V, -S, -s, -u, and the new -v and -x options are not available in these older versions.