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:
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?