Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is the color of the cursor line defined?

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.

like image 428
ZyX Avatar asked Jul 16 '10 22:07

ZyX


2 Answers

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 to CursorLine if one has been set:

:echo synIDattr(synIDtrans(hlID("CursorLine")), "fg")

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 the highlight command to a variable and parse it yourself:

:redir => cursorline_highlight | silent highlight CursorLine | redir END
:echo "CursorLine highlight: " . cursorline_highlight

The color of the cursor line can be set with a highlight command like this one:

:highlight CursorLine  term=underline  guibg=#555555  cterm=underline

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:

:colorscheme desert
:colorscheme evening
:colorscheme koehler

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 any colorscheme 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:

:help :colorscheme
:help :highlight
:help hl-CursorLine
like image 170
Bill Odom Avatar answered Oct 02 '22 18:10

Bill Odom


Also check out http://vim.wikia.com/wiki/Configuring_the_cursor for some other ways to customize it

like image 45
Sam King Avatar answered Oct 02 '22 16:10

Sam King