Using Vim for Arduino development

Here’s a quick post on setting up Vim for Arduino development instead of using the Arduino IDE. If you’re a heavy Vim user, it can be a bit of a shock to go into a different editor. Thankfully the setup is pretty easy to get this all working with Vim. This post is assuming you are comfortable with how Vim is setup and ideally already have an environment that works for you.

Update March 26, 2014

The Arduino Vim plugin originally referenced in this post seems to have been abandoned by the project creator. The README has been updated pointing to a newer Vim Arduino plugin using Ino, command line toolkit for working with Arduino hardware. I haven’t had a chance to test this new solution out fully, but it looks promising. If you have any issue with my guide below using the old plugin, tryout the new plugin and Ino and let me know how it goes!

Once I have a chance to fully test and understand the new build method, I’ll update this post with the new information. On first look, it looks like a project folder structure is imposed by Ino, lib and src folders, but I don’t think that’s too much of an issue in the long run. Overall, I think relying on a command line build process will probably be more stable than trying to tie into the Arduino IDE like before.

Install the Arduino IDE

Wait. What?!? I hear you say. I know, I know. We’re not actually using the Arduino IDE but we need it for some configuration and the files it installs. The Vim plugin we’ll be using ties into what the IDE installs and configures so it’s needed. You can download the IDE from the Arduino site.

Install vim-arduino plugin

To get the main goodness of compiling, monitoring and deploying to an Arduino, grab the latest version of vim-arduino. Install it in your .vim folder using what ever method you use to manage your Vim plugins. Hint: I’d recommend Pathogen as it makes installing as simple as dropping the plugin folder into a bundle folder.

Vim syntax file

Next up is to get the syntax file so we can have nice colour coding for .pde and .ino files. Download the latest arduino.vim and install it in your Vim syntax folder. To get the syntax to apply to the correct file types add the following to your vimrc file

au BufRead,BufNewFile *.pde set filetype=arduino
au BufRead,BufNewFile *.ino set filetype=arduino

Configuring the Arduino IDE

Before trying to compile and deploy with Vim, get it all working with the Arduino IDE first as the Vim plugin just calls from the settings saved by the IDE. If it’s working in the IDE, it should work in Vim. Make sure you select the right tty.usbmodem* serial port from Tools > Serial Port in the IDE. Note: This will only show when the Arduino is plugged in.

Working from Vim

Once you can communicate with your Arduino from the IDE you should be fully good to go with Vim. You shouldn’t have to open the IDE unless you want some example code. Open up your sketch file in Vim and use <Leader>ac to compile a sketch, <Leader>ad to compile and then deploy to the connected Arduino and <Leader>as to open a new window with screen to monitor the serial output from the Arduino.

And that’s it! Overall I’m really happy with the setup so far. Let me know if it works for you or if there are any issues.