开发者

Vim: Calling a custom function from set statusline in vimrc

开发者 https://www.devze.com 2022-12-15 04:26 出处:网络
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:

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.(l开发者_StackOverflow中文版ine=%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 +=.

0

精彩评论

暂无评论...
验证码 换一张
取 消