0

When a variable on which a statusline depends changes, I see the result only in statuslines of active windows. Can inactive ones be made to see those changes too?

4
  • 2
    Nothing happens in an inactive window so there's no reason for the status line of an inactive window to change.
    – romainl
    Apr 23 '16 at 14:04
  • @romainl true, but things might happen outside: a git repo might no longer have modifications, a file might have been changed externally, etc.
    – muru
    Apr 25 '16 at 1:21
  • @muru, all things that have nothing to do with the status of the current window/buffer.
    – romainl
    Apr 25 '16 at 5:22
  • @romainl so? The inactive window can have status lines.
    – muru
    Apr 25 '16 at 5:23
2

Edit: As @Christian Brabandt mentioned in this comment, the Ex command :redrawstatus does the same thing as the 'readonly' hack, and is probably even better. From :help redraws:

                        *:redraws* *:redrawstatus*
:redraws[tatus][!]  Redraw the status line of the current window.  When !
            is included all status lines are redrawn.
            Useful to update the status line(s) when 'statusline'
            includes an item that doesn't cause automatic
            updating.

So, after assigning a new value to your variable you could add | redraws! like this:

:let g:myvar='bar' | redraws!

The bang is necessary to update all the status lines, and not just the one of the current window.


I don't know why but it seems that setting the value of the 'readonly' option has also the side-effect of updating the status lines.

In :help 'statusline', they mention this:

If the statusline is not updated when you want it (e.g., after setting
a variable that's used in an expression), you can force an update by
setting an option without changing its value.  Example: >
    :let &ro = &ro

So, suppose you have a variable g:myvar whose value is 'foo' and appears in your status line:

let g:myvar='foo'
set stl+=%{g:myvar}

And you want to change its value to 'bar' as well as the change to be reflected in every status line. Maybe you could type:

:let g:myvar='bar' | let &l:ro = &l:ro

(&l:ro is the local-buffer value of 'readonly')

To make it a little easier, you could install a custom command:

command! -nargs=1 Let exe 'let ' . <q-args> | let &l:ro = &l:ro

And then, type:

:Let g:myvar='bar'

Alternatively, you could remap <CR> in command-line mode to parse the command before its execution, check whether it matches a certain pattern (let one_of_your_vars=), and substitute the end of the command to add | let &l:ro = &l:ro.

1
  • 1
    there is also the ":redrawstatus" command. Apr 25 '16 at 13:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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