AlexJ136
AlexJ136

Reputation: 1282

Using vi mode in readline/bash appears to break history-search

I'm very fond of using readline's history-search-forward and history-search-backward with bash. I have the following in my .inpurc:

# Scroll through matching history with up and down keys
"\e[A":history-search-backward
"\e[B":history-search-forward

and use the up and down keys to scroll through matching commands in my history.

However, when I enable vi-mode, it seems to stop the history search working. I have vi-mode configured thusly (also in .inputrc):

# Enable vi mode
set editing-mode vi
set keymap vi-command

# insert/command mode indicator:
set show-mode-in-prompt on

# Indicator formatting in prompt:
set vi-cmd-mode-string "\1\e[0;34m\2[\1\e[0m\2C\1\e[0;34m\2]\1\e[0m\2 "
set vi-ins-mode-string "\1\e[0;34m\2[\1\e[0m\2I\1\e[0;34m\2]\1\e[0m\2 "

When I remove the vi-mode related lines from my .inputrc, history search works fine. When I put them back, it breaks.

Is there a way to enable both features simultaneously?

I'm using GNU Bash 4.4.12 installed through homebrew on OSX Sierra.

Upvotes: 1

Views: 985

Answers (1)

pynexj
pynexj

Reputation: 20688

Works for me in vi-insert mode:

set editing-mode vi
set keymap vi-insert
    "\e[A":history-search-backward
    "\e[B":history-search-forward

Or you can write this in the bashrc:

set -o vi
bind -m vi-insert '"\e[A":history-search-backward'
bind -m vi-insert '"\e[B":history-search-forward'

Upvotes: 4

Related Questions