光标线的颜色在哪里定义?
如果我设置 cursorline
选项,我当前的光标行会带有下划线,并且所有未指定颜色的字符也会变成黄色(只有在正常突出显示组未受影响时才会出现黄色)。我想知道这个颜色(黄色)是在哪里定义的?
编辑:我知道CursorLine
突出显示组。问题是,在我使用的默认颜色方案中,它没有定义,并且 :hi CursorLine
显示
CursorLine xxx term=underline cterm=underline
xxx 的颜色为黄色并带有下划线。我不想改变颜色,我想添加对 2html.vim
之类的插件的 cursorline
支持,所以我需要一些突出显示组/变量/等,我可以在其中得到这个黄色从。
If I set cursorline
option I get my current cursor line underlined and all characters which color is not specified also turn to yellow (yellow appears only if Normal highlight group is untouched). I wonder, where this color (yellow) is defined?
Edit: I know about CursorLine
highlight group. The problem is that in default colorscheme which I am using it is not defined and :hi CursorLine
shows
CursorLine xxx term=underline cterm=underline
where xxx is colored with yellow and underlined. I do not want to change color, I want to add cursorline
support for 2html.vim
-like plugin so I need some highlight group/variable/etc where I can get this yellow color from.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
编辑:您可以使用
synIDattr()
函数查询特定突出显示组的大部分值。例如,如果已设置,这将打印分配给CursorLine
的前景色:您还可以确定
underline
、undercurl
的状态,等等,有类似的调用。一些警告:
synIDattr()
存在错误且不完整。它有时会意外返回 -1,并且当前不允许检查所有属性。 (据称即将发布的 Vim 版本正在准备一个补丁。)请参阅以下线程以获取更多信息:synIDattr() 问题
以编程方式检测当前的“突出显示”设置?
如果
synIDattr()
不能执行您想要的操作,则将highlight
命令的输出重定向到变量并自己解析它:光标行的颜色可以使用
highlight
命令来设置,如下所示:这通常是在 Vim colorcheme 文件中完成的,该文件包含许多这样的行来定义颜色Vim 用户界面的一部分,以及常见的语法元素,如字符串、数字、关键字等。
您可以通过发出后跟方案名称的
colorscheme
命令来告诉 Vim 使用哪种颜色方案。这里有一些可以尝试的方法:但是,Vim 中包含的大多数颜色方案实际上并不包含
CursorLine
元素的突出显示命令,因此 Vim 仅使用其内置的默认光标线颜色。要更改 Vim 用于光标线的颜色,您可以在
.vimrc
文件中包含您自己的highlight
命令(在您发出任何命令之后)colorscheme
命令;否则您的突出显示颜色可能会被清除)。更好的是,您可以创建自己的颜色方案文件并在其中添加适当的突出显示语句。 (找到一个可以接受的配色方案,然后复制它并进行任何您喜欢的更改,让您变得轻松。)Vim 包含几个配色方案文件,您可以在网上找到更多。这是一个预览数百个的网站:
http://code.google.com/p/vimcolorschemetest/
有关详细信息,请参阅以下帮助主题:
Edit: You can query most of the values for a particular highlight group with the
synIDattr()
function. For example, this will print the foreground color assigned toCursorLine
if one has been set:You can also determine the state of
underline
,undercurl
, etc., with similar calls.A couple of warnings:
synIDattr()
is buggy and incomplete. It sometimes returns -1 unexpectedly, and doesn't currently allow all attributes to be inspected. (A patch is supposedly in the works for an upcoming release of Vim.) See these threads for more information:Problem with synIDattr()
Programmatically detect a current "highlight" setting?
If
synIDattr()
won't do what you want, it might be easier to redirect the output of thehighlight
command to a variable and parse it yourself:The color of the cursor line can be set with a
highlight
command like this one:This is typically done within a Vim colorscheme file, which contains many such lines to define the colors for parts of the Vim user interface, as well as for common syntactic elements like strings, numbers, keywords, etc.
You can tell Vim what colorscheme to use by issuing the
colorscheme
command followed by a scheme name. Here are a few to try:However, most of the colorschemes included with Vim don't actually contain a highlight command for the
CursorLine
element, so Vim just uses its built-in default cursorline coloring.To change the colors Vim uses for the cursorline, you can include your own
highlight
command in your.vimrc
file (after you've issued anycolorscheme
command; otherwise your highlight colors might get cleared). Better still, you can make your own colorscheme file and add the appropriate highlight statement there. (Make it easy on yourself by finding a tolerable colorscheme, then copying it and making whatever changes you like.)Vim includes several colorscheme files, and you can find many more online. Here's a site that previews a few hundred:
http://code.google.com/p/vimcolorschemetest/
See the following help topics for more info:
另请查看 http://vim.wikia.com/wiki/Configuring_the_cursor 了解其他一些方法定制它
Also check out http://vim.wikia.com/wiki/Configuring_the_cursor for some other ways to customize it
在 cooescemes 上,光标线颜色的属性称为“CursorLine”。例如,wombat colorcheme 使用以下行:
如果要更改默认的 colorcheme,文件存储在(在大多数 Linux 发行版上)/usr/share/vim/vim72/colors 上。
只有一点需要注意:CursorLine选项仅适用于Vim 7以上版本,因此,在极不可能的情况下,您曾经在7(或Vi)之前的版本中使用过该colorscheme,您应该询问colorscheme文件中的版本,例如:
On coloescemes, the property of the color of the cursorline is just called "CursorLine". For example, the wombat colorscheme uses this line:
If you want to change a default colorscheme, the files are stored (on most Linux distributions) on /usr/share/vim/vim72/colors.
Only one note: the CursorLine option only works from Vim 7 upwards, so in for the very improbable case you ever use that colorscheme with a version before 7 (or Vi), you should ask for the version on the colorscheme file, for example: