set laststatus=2
set statusline=
var separator = '    '
set statusline+=%{expand('%:p')}
set statusline+=%{separator}
set statusline+=%l:%v

Error: Undefined variable: separator

Why is that?

1 Answer 1


In Vim9 script :var is used to define a local variable that is not visible outside. Specify global scope g: directly or remove vim9script command as it is not doing much here anyway.

Also to note that creating "long separator" by hardcoding some arbitrary number of spaces is usually a horrible idea. Prefer %= and %< whenever it makes sense.

  • I suspect I need %< in my case. Could you show how to use it?
    – john c. j.
    Jul 30, 2022 at 14:32
  • 2
    @johnc.j. Put percent-less before field to be truncated. By default this is the first one, i.e. too long file name. See how default status line works, for example.
    – Matt
    Jul 30, 2022 at 14:59

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.