Jenkinsfile VIM syntax highlighting

VIM is actually set up to syntax highlight Groovy source files (the programming language that a Jenkinsfile is written in) by default! What it doesn’t know is that the Jenkinsfile is indeed a Groovy source file.

In VIM config land, you can associate a syntax for a file name that matches a pattern. You’d normally use it like the following if you wanted to associate the file extension .foobar with the Groovy syntax.

au BufNewFile,BufRead *.foobar setf groovy

Using this, we can associate a Jenkinsfile with the Groovy syntax highlighter.

echo 'au BufNewFile,BufRead Jenkinsfile setf groovy' >> ~/.vimrc

Restart VIM and open up a Jenkinsfile. You should see syntax highlighting, now!