opt*_*nal 25 keyboard-shortcuts bash command-line key-binding
在bash,所述home/ end/delete键被插入,或者如果前面由逃逸密钥的代字号:[1~
所以我输入echo hellp,将光标移动到hel|lp并输入删除,然后bam,我得到了~tilde
另外,我输入echo hellp,将光标移到hel|lp并输入 esc 然后删除,然后 bam,我得到了[3~
$ echo hel~lp
hel~lp
$ echo hell[3~o
hell[3~o
~
Run Code Online (Sandbox Code Playgroud)
我的 bash 版本:
$ bash --version
GNU bash, version 3.1.17(1)-release (i686-pc-msys)
Copyright (C) 2005 Free Software Foundation, Inc.
Run Code Online (Sandbox Code Playgroud)
我想要的是这样的行为cmd.exe:
我必须编辑什么来解决这个问题?这是您的 bash 的默认设置吗?
更新:我在运行 Windows 程序 sh.exe(如您在 GNU bash 上面所见)的 Windows 机器上,使用 mingw 为 msys 编译:
$ uname -s -m -o
MINGW32_NT-5.1 i686 Msys
Run Code Online (Sandbox Code Playgroud)
opt*_*nal 27
您可以通过 .bash 中的.inputrc文件自定义 bash /home/username,您可以复制默认的
cp /etc/inputrc.default ~/.inputrc
Run Code Online (Sandbox Code Playgroud)
这是我的(评论以 # 开头)
# Key-bindings for the command-line editor.
# Ask before displaying >50 items
# Since $WINDIR $PATH var can be in $PATH, this could list
# all window exectables in C:\WINDOWS
set completion-query-items 50
# Ignore case for the command-line-completion functionality
# on: default to a Windows style console
# off: default to a *nix style console
set completion-ignore-case on
# none, visible or audible
set bell-style audible
# disable/enable 8bit input
set meta-flag on
set input-meta on
set output-meta off
set convert-meta on
# visible-stats
# Append a mark according to the file type in a listing
set visible-stats off
set mark-directories on
# Show all instead of beeping first
set show-all-if-ambiguous off
# MSYSTEM is emacs based
$if mode=emacs
# Common to Console & RXVT
"\C-?": backward-kill-line # Ctrl-BackSpace
"\e[2~": paste-from-clipboard # "Ins. Key"
"\e[5~": beginning-of-history # Page up
"\e[6~": end-of-history # Page down
$if term=msys # RXVT
"\e[7~": beginning-of-line # Home Key
"\e[8~": end-of-line # End Key
"\e[11~": display-shell-version # F1
"\e[15~": re-read-init-file # F5
#$endif
#$if term=cygwin # Console
$else
"\e[1~": beginning-of-line # Home Key
"\e[4~": end-of-line # End Key
"\e[3~": delete-char # Delete Key
#~ "\e\e[D": backward-word # Alt-LeftArrow
#~ "\e\e[C": forward-word # Alt-RightArrow
"\M-\e[D": backward-word # Alt-LeftArrow
"\M-\e[C": forward-word # Alt-RightArrow
`#~` "\C-\E[D": backward-word # Ctrl-LeftArrow, nowork, can't be made to work
#~`enter preformatted text here` "\C-\E[C": forward-word # Ctrl-RightArrow, nowork, can't be made to work
#~ to see current bindings use bind -q backward-kill-line
"\e\e": kill-whole-line # double/triple escape works :) Esc/Escape to delete current line like cmd.exe
$endif
$endif
Run Code Online (Sandbox Code Playgroud)
找出您需要在左侧的 inputrc 中键入的内容(转义码,因为它可能因笔记本电脑/台式机而异...),在提示下键入echo '然后键入Ctrl-V后跟键,例如Home,然后键入'
示例
$ echo ' home key ^[[1~ '
home key
~
$ echo ' end key ^[[4~ '
end key
~
$ echo ' pg up page up ^[[5~ '
pg up page up
~
$ echo ' pg dn page down ^[[6~ '
pg dn page down
~
Run Code Online (Sandbox Code Playgroud)
然后替换每个^[与\e
附加\M-了Alt
理论上你会使用\C-的Ctrl,但它目前不工作(Windows的限制)
可用命令(如backward-kill-line)列在http://www.gnu.org/software/bash/manual/bashref.html#index-backward_002dkill_002dline-_0028C_002dx-Rubout_0029
您可以使用bind -p或查看现有的键盘快捷键/绑定
$ bind -q backward-kill-word
backward-kill-word can be invoked via "\M-\C-h", "\M-\C-?".
~
$ bind -q backward-word
backward-word can be invoked via "\M-\M-[D", "\M-b", "\C-\E[[D".
~
$ bind -q beginning-of-line
beginning-of-line can be invoked via "\C-a", "\M-OH", "\M-[1~", "\M-[H".
~
Run Code Online (Sandbox Code Playgroud)
不要惹 TERMCAP
如果在最近的 Debian/Ubuntu 的最小安装上发生这种情况,可能是因为您还没有安装该readline-common软件包。只需安装该软件包即可解决该问题。
例如,在带有 Debian Stretch 的 Docker 上输入ls HOME:
$ docker run --rm -it debian:stretch
root@6ae7baea9e5a:/# ls~
$ docker run -it --name=debian-stretch-readline-temp debian:stretch
root@2092cb968232:/# apt-get update
root@2092cb968232:/# apt-get install readline-common
$ docker commit debian-stretch-readline-temp debian-stretch-with-readline
$ docker run --rm -it debian-stretch-with-readline
root@53739343e9f7:/# ls
Run Code Online (Sandbox Code Playgroud)
请注意,安装 readline-common 后,它只会对新的登录 shell 起作用。
好吧,既然您说您在 Windows 上工作并且没有使用适当的终端模拟器,例如 PuTTY(使用mintty、puttycyg 等),我建议您查阅readline 文档并了解 readline 的快捷方式。从长远来看会更好。
如果您要使用终端仿真器而不是 Windows 附带的控制台窗口(这里不讨论解释器/shell),您将获得一个更可配置的替代方案。一旦您尝试使用 Vim 等其他程序,情况只会变得更糟。
要点:使用合适的终端模拟器,即使是在 Windows 上,或者学习 readline 快捷方式。我测试了我刚才最常用的那些,它们可以与msys.bat.
mingw-get install mintty && mintty
Run Code Online (Sandbox Code Playgroud)
要编辑的文件将是/usr/share/terminfo(在 MinGW 中不存在) - 用于tic“编译”规则(甚至不包括在内,因为每个人都知道支持会严重受损)。但是,我还没有看到任何有用的开发可以使它在 Windows 上几乎可用。这就是为什么您应该首先使用合适的终端仿真器。但我确信外科医生将能够使用菜刀进行手术,那么为什么不使用 Windows 内置的控制台窗口呢?祝你好运。
| 归档时间: |
|
| 查看次数: |
19121 次 |
| 最近记录: |