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

时间:2016-06-25 14:46:49

标签: vim gnome-terminal

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

文本选择将使用:

完成
hi Visual       ctermfg=52   ctermbg=167  cterm=none

但是这不会改变光标的背景,也会选择但不会给人留下印象。

我可以使用命令来执行此操作吗?我试过了

hi VisualCursor ...  
hi CursorVisual ...

但没有运气。

1 个答案:

答案 0 :(得分:3)

如评论中所述,在终端中,光标的前景/背景颜色主要来自vim的控件。 ctermfgctermbg的设置仅适用于文本前景/背景。请参阅标题为" 2的部分。在vim documentation中突出显示颜色终端的参数" ,其中描述了这些参数。

这些设置对应于 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.
     */

VTE documentation,就像它一样,是从注释中生成的(在这种情况下模仿JavaDoc)。因此,阅读源代码是了解程序功能的唯一方法。评论同意OP提出的其他问题:

  

当选择文本时,光标背景颜色如何变化?事实是,bg颜色会变为光标所在文本的颜色。

VTE中的各个功能模仿xterm的功能,可以更好地控制颜色的管理方式。例如,VTE识别允许xtermcontrol从shell命令更改光标颜色的控制序列。控制序列记录在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.