3

我最初的问题是,在 vi 模式下使用 bash 时,我想要一种方法来区分我是处于 vi 命令模式还是 vi 插入模式。我知道从 GNU readline 7.0 开始,有一种方法可以在命令提示符中设置指示器;但是,我想要的是更改光标的形状(即在插入模式下为垂直线,在命令模式下为实心块)。


注意: 我已经尝试将以下内容放在我的 .inputrc 中,这起到了作用,但是在命令模式下移回行首时会导致一些问题,因此我得出结论,这不是一个好的选择。

set show-mode-in-prompt on
set vi-cmd-mode-string "\e[2 q"
set vi-ins-mode-string "\e[6 q"


我遇到了一篇由遇到同样问题的人写的文章,最终决定自己修补 GNU readline 库,链接如下:

http://blog.mkoskar.com/2010/10/gnu-readline-vi-mode-visualization.html http://blog.mkoskar.com/2010/11/gnu-readline-vi-mode-visualization-2 .html


到目前为止,我已经能够成功应用补丁并编译/安装库(在本地......我宁愿保持安装未打补丁的版本,以防我想切换回来),但 bash 似乎仍在使用原来的。

以下是重要的细节:

1)修补的库文件(静态和动态)位于我的计算机上$HOME/.local/lib/
2)我确定的原始库文件(仅限动态)位于/lib/x86_64-linux-gnu/
3) 我的 LD_LIBRARY_PATH 环境变量设置$HOME/.local/lib:在我的 .bashrc 中。


即使安装了修补版本并且我的 LD_LIBRARY_PATH 变量设置正确,Bash 似乎仍然没有使用我修补的 GNU readline 库。我想知道我做错了什么吗?

我希望问题不在于 Bash 附带已经静态链接的 readline 库,我想我需要重新安装 Bash(以及使用该库的任何其他程序,例如 iPython),在修补版本中手动链接的阅读线。


解决方案

虽然不是标题中列出的问题的解决方案,但这是我遇到的原始问题的解决方案。在浏览了 Readline 的手册页后,我发现了以下对vi-cmd-mode-stringand的描述vi-ins-mode-string

vi-cmd-mode-string ((cmd))
       This  string  is  displayed immediately before the last line of the primary prompt when vi editing mode is active and in command mode.  The value is expanded like a key binding, so the
       standard set of meta- and control prefixes and backslash escape sequences is available.  Use the \1 and \2 escapes to begin and end sequences of non-printing characters, which  can  be
       used to embed a terminal control sequence into the mode string.
vi-ins-mode-string ((ins))
       This  string is displayed immediately before the last line of the primary prompt when vi editing mode is active and in insertion mode.  The value is expanded like a key binding, so the
       standard set of meta- and control prefixes and backslash escape sequences is available.  Use the \1 and \2 escapes to begin and end sequences of non-printing characters, which  can  be
       used to embed a terminal control sequence into the mode string.

关于\1\2转义的部分是重要的东西......


所以基本上,将以下内容放在我的 .inputrc 中允许我根据当前的 vi 模式设置光标形状:

set show-mode-in-prompt on
set vi-cmd-mode-string "\1\e[2 q\2"
set vi-ins-mode-string "\1\e[6 q\2"
4

0 回答 0