So I was setting up my status line and I wanted a function which gives the icon of current file type. But it has to be in string.

  str="{some icon}"
  return str

so far so good

But now I need colored ones because why not?

So I came across something like this

  local str = {}
  str.str = "{some_icon}"
  str.hl = {fg="#FFFFFF",}
  return str

but now str is not a string.

Is there a way to convert it to string while keeping its color? Or all together is there a better way to get a colored icon as string? And also without loading any plugins.

I use feline plugin to setup the statusline....below is an example for a component config

        vim_status = {
        provider = function()
            local s
            if require('lazy.status').has_updates() then
                s = require('lazy.status').updates()
                s = ' '
            s = string.format(' %s', s)
            return s
        hl =vi_mode_hl ,
                right_sep = {
            always_visible = true,
            str =  "",
            hl = vi_sep_hl,

I want to pass the icon to the provider field and this takes only string values

  • It would be helpful if you could share the full code. You mention status line so I suppose you somehow set the statusline option. It would be good if you could share the code that set your status line. Jan 25 at 5:57

1 Answer 1


To control the color of the text of the status line you have to use highlighting groups and a special %#...#... syntax for the return value of your provider.

e.g.: To have Foo in green in your status line you could do:

highlight Green guifg=#008000
set statusline=%#Green#Foo
  • 1
    Fwiw the User1 through 9 groups are specifically intended for statusline highlights.
    – D. Ben Knoble
    Jan 25 at 16:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.