bind 命令详解

| 选择喜欢的代码风格  

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

bind 命令安装:


-bash/zsh: bind command not found

#Debian
apt-get install kbd

#Ubuntu
apt-get install kbd

#Alpine
apk add kbd

#Arch Linux
pacman -S kbd

#Kali Linux
apt-get install kbd

#CentOS
yum install kbd

#Fedora
dnf install kbd

#Raspbian
apt-get install kbd

#Docker
docker run cmd.cat/showkey showkey

bind 命令补充说明:


bind 命令用于显示和设置命令行的键盘序列绑定功能。通过这一命令,可以提高命令行中操作效率。您可以利用 bind 命令了解有哪些按键组合与其功能,也可以自行指定要用哪些按键组合。

bind 命令语法:


bind [-m keymap] [-lpsvPSV]
bind [-m keymap] [-q function] [-u function] [-r keyseq]
bind [-m keymap] -f filename
bind [-m keymap] -x keyseq:shell-command
bind [-m keymap] keyseq:function-name
bind readline-command

bind 命令选项:


-d:显示按键配置的内容;
-f<按键配置文件>:载入指定的按键配置文件;
-l:列出所有的功能;
-m<按键配置>:指定按键配置;
-q<功能>:显示指定功能的按键;
-v:列出目前的按键配置与其功能。

bind 命令实例:


bind -x '"\C-l":ls -l'    #直接按 CTRL+L 就列出目录

其中 keyseq 可以使用 showkey -a 命令来获取:

[root@localhost ~]
$ showkey -a

Press any keys - Ctrl-D will terminate this program

^[[A     27 0033 0x1b  上
         91 0133 0x5b
         65 0101 0x41
^[[B     27 0033 0x1b  下
         91 0133 0x5b
         66 0102 0x42
^[[D     27 0033 0x1b  左
         91 0133 0x5b
         68 0104 0x44
^[[C     27 0033 0x1b 右
         91 0133 0x5b
         67 0103 0x43
         32 0040 0x20
^M       13 0015 0x0d 字母M
^C        3 0003 0x03 Ctrl-C
^D        4 0004 0x04 Ctrl-D 退出

bind 显示当前按键组合的设置:

$ bind -l
abort
accept-line
alias-expand-line
arrow-key-prefix
backward-byte
backward-char
backward-delete-char
backward-kill-line
backward-kill-word
backward-word
beginning-of-history
beginning-of-line
call-last-kbd-macro
capitalize-word
character-search
character-search-backward
clear-screen
complete
complete-command
complete-filename
complete-hostname
complete-into-braces
complete-username
complete-variable
copy-backward-word
copy-forward-word
copy-region-as-kill
dabbrev-expand
delete-char
delete-char-or-list
delete-horizontal-space
digit-argument
display-shell-version
do-lowercase-version
downcase-word
dump-functions
dump-macros
dump-variables
dynamic-complete-history
edit-and-execute-command
emacs-editing-mode
end-kbd-macro
end-of-history
end-of-line
exchange-point-and-mark
forward-backward-delete-char
forward-byte
forward-char
forward-search-history
forward-word
glob-complete-word
glob-expand-word
glob-list-expansions
history-and-alias-expand-line
history-expand-line
history-search-backward
history-search-forward
insert-comment
insert-completions
insert-last-argument
kill-line
kill-region
kill-whole-line
kill-word
magic-space
menu-complete
menu-complete-backward
next-history
non-incremental-forward-search-history
non-incremental-forward-search-history-again
non-incremental-reverse-search-history
non-incremental-reverse-search-history-again
old-menu-complete
operate-and-get-next
overwrite-mode
possible-command-completions
possible-completions
possible-filename-completions
possible-hostname-completions
possible-username-completions
possible-variable-completions
previous-history
quoted-insert
redraw-current-line
re-read-init-file
reverse-search-history
revert-line
self-insert
set-mark
shell-backward-kill-word
shell-backward-word
shell-expand-line
shell-forward-word
shell-kill-word
skip-csi-sequence
start-kbd-macro
tab-insert
tilde-expand
transpose-chars
transpose-words
tty-status
undo
universal-argument
unix-filename-rubout
unix-line-discard
unix-word-rubout
upcase-word
vi-append-eol
vi-append-mode
vi-arg-digit
vi-back-to-indent
vi-backward-bigword
vi-backward-word
vi-bword
vi-bWord
vi-change-case
vi-change-char
vi-change-to
vi-char-search
vi-column
vi-complete
vi-delete
vi-delete-to
vi-editing-mode
vi-end-bigword
vi-end-word
vi-eof-maybe
vi-eword
vi-eWord
vi-fetch-history
vi-first-print
vi-forward-bigword
vi-forward-word
vi-fword
vi-fWord
vi-goto-mark
vi-insert-beg
vi-insertion-mode
vi-match
vi-movement-mode
vi-next-word
vi-overstrike
vi-overstrike-delete
vi-prev-word
vi-put
vi-redo
vi-replace
vi-rubout
vi-search
vi-search-again
vi-set-mark
vi-subst
vi-tilde-expand
vi-yank-arg
vi-yank-to
yank
yank-last-arg
yank-nth-arg
yank-pop

bind 扩展阅读:




bind 命令评论