Unless I missed it there is no option to print the code in the IDE
Whilst it might seem archaic to want to print code, it comes into its own for examination of the code away from a PC, and can also be useful in providing documentation of a project. This is particularly the case where it is "printed" to a PDF file
Is it planned to add a print option to the IDE editor ?
I think it is planned, but I checked and there's no issue in the tracker for it. You're welcome to submit one. That will signal to the team that the users are missing this feature and make it easier to track.
As Microsoft has not seen the need to add native printing support to VS Code, a free open source 3rd party extension named PrintCode was created to add the capability. This extension can be installed in Arduino IDE 2.x to do the same.
Install the extension
If you have used VS Code, you will be used to installing extensions via the manager in the application. Arduino IDE 2.x does not have that capability, so the extension installation process is different.
ⓘ Despite the .vsix file extension, the downloaded file is really a ZIP archive. Depending on which unzipping utility you use, it may help to rename the file to use a .zip extension. For example, on Windows that will allow you to right click the file and select "Extract All..." from the context menu.
Create a folder named plugins under Arduino IDE's configuration folder:
Windows:
C:\Users\<username>\.arduinoIDE\
Linux:
~/.arduinoIDE/
The .arduinoIDE folder is hidden by default in the file manager and terminal.
macOS:
~/.arduinoIDE/
The .arduinoIDE folder is hidden by default. You can make it visible by pressing the Command+Shift+. keyboard shortcut.
ⓘ If you are using Arduino IDE 2.0.4 or older, name the folder extensions instead of plugins, and substitute that folder name in the rest of the instructions.
Copy the unzipped extension folder to the plugins folder you created.
(e.g., C:\Users\<username>\.arduinoIDE\plugins\nobuhito.printcode-3.0.0).
If Arduino IDE is running, select File > Quit from the Arduino IDE menus to exit all windows.
Printing sketches
Because the printing support is provided by an extension, it works a bit differently than usual:
Open the sketch you want to print in Arduino IDE.
Select the sketch tab you want to print.
Press the Ctrl+Shift+P keyboard shortcut (Command+Shift+P for macOS users) to open the "Command Palette".
Select the "PrintCode" command from the menu.
The sketch file will now be rendered as a webpage in your browser and a print dialog will open.
Configure the print job to your preferences and click the "Print" button when you are ready.
Configuring the extension
In case the default behavior of the extension is not to your liking, it offers several configuration settings:
Press the Ctrl+Shift+P keyboard shortcut (Command+Shift+P for macOS users) to open the "Command Palette".
Select the "Preferences: Open Settings (UI)" command from the menu.
A "Preferences" tab will open in the Arduino IDE main panel.
Type printcode in the "Search Settings" field of the "Preferences" tab.
The settings for the PrintCode extension will be shown in the search results.
Adjust the PrintCode configuration according to your preferences.
@in0 thanks for that. I tried it and it actually works quite well.
Needed to change the scale down a bit to get a better font size on the printer.
Would be even better if a shortcut could be assigned to it. I did not find it listed in "Keyboard Shortcuts" - probably extensions are not picked up and listed. Is it possible to assign a shortcut key to it?
There's an option under the Sketch menu to Show Sketch Folder which will open your native OS file browser and have the sketch selected so all you need to do is right-click on the selected sketch and open in any text editor for printing.
It's only a few steps and it gets you to all of the features your OS has for doing things with text files. I suppose you could drag and drop the sketch file onto your printer as another way to print.
ON MAC, using simply "open with" and choosing "TextEdit" or better "WORD" , you can print directly the sketch
So you can choosing font, character height, colours and others
It's very easy to do
The PrintCode extension I mentioned in my previous post is no longer actively maintained. From my limited use of the extension, it seems to work perfectly well so this is not necessarily an immediate problem and if you are already using the extension and happy with it then you are free to continue to do so. However, for any new installations, or for those who prefer to use actively maintained software I can suggest an alternative extension:
You might also find this extension a bit more convenient to use since it allows you to print by clicking an icon in the primary Arduino IDE user interface rather than having to use the "command palette" as is required when using the PrintCode extension.
Install the extension
If you have used VS Code, you will be used to installing extensions via the manager in the application. Arduino IDE 2.x does not have that capability, so the extension installation process is different.
If Arduino IDE is running, select File > Quit from the Arduino IDE menus.
All Arduino IDE windows will close.
Click the following link to open the extension's Visual Studio Marketplace page in your web browser: Print - Visual Studio Marketplace
Click the "Download Extension" link on the right side of the page.
A file download will start.
Wait for the download to finish.
Create a folder named plugins under the Arduino IDE's configuration folder:
Windows:
C:\Users\<username>\.arduinoIDE\
(where <username> is your Windows username)
Linux:
/home/<username>/.arduinoIDE/
(where <username> is your Linux username) The .arduinoIDE folder may be hidden by default in your file manager and terminal.
macOS:
/Users/<username>/.arduinoIDE/
(where <username> is your macOS username) The .arduinoIDE folder is hidden by default. You can make it visible by pressing the Command+Shift+. keyboard shortcut.
Copy the downloaded file to the plugins folder you created.
(e.g., C:\Users\<username>\.arduinoIDE\plugins\pdconsec.vscode-print-0.11.19.vsix).
Printing sketches
Open the sketch you want to print in Arduino IDE.
Select the sketch tab you want to print.
Click the icon that looks like a printer ("Print") at the right side of the sketch editor toolbar
The sketch file will now be rendered as a webpage in your browser and a print dialog will open.
Configure the print job to your preferences and click the "Print" button when you are ready.
Configuring the extension
In case the default behavior of the extension is not to your liking, the extension offers several configuration settings:
Press the Ctrl+Shift+P keyboard shortcut (Command+Shift+P for macOS users) to open the "Command Palette".
Select the "Preferences: Open Settings (UI)" command from the menu.
A "Preferences" tab will open in the Arduino IDE main panel.
Select Extensions > Print from the navigation panel on the left side of the panel.
The settings for the Print extension will be shown.
Adjust the settings of the Print extension according to your preferences.
I used the PrintCode extension based on your earlier recommendation, on the odd occasion I needed to print something, but always had a gripe with having to go to the Command Palette.