Unknown option: \ %{SetTimeOfDayColors()}
Asked Answered
I

1

0

Here is my .vimrc config file according to the book <<learning the vi and vim>> p201-203.

function SetTimeOfDayColors()
    let currentHour = strftime("%H")
    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 += \ %{SetTimeOfDayColors()}

An error occur when to vim test.txt.

line 15: E518: Unknown option: \ %{SetTimeOfDayColors()} Press ENTER or type command to continue

What is the matter with the codes here?

Ingleside answered 11/8, 2017 at 6:1 Comment(1)
just remove the space after the +=Amy
F
1

You must not use whitespace around the = (or +=) assignment of :set:

set statusline+=\ %{SetTimeOfDayColors()}

You've properly escaped the leading space, though. Here, this is easy to fix; for more complicated modifications, it can be useful to switch to :let instead:

let &statusline .= ' %{SetTimeOfDayColors()}'

As :let deals with variables (and the &statusline is a special case referring to an option), you can have whitespace here, and do not need to escape whitespace, because the right-hand side is an expression (here: a quoted string).

Ferreous answered 11/8, 2017 at 7:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.