Arduino and Vim, NO IDE Required!

Look Ma, No IDE! :laughing:

Quick tutorial on how to merge Arduino CLI tools and the Vim editor in Linux.

This process has taken me a little while to get figured out, so I figured I would post this here for others so they can save themselves the time to get this up and running.

So first of all, it goes without saying that if you are wanting to use Vim as part of your workflow and not the IDE then I would consider you at a minimum a intermediate skill level user of Linux. This means I will not be getting into the 'why would you want to do that?', just simply how to do it.

So you do not need to install the IDE at all, there is nothing you gain from installing it, other then to be able to use it. For me, maybe...someday...moving on..

Everyone will have a different version of Linux and they do vary slightly so you will need to be familiar with your directories, $PATH variables, chown, chmod, etc...again, its implied that if your running vim as your primary editor then you should know these basics.

//my setup
Debian 4.19.181-1 (2021-03-19) x86_64 GNU/Linux

You will need the following downloads:
GitHub - arduino/arduino-cli: Arduino command line tool //this is your main arduino program
GitHub - sudar/vim-arduino-syntax: Arduino syntax files for Vim //this provide arduino syntax highlighting in vim
GitHub - arduino/arduino-examples: Arduino IDE bundled examples //sketch examples provided in IDE (optional)
https://www.putty.org/ //Serial monitor program (optional)

So I started out by creating a Arduino directory in my home directory to keep everything in one central place.

robert@mountain-cabin:~/Arduino$ l
arduino-cli*         arduino-examples/  LICENSE.txt   tools/
ArduinoCreateAgent/  libraries/         Sketch_Book/

In my Sketch_Book directory I have all my sketch folders so they are in 1 location. In my tools directory I have my home made scripts I use to compile, upload, open serial monitor, etc...Libraries is self explanatory. The arduino-examples is the git hub folder with all the original example sketches. Finally the ArduinoCreate Agent is for if I need to access the cloud based version for whatever reason.

I would suggest you spend some time on the Arduino CLI github page and get familiar with all the commands and go through them. You going to need to get your board core installed, any libraries you need, etc. Once you have verified you can communicate with the board and get more comfortable with working with the command line utilities your ready to move on.

I found the following link helpful to print out and keep at my desk so I have a handy reference to all the commands without having to jump over to github every time.

At this point you are going to want to work on getting syntax highlighting. I found the file from sudar to be the easiest to work with, just copy the files into the appropriate syntax, indent, ftdetect folders and that is it. There are some other ones out there, this is what worked for me.

The following link was golden for me, not only did it give me the serial monitor setup the user also provides a script for compiling, uploading and opening a serial monitor. I took this basic script and broke it down into several tools.

Scripts I created:
ard-cpm_upl_ser // compiles, uploads and opens serial monitor
ard-cmp_upl // compiles and uploads sketch
ard-compile // compile sketch only
ard-upload // upload sketch only
ard-serial // open a serial monitor

In these scripts I have a partial path to my .ino's.
~/Arduino/Sketch_Book then I have to fill in the rest....

Example from within Vim,
:!ard-cpm_upl_ser /temperature_warning

The command will automatically append that to the existing directory and find the .ino file, it will exit vim briefly and do what it needs to do and then tell you to enter to return to Vim.

Here are a couple example pics so you can see it all in action....
Here I am using the example .ino to produce the ascii table to the serial monitor..


Hope that is useful,

Cheers! :beers:
Robert

1 Like

You have explained what is possible, but can you please explain why you would do this instead of using an IDE ?

Its cool and all, but what advantage does this give as opposed to an IDE and why you use this instead of the default Arduino IDE?

Arduino default IDE is already a pain in the back but this looks even more of a pain. If the aim is to be able to upload blink.ino using alternative means, then this gets 5 stars from me!

I was kinda hoping not to have to explain the 'Why' behind using Vim for the simple reason that if you have to ask then its quite possibly not for you.

Vim does have a fairly steep learning curve so if your not currently using it, then it is probably not for you. However, if you want to use one of the quite arguably fastest and most powerful editors available used by top software developers all over the world then I would encourage you to do a little research. It is also installed by default on every Linux, Unix, and Mac OS.

I will help and put up some links and another couple pics.

To Have the Ultimate Powerzzz of the Universe, mahhahahahaha!
No but really it is virtually unlimited in its versatility, configuration and power.

See now there's the spirit! :laughing: I will take those 5 Stars, Thank YOU!

Lets see here...So in your Arduino IDE can you split the screen into 4 panes and view your current temperature warning project code alongside a switch case example code you want to work into your project code, AND work on your recursive vs iterative Fibonacci code for your C programming class AND work on your micropython code for reading the onboard temp sensor on your Pi Pico...All at the SAME TIME?? Say What?!!! :joy:

Why use Vim they ask, hahahaha!

So how many programming language syntax does Vim support out of the box you ask?
bah, just a few random languages no one would every have a use for :wink:
I was going to post them here but no reason to show the dozens and dozens of different ones, but suffice it to say that if you can think of it, its there. ascii, ada, arduino (I added), awk, B, Basic, C, C++, C#, Cobal, CSS, Docker, Django, Fortran, FoxPro, Go, Haskel, Html, Ocaml, Perl, Python, Ruby, Rust, Sed, Sql, Tex, VB, and let us not forget Yacc and Yaml....To name just a few of them....

But wait there is more, you want choice right, I know the Arduino color scheme can get kinda old so we might want to switch things up just a little bit...Hmmm Shall We??
There are 18 color schemes by default and you can create your own and download more.


So if your truly interested there is a TON of information out there for Vim.
I recommend a fun 6 part tutorial series 'Vim as your editor 1/6' from the Primeagen on YouTube.
He happens to be a senior software engineer at Netflix, not that it means anything other then its just an example of a professional programmer sharing skills for his favorite editor.

Here is a fun one I like just to get you used to his style.

Fun fact, Microsoft had actually licensed Unix from AT&T in the late 70's. Thankfully they sold their interest in Unix shortly thereafter. So it was a possibility that Vi(Vim) could very well have been the default editor for all MS products, instead MS decided to give its users the DOS editor that eventually became notepad.