我通过 Ubuntu 终端使用 vim。我想在选择测试时更改光标的光标背景颜色。
文本选择将使用:
hi Visual ctermfg=52 ctermbg=167 cterm=none
然而,这不会改变光标的背景,它也被选中但不会给人这种印象。
是否有我可以使用的命令来执行此操作?我试过了
hi VisualCursor ...
hi CursorVisual ...
但没有运气。
最佳答案
如评论中所述,在终端中,光标的前景色/背景色大多不受 vim 控制。 ctermfg
和 ctermbg
的设置仅适用于文本前景/背景。请参阅 vim documentation 中标题为“2. 突出显示颜色终端的参数”的部分,其中描述了这些。
这些设置对应于 ANSI 转义序列 (ECMA-48)。光标颜色没有相应的标准:
同样,当您使用鼠标选择文本时,光标颜色更改(或不更改)的方式也没有标准:
没有提到实际使用的终端;假设默认终端是 gnome-terminal。所有相关功能都在 VTE library 中。其中一些会随着时间而变化,但在当前代码中,要查看的位置在
vtegtk.cc
(尽管它也有助于阅读 vte.cc
):/** * vte_terminal_set_color_cursor: * @terminal: a #VteTerminal * @cursor_background: (allow-none): the new color to use for the text cursor, or %NULL * * Sets the background color for text which is under the cursor. If %NULL, text * under the cursor will be drawn with foreground and background colors * reversed. */
/** * vte_terminal_set_color_cursor_foreground: * @terminal: a #VteTerminal * @cursor_foreground: (allow-none): the new color to use for the text cursor, or %NULL * * Sets the foreground color for text which is under the cursor. If %NULL, text * under the cursor will be drawn with foreground and background colors * reversed. * * Since: 0.44 */
/** * vte_terminal_set_color_highlight_foreground: * @terminal: a #VteTerminal * @highlight_foreground: (allow-none): the new color to use for highlighted text, or %NULL * * Sets the foreground color for text which is highlighted. If %NULL, * it is unset. If neither highlight background nor highlight foreground are set, * highlighted text (which is usually highlighted because it is selected) will * be drawn with foreground and background colors reversed. */
The VTE documentation, such as it is, is generated from the comments (imitating JavaDoc, in this case). So reading the source code is the only way to understand what the program does. The comments agree with OP's additional question asked:
The individual functions in VTE imitate features of xterm, which provides more control over the way colors are managed. For instance, VTE recognizes the control sequence which lets xtermcontrol
change the cursor color from a shell command. The control sequence is documented in XTerm Control Sequences:
Ps = 1 2 -> Change text cursor color to Pt.
这样做会覆盖评论中提到的反向视频方案。引用 xterm manual 给出了一些可以在 VTE 中实现的替代方案:
highlightColor (class HighlightColor)
Specifies the color to use for the background of selected
(highlighted) text. If not specified (i.e., matching the
default foreground), reverse video is used. The default is
"XtDefaultForeground".
highlightColorMode (class HighlightColorMode)
Specifies whether xterm should use highlightTextColor and high-
lightColor to override the reversed foreground/background col-
ors in a selection. The default is unspecified: at startup,
xterm checks if those resources are set to something other than
the default foreground and background colors. Setting this
resource disables the check.
关于vim - 突出显示文本时更改光标背景,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38029670/