Bash

bash 中的鍵盤快捷鍵 Ch、Cm

  • June 24, 2016

Bash使用GNU Readline。Readline 提供了一組鍵盤快捷鍵。但是,有一些適用於 bash 的快捷方式,並且未在 Readline參考中記錄。一些例子是:

  • C-h- 與退格鍵相同
  • C-m- 與 Enter 相同(我猜是 CR)

那麼為什麼這些快捷方式有效呢?我猜這些可能與ASCII有關,但我不確定哪個組件提供了對這些控制序列的解釋,正如我所指出的那樣。

它是 Readline 庫嗎?還是 bash 本身?是我的終端模擬器嗎?是核心嗎?ETC…

是什麼組件使這些控制序列以這種方式執行?

編輯:我的.inputrc文件:

# To the extent possible under law, the author(s) have dedicated all 
# copyright and related and neighboring rights to this software to the 
# public domain worldwide. This software is distributed without any warranty. 
# You should have received a copy of the CC0 Public Domain Dedication along 
# with this software. 
# If not, see <http://creativecommons.org/publicdomain/zero/1.0/>. 

# base-files version 4.2-4

# ~/.inputrc: readline initialization file.

# The latest version as installed by the Cygwin Setup program can
# always be found at /etc/defaults/etc/skel/.inputrc

# Modifying /etc/skel/.inputrc directly will prevent
# setup from updating it.

# The copy in your home directory (~/.inputrc) is yours, please
# feel free to customise it to create a shell
# environment to your liking.  If you feel a change
# would be benifitial to all, please feel free to send
# a patch to the cygwin mailing list.

# the following line is actually
# equivalent to "\C-?": delete-char
"\e[3~": delete-char

# VT
"\e[1~": beginning-of-line
"\e[4~": end-of-line

# kvt
"\e[H": beginning-of-line
"\e[F": end-of-line

# rxvt and konsole (i.e. the KDE-app...)
"\e[7~": beginning-of-line
"\e[8~": end-of-line

# VT220
"\eOH": beginning-of-line
"\eOF": end-of-line

# Allow 8-bit input/output
#set meta-flag on
#set convert-meta off
#set input-meta on
#set output-meta on
#$if Bash
 # Don't ring bell on completion
 #set bell-style none

 # or, don't beep at me - show me
 #set bell-style visible

 # Filename completion/expansion
 #set completion-ignore-case on
 #set show-all-if-ambiguous on

 # Expand homedir name
 #set expand-tilde on

 # Append "/" to all dirnames
 #set mark-directories on
 #set mark-symlinked-directories on

 # Match all files
 #set match-hidden-files on

 # 'Magic Space'
 # Insert a space character then performs
 # a history expansion in the line
 #Space: magic-space
#$endif

綁定(無論它們是否出現在手冊中)在您鍵入時出現

bind -p

例如(部分列表):

"\C-g": abort
"\C-x\C-g": abort
"\e\C-g": abort
"\C-j": accept-line
"\C-m": accept-line
# alias-expand-line (not bound)
# arrow-key-prefix (not bound)
# backward-byte (not bound)
"\C-b": backward-char
# backward-byte (not bound)
"\C-b": backward-char
"\eOD": backward-char
"\e[D": backward-char
"\C-h": backward-delete-char
"\e[3;5~": backward-delete-char
"\C-?": backward-delete-char
"\C-x\C-?": backward-kill-line
"\e\C-h": backward-kill-word
"\e\C-?": backward-kill-word
"\eb": backward-word
"\e&lt;": beginning-of-history

該手冊記錄了該-p選項:

該**bind -p**命令以可以直接放入初始化文件的格式顯示*Readline函式名稱和綁定。*請參閱Bash 內置函式

綁定(閱讀原始碼)取決於鍵盤映射。我引用的那些來自emacs keymap,它是在應用腳本之前從內置表初始化的。有一個相應的文件,其中包含vi keymap的表。

所有這些都是Readline(與 捆綁在一起bash)的一部分。bash啟動時,它使用這些表定義綁定。根據它讀取的其他文件/etc/inputrc~/.inputrc它可能會添加、修改或刪除其中一些內置綁定。

引用自:https://unix.stackexchange.com/questions/291625