Arduino Programming in Vim

How to build Arduino projects without ever leaving your favorite editor

Working Laptop by Unsplash is licensed by Creative Commons CC0

I’m ramping up on an Arduino project at Collective Idea. The Arduino IDE is a great place for beginners, and I’ve used it in the past. This time around, though, I wanted to stick with my favorite development tool, Vim. It was a bumpy start trying to write Arduino code in Vim, but I have a nice workflow now. Here’s what I learned getting there.

What Doesn’t Work

My first Google search for “vim arduino” pointed me to two Vim plugins for Arduino development: tclem/vim-arduino and jplaut/vim-arduino-ino. I didn’t have luck getting either of these plugins to compile code and upload it to my Arduino board.

I’ll keep an eye out for updates on these projects, but for now, I’m avoiding them.

What Works Well

After scouring through a few blog posts, I was able to find a few helpful tidbits.

To get syntax highlighting and code snippets, I found two plugins from Sudar: sudar/vim-arduino-syntax and sudar/vim-arduino-snippets. Both of these worked out of the box for me (I already had UltiSnips installed).

Building code and uploading it to a board is handled with Arduino-Makefile. I cloned this repository to a location in my home directory, and sourcee it from a Makefile in my project:

$ git clone ~/.arduino_mk
# Makefile
ARDMK_DIR = $(HOME)/.arduino_mk
include $(ARDMK_DIR)

From the command line, I can compile and upload a .ino file directly to the board:

$ make upload

This same command can be called in Vim with :make upload.

And finally, to quickly navigate code within my project, I’m using Ctags. To generate the Ctags, I’ve “borrowed” and modified a snippet of code from David Crosby, updating my Makefile to look like this:

ARDUINO_DIR = /Applications/
ARDMK_DIR = $(HOME)/.arduino_mk
CTAGS_PATH = $(ARDUINO_DIR)/tools-builder/ctags/5.8-arduino11/ctags

include $(ARDMK_DIR)/

.PHONY: ctags
	$(CTAGS_PATH) -f tags.cpp $(shell find . -name "*.cpp" -o -name "*.h")
	$(CTAGS_PATH) -f tags.ino --langmap=c++:.ino $(shell find . -name "*.ino")
	cat tags.cpp tags.ino > tags
	sort tags -o tags
	rm -f tags.*

In the Ctags task I use the ctags binary provided by the Arduino IDE installation. There’s no need to install it system-wide if I don’t need it elsewhere.

Now when I run :make ctags in Vim, then place my cursor over a variable or function name and press <C-]>, my cursor jumps to the definition of that variable or function.

With this configuration, I can do everything I need to do for Arduino development, without ever leaving Vim.

Photo of Chris Rittersdorf

Chis has been interested in computers and programming since owning his first NES as a child. At Collective Idea, his expertise is in web and mobile development.


Add a Comment

Hmm...that didn't work.

Something went wrong while adding your comment. If you don't mind, please try submitting it again.

Comment Added!

Your comment has been added to this post. Please refresh this page to view it.

Optional. If added, we will display a link to the website in your comment.
Optional. Never shared or displayed in your comment.
  1. August 04, 2018 at 5:07 AM

    Great guide about arduino Programming inn vim. It’s really informative content for who experts in arduino programming as well as advanced professional . Thanks for sharing useful information