1

This question already has an answer here:

I often get really long lines, such as:

syntax region SomeName start=/some_pattern/ end=/some other pattern/ contained contains=SomeOtherName,YetAnotherName,EvenMoreNames,More,MoreAgain,KeepsGoing,Etc,UntilLineWrapsAroundAndItLooksReallyUgly

I tried to add \ to break the long lines, as follows:

syntax region SomeName start=/some_pattern/ \
                       end=/some other pattern/ contained\
                       contains=SomeOtherName,YetAnotherName,\
                       EvenMoreNames,More,MoreAgain,\
                       KeepsGoing,Etc,\
                       UntilLineWrapsAroundAndItLooksReallyUgly

But it didn't work.

Thoughts?

(note: I'm open to neovim-specific solutions)

marked as duplicate by statox Jul 30 at 13:17

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 3
    To me this is a duplicate of this question – statox Jul 30 at 11:25
  • It is indeed a duplicate :(. Apologies. – caveman Jul 30 at 13:11
2

Line continuation in Ex commands is done by prepending a backslash to the beginning of the continuation lines themselves, not appending it to the end of the preceding lines.

See :help line-continuation:

Long lines in a :sourced Ex command script file can be split by inserting a line continuation symbol \ (backslash) at the start of the next line. There can be white space before the backslash, which is ignored.

And there's even an example for a :syntax command:

:syn match Comment
    \ "very long regexp"
    \ keepend

This may look very odd, so the help page even explains why it needs to be that way:

Rationale:

Most programs work with a trailing backslash to indicate line continuation. Using this in Vim would cause incompatibility with Vi.

For example for this Vi mapping:

  :map xx  asdf\

Therefore the unusual leading backslash is used.

Applying that to your particular case:

syntax region SomeName
        \ start=/some_pattern/
        \ end=/some other pattern/
        \ contained
        \ contains=SomeOtherName,YetAnotherName,
        \EvenMoreNames,More,MoreAgain,
        \KeepsGoing,Etc,
        \UntilLineWrapsAroundAndItLooksNotThatBad

The help page also has detailed explanations on how to handle whitespace, which is applicable to the last lines in your example:

All leading whitespace characters in the line before a backslash are ignored. Note however that trailing whitespace in the line before it cannot be inserted freely; it depends on the position where a command is split up whether additional whitespace is allowed or not.

In short, you might need to be careful if using it where whitespace is to be prevented, but it's certainly doable even in those cases.

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