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