Is it possible to print a conditional string on the statusline? e.g. GREEK if iminsert=1 and LATIN otherwise?

1 Answer 1


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:


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'}
  • 1
    Note 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 the git branch name, the date, or some other relatively expansive operation). Mar 13, 2016 at 21:10

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.