Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: Calling a custom function from set statusline in vimrc

Tags:

vim

I'm trying to implement the vim script from the book Learning vi and vim on page 202. The following function works, but when I try to use statusline to call it I get the following error:

$ vim
$ Error detected while processing /Users/me/.vimrc:
E518: Unknown option: \ %{SetTimeOfDayColors()}

Here's the vim script (it's currently in my .vimrc)

function SetTimeOfDayColors()
    let currentHour = strftime("%H")
    echo "currentHour is " . currentHour
    if currentHour < 6 + 0
      let colorScheme = "darkblue"
    elseif currentHour < 12 + 0
      let colorScheme = "morning"
    elseif currentHour < 18 + 0
      let colorScheme = "shine"
    else
      let colorScheme = "evening"
    endif
    echo "setting color scheme to " . colorScheme
    execute "colorscheme " . colorScheme
endfunction
set statusline=%<%f\ %h%m%r%=%-20.(line=%l,col=%c%V,totlin=%L%)\%h%m%r%=%-40(,bytval=0x%B,%n%Y%)\ %{strftime(\"%c\")}%=0x%B\ %P
set statusline += \ %{SetTimeOfDayColors()}

The purpose of the last line is to have vim check the time whenever I make an edit and run the custom function. But I can't get it to work. Any suggestions? Thanks.

like image 820
Rob Avatar asked Dec 23 '09 14:12

Rob


1 Answers

You need to remove the space immediately to the right of the +=.

like image 112
Michał Marczyk Avatar answered Sep 16 '22 18:09

Michał Marczyk