statusline不从表达式展开颜色

statusline不从表达式展开颜色

本文介绍了Vim statusline不从表达式展开颜色/突出显示组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个函数,它返回一个字符串:

  StatusBricks()
let l:stat = Brick(statusbricks#ReportLinecount('raw'),{
\'brick_color':'LineNr',
\'delimiter_position':'right ',
\'delimiter_right':'❯'
\})
return l:stat
endfunction

结果具有以下格式,由 Brick()生成:

 %#HighlightGroup#SomeData 

我使用函数作为状态行内的表达式,我期望突出显示组得到扩展,以便为适当的状态行部分着色:

  set statusline =%{StatusBricks()} 

但是我得到的是一个statusline字面上显示%#HighlightGroup#ExpandedData ,而不是 ExpandedData





我做错了什么?

解决方案

%{的结果不会进一步解释, c $ c>%!是。使用

  set statusline =%!StatusBricks()

%!在帮助文件中似乎没有标签,但在<$ c $ 如果您要在状态行中使用不同的颜色,请选择 在每个特定窗口的状态,然后你可以突出显示一个空字符串,如果你不想显示特定的高亮。例如

  set stl =%#error#%r%#search#
/ pre>

只读只读窗口(例如打开帮助缓冲区)将使只读标志显示为红色。诚然,这可能会变得复杂,取决于您的突出显示要求。


I wrote a function which returns a string:

function! StatusBricks()
    let l:stat = Brick(statusbricks#ReportLinecount('raw'), {
        \ 'brick_color': 'LineNr',
        \ 'delimiter_position': 'right',
        \ 'delimiter_right': '❯'
        \ })
    return l:stat
endfunction

The result has the following format, generated by Brick():

%#HighlightGroup#SomeData

When I use the function as an expression inside the statusline I expect the highlight group to get expanded in order to colorize the appropriate statusline section:

set statusline =%{StatusBricks()}

But what I get is a statusline literally showing %#HighlightGroup#ExpandedData rather than ExpandedData:

What am I doing wrong?

解决方案

The result of %{ isn't interpreted further, however the result of %! is. Use

set statusline=%!StatusBricks()

%! doesn't appear to have a tag in the helpfile, but it's mentioned near the beginning of :help 'statusline'.

Following your comment: if you want different colours in the statusline depending on the state of each particular window, then you can highlight an empty string if you don't want a particular highlight to appear. E.g.

set stl=%#error#%r%#search#

Only read-only windows (e.g. open a help buffer) will have the read-only flag displayed in red. Admittedly this can get complicated depending on your highlighting requirements.

这篇关于Vim statusline不从表达式展开颜色/突出显示组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 11:48