配置向上箭头以浏览以已键入字符开头的命令

Configure up-arrow to browse through commands starting with already typed characters

这是一个自我回答 post。

在 octave-3.8.2 命令行上,向上箭头仅调用以当前行中已键入的字符开头的命令。

例如,最近的八度 (4.2.0) 中已丢失此行为。

如何恢复以前的行为?

Octave 现在使用 ~/.inputrc(如果存在),而不是默认的 octave/4.2.0/m/startup/inputrc

随时可以使用另一个readline配置readline_read_init_file

如果要在所有 readline 程序之间共享行为(例如 bash),则只需将以下内容(取自 this answer,对于 bash)添加到您的 ~/.inputrc:

# allow to enter the first characters of a command, 
# and then use the Up and Down keys to move through only those commands 
# in history that begin with that string.
"\e[A": history-search-backward            # arrow up
"\e[B": history-search-forward             # arrow down

如果只对八度音阶执行此操作,一种方法是将这些行换行在 $if octave ... $else ... $endif:

之间
$if octave
"\e[A": history-search-backward            # arrow up
"\e[B": history-search-forward             # arrow down
$endif

另一种方法是在 ~/.octaverc.

中发出 readline_read_init_file("~/.octave_inputrc")