Using an External Text Editor in Arduino IDE

Whenever I program an Arduino based project I would always use Sublime Text as my editor then compile and upload using the Arduino IDE. I prefer using Sublime Text as my Arduino Sketch editor as it gives more flexibility on color highlighting.

This post is a tutorial on how to use Sublime Text as an External Editor. It also answers the why, advantages and disadvantages of using External Editor.

In case you prefer to use Atom Text Editor  or Visual Studio Code than Sublime Text then you may still do so by opening your code on Atom Text Editor.

(Left) Sublime Text; (Right) Arduino IDE
Both editors are showing the same stripped down version of the Blink code.


Using an External Editor without setting the Arduino IDE properly

Before I show you on how to properly set the Arduino IDE to use an External Editor, let me show you first on what happens when you use an External Editor without doing the proper setup.

I opened the same .ino file on the Arduino IDE and on Sublime Text. Then I edited the one on Sublime Text.

Note: The code is a stripped down version of the Blink Code.

Then I edited the code on Sublime Text and saved it.

Added 4 lines of code on Sublime Text.

Then without editing or saving the code on the Arduino IDE I compiled the code.

The normal Blink code sketch would only use 928 bytes (2%) of program storage space. Therefore, the one compiled on the above experiment was the modified Blink code with 4 lines of additional code.

That is cool and all since you can modify your code on an External Editor and compile it on the Arduino IDE. But what if you forgot that you were using an External Editor and edited the code on the Arduino IDE instead? This actually happened to me and with a snap of a finger I said goodbye to 3 days worth of coding.

To avoid this we must set properly the Arduino IDE to use an External Editor. See the steps below.


How to use an External Editor in Arduino IDE

On your Arduino IDE go to File >> Preferences.

Inside the Preferences window find and check the Use external editor check box. Then press OK.

Once you have done the above instructions the Arduino IDE editor would then be colored grey. You can try editing the code on your Arduino IDE but the program would not allow you to do any changes.

I did the same experiment as the above.

I edited the code on Sublime Text and saved it.

When I clicked on anywhere in the Arduino IDE the code was updated to the new saved version.

With that I can make sure that what I compile on my Arduino IDE is the latest version of my Project Code without worrying that I would overwrite it whenever I forget that I am using a different editor.


Do you use an External Editor for your Arduino projects? What editor do you usually use? Tell me your answers on the comments below.

16 thoughts on “Using an External Text Editor in Arduino IDE”

  1. Very useful explanation.
    As in many areas, the tools and options are all defined, but it’s hard to find a clear explanation (for a learner) of how to put them together.
    (The same applies to many libraries)
    I am using Notepad++ to edit sketches.
    Regards
    Peter A

  2. Does anyone know of a way for the Arduino IDE to open the external editor on the file of choice with just a button press or pop-up menu?

  3. This works well for editing main programs and header files that are already in the Arduino library when you start the Arduino IDE. *However* if you add a new program or header file, you will have to exit and relaunch the Arduino IDE (for some bizarre reason, the Arduino IDE seems to read and store the directory tree)

  4. I too agree that it would be a big advantage if the external editor completely replaced the Arduino one with its black on gray. Not only would that make reading the text much easier especially for old people who are half blind such as myself but also one would not have to switch back to the Arduino in order to compile and upload.

    1. Hi Larry, I agree that reading code in Sublime Text is so much easier compared to doing it in the Arduino IDE.

      By the way, the DevIOT that ShiroiAkuma recommended I think would help. I have not tested yet. Will test it in the next few days.

  5. Nice post – thanks. I use Atom and arduino 1.8.8. I did not loose any code but then I closed the file in Atom first. Thanks so much as one day I will forget.

  6. You can change the theme for Arduino. I have white lettering on black background for my old eyes. Look for “Arduino IDE themes” in Google. I also increased font size.

  7. I use emacs, among many other things the automatic code indentation via TAB is perfectly solved there

    Is there also with the new IDE 2.0 a possibility to fall back on an external editor, in the settings I could find nothing about it.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.