Answers:
Readline库提供了一些有用的行编辑键绑定:
Ctrl-A
:转到行首Ctrl-E
:转到行尾Alt-B
:向后跳过一个字Alt-F
:向前跳过一个字Ctrl-U
:删除到行首Ctrl-K
:删除到行尾Alt-D
:删除到单词末尾Alt-A
打开菜单而不是移动光标。您如何Alt-A
与Gnome一起使用?我的意思是,Gnome是默认设置,因此阅读此书的任何人都有可能在Gnome中运行终端。
这里还有更多捷径
Ctrl + a – go to the start of the command line
Ctrl + e – go to the end of the command line
Ctrl + k – delete from cursor to the end of the command line
Ctrl + u – delete from cursor to the start of the command line
Ctrl + w – delete from cursor to start of word (i.e. delete backwards one word)
Ctrl + y – paste word or text that was cut using one of the deletion shortcuts (such as the one above) after the cursor
Ctrl + xx – move between start of command line and current cursor position (and back again)
Alt + b – move backward one word (or go to start of word the cursor is currently on)
Alt + f – move forward one word (or go to end of word the cursor is currently on)
Alt + d – delete to end of word starting at cursor (whole word if cursor is at the beginning of word)
Alt + c – capitalize to end of word starting at cursor (whole word if cursor is at the beginning of word)
Alt + u – make uppercase from cursor to end of word
Alt + l – make lowercase from cursor to end of word
Alt + t – swap current word with previous
Ctrl + f – move forward one character
Ctrl + b – move backward one character
Ctrl + d – delete character under the cursor
Ctrl + h – delete character before the cursor
Ctrl + t – swap character under cursor with the previous one
如果您是vi [m]和bash用户,则可能会发现,将readline(供bash使用)添加set editing-mode vi
到~/.inputrc
或/etc/inputrc
文件中以使用vi样式编辑很有用。或者,您可以通过运行bash命令使bash使用vi风格的编辑set -o vi
。将命令添加到您的~/.bashrc
文件以使行为持久。
如果您是zsh用户,请添加bindkey -v
到.zshrc
文件中以进行vi样式编辑。
在您的.bashrc中获取以下代码片段。Ctrl-a跳到开头,再次按Ctrl-a跳到中间。
jump_mid() {
if [ "$READLINE_POINT" -eq "0" ]; then
LEN=${#READLINE_LINE}
POS=$(($LEN / 2))
READLINE_POINT=$POS
else
READLINE_POINT=0
fi
}
bind -x '"\C-a" : jump_mid'
或者,如果您想使用Ctrl-Something直接跳到中间,请将代码更改为:
jump_mid() {
LEN=${#READLINE_LINE}
POS=$(($LEN / 2))
READLINE_POINT=$POS
}
并将其绑定到与Ctrl-a不同的东西。
screen
用户而言,Ctrl-A变为Ctrl-