问题
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