views:

68

answers:

2

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.

+3  A: 

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
Bill Odom
A: 

On coloescemes, the property of the color of the cursorline is just called "CursorLine". For example, the wombat colorscheme uses this line:

hi CursorLine guibg=#2d2d2d

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:

if version >= 700
  hi CursorLine guibg=#2d2d2d
endif
Martín Fixman