I have a plugin that has some functionality that adds some string to the statusline
. I have a series of functional tests that verify that certain actions produce some output, and would like to verify that, if set, the statusline
will change after some trigger.
I haven't been able to find something that will allow me to capture (dump?) the rendered contents of the statusline
. Both the :help statusline
and :help status-line
didn't hint to anything that might allow this.
Is there a way to actually do this?
You're looking for :help screenchar()
. With it, you can capture any visible screen cell controlled by Vim (including status lines), and it's main purpose is testing. Its use is a bit clumsy, because you have to query each position individually, and have to explicitly convert back to characters / strings. For example, if the statusline is the second-to-last line, this will get it's first character:
:echo nr2char(screenchar(&lines-1, 1))
And this will obtain the entire statusline (assuming you don't have any vertical window splits):
:echo join(map(range(1, &columns), 'nr2char(screenchar(&lines-1, v:val))'), '')