Is it possible to print a conditional string on the statusline? e.g. GREEK
if iminsert=1 and LATIN
otherwise?
1 Answer
From :help 'statusline'
:
The result can contain %{} items that will be evaluated too.
So if you write an expression inside %{}
and add it to your 'statusline'
option, it should be evaluated and the result displayed. Here, your expression would be:
&iminsert==1?'GREEK':'LATIN'
The syntax of this expression is described in :help expr1
; if the test before the question mark succeeds (here &iminsert == 1
), the evaluation of the expression is the value just after the question mark, otherwise if it fails, it's the value after the colon.
To add this expression to your 'statusline'
value, you could write in your vimrc
:
set statusline+=%{&iminsert==1?'GREEK':'LATIN'}
-
1Note that the contents of
statusline
will be evaluated on every screen update. That's a lot. This simple expression is not a problem, but more complicated ones might be (like, say, getting thegit
branch name, the date, or some other relatively expansive operation). Commented Mar 13, 2016 at 21:10