问题描述
当我必须输入长命令时,有没有办法加快Linux CLI导航的速度?我现在只是简单地使用箭头,并且 – 如果我有一个很长的命令,从命令开始到其中间需要一些时间。
有没有办法让跳转到命令的中间而不使用箭头?
最佳解决方法
由Readline库提供的一些有用的行编辑键绑定:
-
Ctrl-A
:转到行首 -
Ctrl-E
:到行尾 -
Alt-B
:向后跳过一个单词 -
Alt-F
:向前跳过一个单词 -
Ctrl-U
:删除到行首 -
Ctrl-K
:删除到行尾 -
Alt-D
:删除到词尾
次佳解决方法
来自here的更多快捷方式
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用户,你可能会发现通过将set editing-mode vi
添加到~/.inputrc
或/etc/inputrc
文件中,使readline(由bash使用)可以使用vi-style编辑。或者,您可以通过运行bash命令set -o vi
使bash使用vi-style编辑。将该命令添加到您的~/.bashrc
文件以使行为持久。
如果您是zsh用户,请将bindkey -v
添加到您的.zshrc
文件以进行vi-style编辑。
第四种方法
我不知道如何在不使用光标键的情况下专门跳到中间位置。但是,我可以推荐使用CTRL +光标键从空白移到空白(即从一个单词跳转到另一个单词)。