O'Reilly logo

Hacking Vim 7.2 by Kim Schulz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required