Vim 在statusline中包含颜色字符串

Vim 在statusline中包含颜色字符串,vim,Vim,我有一些函数定义为 function! myfunc() let s = 'hello world' return s endfunction 我可以将它作为statusline=%{myfunc()}包含在我的状态行中,很好地打印出“hello world”。我还可以将其着色为statusline=%#mycolor#%{myfunc()},其中mycolor是我定义的颜色 现在我想分别给每个单词上色,所以我将我的函数重新定义为 function! myfunc()

我有一些函数定义为

function! myfunc()
    let s = 'hello world'
    return s
endfunction
我可以将它作为
statusline=%{myfunc()}
包含在我的状态行中,很好地打印出“hello world”。我还可以将其着色为
statusline=%#mycolor#%{myfunc()}
,其中
mycolor
是我定义的颜色

现在我想分别给每个单词上色,所以我将我的函数重新定义为

function! myfunc()
    let s = '%#mycolor1#hello %#mycolor2#world'
    return s
endfunction
但是,当我在状态行中设置它时,输出的只是文本字符串
“%#mycolor1#hello%#mycolor2#world”
,而我希望
hello
根据
mycolor1
world
根据
mycolor2
着色


我该怎么做呢?

我认为这个vim实用程序可以部分回答您的问题:

因此,在“myfunc”函数中似乎不能更改颜色。但您可以通过使用exec命令指定statusline来更改颜色,例如:

:let sl_statement = 'set statusline=%#' . color1highlight .
                 \   '#%{myfunc1()}%#' . color2hl . '#%{myfunc2()}'
:exec sl_statement