【问题标题】:Using vi mode in readline/bash appears to break history-search在 readline/bash 中使用 vi 模式似乎会破坏历史搜索
【发布时间】:2017-08-14 13:00:40
【问题描述】:

我非常喜欢在 bash 中使用 readline 的 history-search-forwardhistory-search-backward。我的.inpurc 中有以下内容:

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

并使用向上和向下键滚动浏览我历史记录中的匹配命令。

但是,当我启用 vi 模式时,它似乎停止了历史搜索工作。我已经这样配置了 vi 模式(也在 .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 "

当我从.inputrc 中删除与 vi 模式相关的行时,历史搜索工作正常。当我把它们放回去时,它就坏了。

有没有办法同时启用这两个功能?

我在 OSX Sierra 上使用通过自制软件安装的 GNU Bash 4.4.12。

【问题讨论】:

  • 我投票结束这个问题,因为它不是一个编程问题,所以更适合U&L

标签: bash shell command-line vi readline


【解决方案1】:

vi-insert 模式下为我工作:

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

或者你可以写在bashrc:

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

【讨论】:

    猜你喜欢
    • 2018-03-19
    • 1970-01-01
    • 1970-01-01
    • 2014-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多