bashrcinput-history

Make Ctrl-p and Ctrl-n search the shell history filtered by typed characters


I love that emacs key bindings also work in the ubuntu shell by default. However, I would also like to have those two keys partially search through the shell history but filtered based on what was already typed in. If enabled in /etc/inputrc, the normal page up and page down keys do just that, but I don't have those keys and thus would like to use Ctrl-p and Ctrl-n for that as well. I have seen this working in the zshell but I am using bash. How can I achieve that?


Solution

  • To use the typed string as a prefix for searching forward/backward in the history, add the following bindings to your ~/.inputrc

    "\C-p": history-search-backward
    "\C-n": history-search-forward