Code Format in Notepad++ with AStyle

If you are familiar with programming IDE such as MS Visual Studio, NetBean, Eclipse, etc., you might found that they come with their own formatting facility, but if you are using a multi-purpose editor such asNotepad++, then you may have to use a plugin to format your code. This tutorial will help you do code format with AStyle in Notepad++.

First you need to make sure you have NppExec plugin added to your Notepad++ by going to Plugin menu.


Download AStyle. The zip archive includes all the source and an  executable. You can simple copy the executable to a suitable location (For this demo, I am copying it to C:\Programming\AStyle\bin\AStyle.exe. Or you can recompile from the source.

Go to NppExec under Plugin menu and click on Execute or hit F6. You will get the Execute dialogue box.


Execute Dialogue Box

Select ” from the dropdown box if it is not already selected.

Type in the following commands in the window:

C:\Programming\AStyle\bin\AStyle --style=allman "$(FULL_CURRENT_PATH)"

The first line, formats the code and saves the file. The view doesn’t get refreshed, so we need to reload the file from disk, and npp_open does that in the above. Note that I am using AStyle with –style=allman flag which uses broken brackets.

Hit the save button and it will ask you for a name, just type an appropriate name and hit OK to run.

Execute AStyle

You could stop right there and every time you need to run the command, just go to Plugins -> NppExec -> Execute… But let’s go one step further.

Under Plugins, go to NppExec and click on Advanced Options.


NppExec Advanced Options

Select “Run AStyle” from the Associated Script drop down menu and then hit the “Add/Modify” button. Make sure the “Place to the Macros Submenu” is ticked.

This will add a new option in Macro Menu.


Notepad++ Macro Menu

That’s all. Having fun with your coding life ;-)

Leave a Reply