Arduino code highlighting in Vim

A big thankyou to Johannes Hoff for putting together a Vim syntax highlighting file for Arduino development. Most people start their Arduino journey using the IDE but many then move on to using other tools, and for me personally my editor of choice has been Vim for so long I can’t remember when I started with it. The Arduino language is really just C++ with some extra libraries thrown on top but because sketch files are stored with a .pde extension Vim doesn’t even apply regular C++ highlighting by default, let alone highlight Arduino-specific functions. So Johannes put together an “arduino.vim” syntax file that you can grab from www.vim.org/scripts/script.php?script_id=2654.

To get it running on my Ubuntu system these are the steps I followed:

  1. Create the directory to store syntax files if it doesn’t already exist: mkdir -p ~/.vim/syntax
  2. Put the file you just downloaded into it: mv arduino.vim ~/.vim/syntax/
  3. Bind that syntax definition to files with the .pde extension by adding the following line to your ~/.vimrc file: au BufNewFile,BufRead *.pde setf arduino
  4. Open a .pde file in Vim and type: :syntax on

Voila! Syntax highlighty goodness for .pde files:

arduino-vim-highlighting

If you want Vim to always have syntax highlighting automatically each time you open a file, just add this to your ~/.vimrc file:

syntax on

Enjoy!

Leave a Reply