如何保留上一个命令中的光标位置?

ks1*_*322 5 shell bash command-history

当我迭代 bash 历史记录中的先前命令时,光标位置始终跳转到命令末尾。我想要某种方法来记住上次执行命令的当前光标位置。

当为某些命令尝试不同的命令行选项时,这可能很有用。现在我必须按up键并将光标向后移动到键入选项的位置才能对其进行编辑。如果可能的话,我想消除第二步。

我使用的是 bash,但其他 shell 的解决方案也很有趣。

小智 1

也许这就是您正在寻找的选择?

history-preserve-point (Off)
        If  set to On, the history code attempts to place point at the
        same location on each history line retrieved 
        with previous-history or next-history.
Run Code Online (Sandbox Code Playgroud)

要打开它,请将其添加到您的~/.inputrc

set history-preserve-point on
Run Code Online (Sandbox Code Playgroud)