How do I change bash history completion to complete what's already on the line?

后端 未结 5 1154
北荒
北荒 2020-12-02 03:54

I found a command a couple of months ago that made my bash history auto-complete on what\'s already on the line when pressing the up arrow:

$ vim fi
         


        
5条回答
  •  隐瞒了意图╮
    2020-12-02 03:56

    Probably something like

    # ~/.inputrc
    "\e[A": history-search-backward
    "\e[B": history-search-forward
    

    or equivalently,

    # ~/.bashrc
    if [[ $- == *i* ]]
    then
        bind '"\e[A": history-search-backward'
        bind '"\e[B": history-search-forward'
    fi
    

    (the if statement checks for interactive mode)

    Normally, Up and Down are bound to the Readline functions previous-history and next-history respectively. I prefer to bind PgUp/PgDn to these functions, instead of displacing the normal operation of Up/Down.

    # ~/.inputrc
    "\e[5~": history-search-backward
    "\e[6~": history-search-forward
    

    After you modify ~/.inputrc, restart your shell or use Ctrl+X, Ctrl+R to tell it to re-read ~/.inputrc.


    By the way, if you're looking for relevant documentation:

    Bash uses The GNU Readline Library for the shell prompt and history.

提交回复
热议问题