在状态行中包含颜色字符串
我定义了一些函数
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
着色。
我该怎么做呢?
I have some function defined as
function! myfunc()
let s = 'hello world'
return s
endfunction
and I can include this in my status line as statusline=%{myfunc()}
, which nicely prints 'hello world'. I can also color it as statusline=%#mycolor#%{myfunc()}
where mycolor
is a color I've defined.
Now I want to color each of the words separately, so I redefine my function as
function! myfunc()
let s = '%#mycolor1#hello %#mycolor2#world'
return s
endfunction
However, when I set this in the status line, the output is simply the literal string "%#mycolor1#hello %#mycolor2#world"
, whereas I want hello
to be colored according to mycolor1
and world
colored according to mycolor2
.
How do I go about doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这个 vim 实用程序可以部分回答您的问题:
http://www.vim。 org/scripts/script.php?script_id=3383
所以看起来你不能在“myfunc”函数中改变颜色。但是您可以通过使用 exec 命令分配状态行来获得颜色变化,例如:
I think this vim utility may partly answer your question:
http://www.vim.org/scripts/script.php?script_id=3383
So it looks like you can't have color changes within your 'myfunc' function. But you can get color changes by assigning statusline using an exec command, e.g.: