Search code examples
vimmacvimstatuslinevim-airline

Display the current status of `expandtab` in statusline in macvim


I am currently using vim-airline in my macvim and I want to display the status of expandtab whether it is set or not in the statusline.

I can find out the status of expandtab by running the following command :set expandtab?. From the vim-airline documentation I found that I can use something like this

let g:airline_section_b = '%{getcwd()}'

I modified it to

let g:airline_section_b = '%{expandtab?}'

but I am getting the error undefined variable: expandtab.

Can someone kindly tell how I can retrieve the status of expandtab and then show it in the status line. Thanks.


Solution

  • :set does not access variables, so you cannot use the question mark to query variables.

    You are trying to access the variable expandtab variable, which doesn't exists. You actually want to access an option setting and those are accessed using the & prefix.

    Sou you should add:

    let g:airline_section_b = '%{&expandtab}'
    

    Note, the quesion mark is not necessary and has no special meaning for VimL.

    See :h expr-option for the details.

    Update This will only display 1 (expandtab set) or 0 (expandtab not set). What should work however is something like this:

    let g:airline_section_b = '%{&expandtab?"et":"noet"}'
    

    Which will display 'et' when expandtab is set or 'noet' when expandtab is not set. This uses the <cond>?<true>:<false> expression to display a certain string depening on the value of the <cond> condition. This is explained in the help below :h expr1