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.
You need to remove the space immediately to the right of the +=.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With