You should try binding UP/DOWN to history-search-backward and history-search-forward[1]. Adding this to your ~/.inputrc
"\e[A": history-search-backward
"\e[B": history-search-forward
enables searching by the current line's prefix in all programs that use readline (a lot of languages use readline for their REPL). That is, if you type "cp<UP>" you immediately get the previous command that started with "cp", regardless of how far back it is in your history.[1] https://codeinthehole.com/tips/the-most-important-command-li...