I am building my statusline. Previously I used functions to return information, but recently I learnt that these can be done in one line. For example:

set statusline+=%{&modified?'\ \ [+]':''}

I need to find if file is readonly or non-modifiable, like the example above. Right now I have:

set statusline+=%{&readonly?'\ ':''}\ 

But I need something like this:

set statusline+=%{(&readonly || !&modifiable)?'\ ':''}\ 

But I get an error: unclosed expression sequence. What's the situation here?


The full error gives you a hint as to the problem:

E540: Unclosed expression sequence: statusline=%{(&readonly

You cannot include unescaped space characters in :set commands, because Vim interprets them as the end of the setting. (See :h option-backslash.)

The quickest solution is to escape your space characters (or just remove them! (&readonly||!&modifiable) will evaluate fine), but I prefer to use :let:

let &statusline .= '%{(&readonly || !&modifiable) ? " " : ""} '

(See :h :let-option)

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.