Syntax regions

In our previous example, we selected the comment line using the match option for the syntax command. In some cases, however, it is hard to create a suitable match and other simpler approaches are needed.

In Vim, you can select entire regions of the code and color them, simply by setting what a region starts with and what it ends with. To build on our previous example, let's make a region-syntax command to substitute our old match command:

:syntax region myComments start=/\/\*/ end=/\*\//

With this command, I can easily match any of the following comment blocks:

/* single line comment */
 *  multi line comments
/* multi line comment

But the region option ...

Get Hacking Vim 7.2 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.