Vim statusline does not expand color/highlight group from expression

被刻印的时光 ゝ 提交于 2019-12-14 03:49:40

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/31805367/vim-statusline-does-not-expand-color-highlight-group-from-expression

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!