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

后端 未结 5 1159
北荒
北荒 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 04:14

    If set enable-keypad on is in your ~/.inputrc as some st (suckless simple terminal) users might, be aware that the arrows keys are in keypad mode. Ubuntu ships with this useful /usr/share/doc/bash/inputrc.arrows:

    # This file controls the behaviour of line input editing for
    # programs that use the Gnu Readline library.
    #
    # Arrow keys in keypad mode
    #
    "\C-[OD"        backward-char
    "\C-[OC"        forward-char
    "\C-[OA"        previous-history
    "\C-[OB"        next-history
    #
    # Arrow keys in ANSI mode
    #
    "\C-[[D"        backward-char
    "\C-[[C"        forward-char
    "\C-[[A"        previous-history
    "\C-[[B"        next-history
    #
    # Arrow keys in 8 bit keypad mode
    #
    "\C-M-OD"       backward-char
    "\C-M-OC"       forward-char
    "\C-M-OA"       previous-history
    "\C-M-OB"       next-history
    #
    # Arrow keys in 8 bit ANSI mode
    #
    "\C-M-[D"       backward-char
    "\C-M-[C"       forward-char
    "\C-M-[A"       previous-history
    "\C-M-[B"       next-history
    

    So I'm not sure if you'll need all, but it might not hurt to have in your ~/.inputrc:

    # Arrow keys in keypad mode
    "\C-[OA": history-search-backward
    "\C-[OB": history-search-forward
    "\C-[OC": forward-char
    "\C-[OD": backward-char
    
    # Arrow keys in ANSI mode
    "\C-[[A": history-search-backward
    "\C-[[B": history-search-forward
    "\C-[[C": forward-char
    "\C-[[D": backward-char
    

    This is also on the same topic: My cursor keys do not work and also this xterm: special keys

提交回复
热议问题