Where is the color of the cursor line defined?
Asked Answered
B

3

7

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.

Billiton answered 16/7, 2010 at 22:15 Comment(2)
Belongs on superuser.comGomes
See my edited response below based on your update.Quiddity
Q
6

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
Quiddity answered 17/7, 2010 at 4:37 Comment(0)
L
1

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

Lao answered 17/3, 2011 at 9:57 Comment(0)
S
0

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
Sher answered 17/7, 2010 at 4:58 Comment(1)
It's not advisable to change the files in /usr/share/vim or any other system-wide location, otherwise when you upgrade vim you have to save and move them. If you like one of them and just want to change something, copy that file into your own ~/.vim/colors/whatever.vim (I recommend you rename it to a new name of your choosing). Now edit that file and change the let g:colors_name to the name you chose for the file and change/add any highlight groups you want. Note, on windows your user-specific path will be $HOME\vimfiles. You can see the paths vim uses at runtime with :set rtp?.Evidence

© 2022 - 2024 — McMap. All rights reserved.