gpt4 book ai didi

vim - 突出显示文本时更改光标背景

转载 作者:行者123 更新时间:2023-12-01 13:43:19 26 4
gpt4 key购买 nike

我通过 Ubuntu 终端使用 vim。我想在选择测试时更改光标的光标背景颜色。

文本选择将使用:

hi Visual       ctermfg=52   ctermbg=167  cterm=none

然而,这不会改变光标的背景,它也被选中但不会给人留下那种印象。

是否有我可以用来执行此操作的命令?我试过了

hi VisualCursor ...  
hi CursorVisual ...

但没有运气。

最佳答案

如注释中所述,在终端 中,光标 的前景色/背景色大部分不受 vim 的控制。 ctermfgctermbg 的设置仅适用于 text 前景/背景。请参阅 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:

How comes the cursor background color changes when selecting text then? Thing is, the bg color changes to the color of the text the cursor is on.

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com