:help airline states that variables related to sections can be window-local. The example from help shows how to do it for a plugin:

  function! MyPlugin(...)
    if &filetype == 'MyPluginFileType'
      let w:airline_section_a = 'MyPlugin'
      let w:airline_section_b = '%f'
      let w:airline_section_c = '%{MyPlugin#function()}'
      let g:airline_variable_referenced_in_statusline = 'foo'
  call airline#add_statusline_func('MyPlugin')

I want to know how can I do it from the window itself, or understand a proper way to configure autocmd for this purpose. After executing :let w:airline_section_b = 'foo', the bar isn't updated. Is there a way to redraw it with new changes? I found :AirlineRefresh, but it just resets everything to defaults.

1 Answer 1


A simple way to do this would be to just run the function definition and airline function add for each window—that is, to do it from the window itself should require no modification other than removing the filetype check and changing plugin functions for your functions.

You could use an autocommand on the WinEnter event (I may have that wrong—someone feel free to edit and correct me): it could declare some kind of function or variable referenced in a global function to be used.

It occurs to me that some of the confusion is in the way the example references plugins.

A .vimrc file contains Vimscript, the special scripting language builtin to vim. It is, for all intents and purposes, an extension of the Ex commands—:global, :join, etc., are all valid Vimscript commands. And so are :function and :autocmd.

To summarize, you can just place things like

function MyFunc()
  echo 'do something here'

directly in your vimrc.

(This ability to put Vimscript code in files is not unique to 3rd-party plugins or the plugin directory of the 'runtimepath'.)

  • Thank you for the answer, but it's still not clear to me. Could you update your answer with an example? To be clear, I'm not trying to create a plugin, I just want to define regular autocmd and/or functions in vimrc. Oct 4, 2019 at 20:23
  • See update @Thunderbeef
    – D. Ben Knoble
    Oct 4, 2019 at 20:29
  • Thanks, I understand now. Unfortunately, this doesn't seem to work for terminal buffers, which was my original intention. However, the answer is still correct, so I'll accept it. Oct 6, 2019 at 14:28

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.