Wed, 26 Nov 2008

Vim Syntax Highlighting for Puppet

I've just set up syntax highlighting for Puppet manifest files, and thought I'd share the simple steps. The first thing to do is download the syntax file from http://www.reductivelabs.com/downloads/puppet/puppet.vim and save this to ~/.vim/syntax/puppet.vim. Now when the filetype is set to "puppet", vim will use this syntax file.

That's useful, it it would be even nicer if we could make vim know that files ending in .pp were puppet files. Turns out this is very easy to do. You need to create a file to detect the correct filetype when you open a file. You need to put the following lines in ~/.vim/ftdetect/puppet.vim:

au BufRead,BufNewFile *.pp   setfiletype puppet

Now when you load a file ending in .pp, you should get nice syntax highlighting. You can also make vim use special settings for the puppet filetype by creating a vim script file in one of ~/.vim/ftplugin/puppet.vim, ~/.vim/ftplugin/puppet_*.vim and/or ~/.vim/ftplugin/puppet/*.vim. Vim has a lot of flexible hooks to enable file type specific configuration; hopefully it should be fairly easy to modify these examples for other file formats.

[] | # Read Comments (3) |

Comments

I'm using vim 7.1 on Debian Lenny.

In order to get this to work I first had to apt-get install vim.
According to http://ubuntuforums.org/showthread.php?t=845919 Lenny starts with vim tiny which does not have syntax highlighting.

I then put "au BufNewFile,BufRead *.pp setf puppet" in ~/.vim/filetype.vim
Posted by Josh Kline at Wed May 13 06:13:29 2009
Thanks, this helped a lot.
Posted by Jeff at Sat Feb 6 23:48:20 2010
Thanks, this was very helpful!
Posted by Dan at Thu Feb 25 22:47:38 2010

Name:


E-mail:


URL:


Comment:


Please enter "fudge" to prove you are a human