Hi,

[Quoting reordered]

Benoit Thomas wrote:
> 
> On 2010-04-12 11:07, Jürgen Krämer wrote:
>>
>> Benoit Thomas wrote:
>>    
>>> I've done my own color scheme file, which work great. However, when I
>>> tried to use variable instead of color name or color number (#000000) it
>>> doesn't work and I don't know what I'm doing wrong.
>>>
>>> For example, I want to do something like this:
>>>
>>> " Text color is black.
>>> let s:text = "#000000"
>>> hi Normal guifg=s:text
>>>      
>> make this
>>
>>    exe 'hi Normal guifg=' . s:text
> 
> Thanks, works great.
>
> However, is there a more "elegant" way of doing this ? Otherwise I'll
> end up doing :
>
> exe 'hi Normal gui=' . s:text_style . ' guifg=' . s:text_fg . ' guibg='
> . s:text_bg
>
> which may become hard to read.

I don't think so, but if you need this more often you can write a short
helper function and call this, e.g.,

  function! MyHighlight(group, style, fg, bg)
    exe 'hi' a:group 'gui=' . a:style 'guifg=' . a:fg 'guibg=' . a:bg
  endfunction

  call MyHighlight('Normal', 'NONE', '#000000', '#ffffff')
  call MyHighlight('Search', 'bold', '#990000', '#ffffff')
  " ...

Note that in the "exe"-line some parts are concatenated with a dot and
some are not. In the latter case Vim automatically inserts a space
between these parts, so you can save yourself some typing and make the
command a litte bit easier to read.

If you want the function to accept empty strings whenever you don't want
to provide an argument you now have a central place:

  function! MyHighlight(group, style, fg, bg)
    exe 'hi' a:group
      \ . ' ' . (a:style != '' ? 'gui='   . a:style : '')
      \ . ' ' . (a:fg    != '' ? 'guifg=' . a:fg    : '')
      \ . ' ' . (a:bg    != '' ? 'guibg=' . a:bg    : '')
  endfunction

  call MyHighlight('Normal', '',     '#000000', '')
  call MyHighlight('Search', 'bold', '#990000', '')
  " ...

(Because of the use of the ternary operator ?: I had to use parentheses
around the different parts. This again made it necessary to insert the
spaces before every part by myself.)

Regards,
Jürgen

-- 
Sometimes I think the surest sign that intelligent life exists elsewhere
in the universe is that none of it has tried to contact us.     (Calvin)

-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

To unsubscribe, reply using "remove me" as the subject.

Reply via email to