19

I have this oneliner in my vimrc but it does not work :

if has("patch-7.4.710") | set listchars+=space:· else | set listchars+=trail:· | endif

VIM says :

E518: Unknown option: else

Can you help me ?

1 Answer 1

30

You need to put another | before else otherwise vim will think your command is set listchars+=space:· else instead of two separate commands. That's why you got the error message: else is an unknown option for the command set.

The correct syntax is the following:

if has("patch-7.4.710") | set listchars+=space:· | else | set listchars+=trail:· | endif
7
  • I was struggling to where would I place the |, before or after the else ? Now, I now it's both :-D. Thanks a lot :) !
    – SebMa
    Sep 11, 2017 at 9:52
  • 2
    @SebMa: Think of how vim would parse your code if it was written on several lines: instruction 1 if has("patch-7.4.710"), instruction 2 set listchars+=space:·, instruction 3 else, instruction 4 set listchars+=trail:· and last instruction endif. As the | are used to separate instructions it is only logical to put one before else and one after :)
    – statox
    Sep 11, 2017 at 9:58
  • 1
    It's logical as long as one knows the language. In C, we use ; to separate instructions . In C else is not an instruction, otherwise there would be a ; after it :)
    – SebMa
    Sep 11, 2017 at 10:02
  • 1
    The semantics of VimScript are a lot closer to shell scripting than C @SebMa. Sep 11, 2017 at 10:31
  • 1
    @SebMa No, but the semantics of "(almost) everything including control structures are a command" is similar to VimScript (and different from C). Sep 11, 2017 at 12:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.