使用搜索编辑长bash命令时是否可以移动光标,而不仅仅是箭头?像正则表达式搜索当前键入命令内部的东西。据我所知,bash本身不能做到这一点,但可能还有其他方便的解决方案吗?
答案 0 :(得分:1)
The best way achieving what you're after (if you're still wondering after ten months) is spawning the bash default editor (which can be changed with export EDITOR=vim
, on bash) using the shortcut:
Ctrl+x+e
(Hold Ctrl, then press x followed by e).
From bash man:
edit-and-execute-command (C-xC-e)
Invoke an editor on the current command line, and execute the result as shell commands. Bash attempts to invoke $VISUAL, $EDITOR, and emacs as the editor, in that order.
You'll find yourself into a vim (or vi, or nano, or other..) session, where you can write your command using every shortcut your editor provides. The downside of this approach is that, obviously, you'll lose bash shortcuts, so no tab-tab for completion during the session.
Honestly, when a command is too large, I like editing it in a text file myself, running it as a script. This allows you to test and change the command until it works, Ctrl+x+e creates instead a temp file, which is trashed once the command run.
答案 1 :(得分:0)
我个人所做的是CTRL + ArrowL / R它将逐字逐句移动光标而不是逐字。您也可以使用这些箭头:键盘上的↖↖在当前行的开头(分别为:结尾)。这背后的想法是,在编辑命令行的方式上更有效率。
但我不认为有任何命令搜索可用...或者您可以在脚本中编写它并使用文本编辑器进行搜索