Configure vim for CFEngine highlighting

If you edit or read CFEngine files with vim, you may have noticed that the syntax highlighting is at best weird. Just for you, Neil Watson made a vim syntax highlighter.

Vim editor

The latest version can be found on github.

Syntax highlighting in vim has two components: type detection and highlighting. Since detection is not needed and often doesn’t work, let’s just use highlighting.

First download and put it in ~/.vim/syntax/

Then add these lines in your ~/.vimrc file:
syntax enable
au BufRead,BufNewFile *.cf set ft=cf3
” disable folding which can be confusing
set nofoldenable

Add this line if you have other file extension with CFEngine syntax (for example *.st is used within Rudder for string template preprocessing):
au BufRead,BufNewFile *.st set ft=cf3

Finally do not forget to use vim and not vi (by using alias ou alternatives).

Here is a screenshot of syntax highlighting before and after:

screenshot bpe

screenshot bpe 2

For a more complete description and usage of the plugin.

Bonus: did you know that vim has two types of highlighting depending on your terminal colors? It can try to detect the color type, but it’s often wrong. So you can change it easily using one of those commands:
:set bg=dark
or
:set bg=light

You can also put this in your .vimrc file to do it permanently.

Other tools

As you may not know, vim is not the only text editor or viewer.
Some of you may even use emacs, be reassured, emacs too has its own syntax highlighter for CFEngine.

And you, what editor do you use?
Do you have a syntax highlighter for CFEngine?
Is it possible to add one?

Share this post

Scroll to Top
Rudder robot named Ruddy makes an announcement.

Release 8.2: simplify IT security compliance with Policy and benchmark solution

Security management module details

This module targets maximum security and compliance for managing your infrastructure, with enterprise-class features such as:
Learn more about this module on the Security management page

Configuration & patch management module details

This module targets maximum performance and reliability for managing your infrastructure and patches, with enterprise-class features such as:

Learn more about this module on the Configuration & patch management page