Cover by Kim Schulz

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

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

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required