Indentation is very important for readability and manageability of code, especially, if the size of code base fairly big. Badly indented code is very difficult to understand or maintain. Good developers always maintain proper indentation but many times we get codes from internet or other sources which are not properly indented, many times they are not indented at all. Here we’ll see how to re-indent code which are not properly indented using Notepad++. Core Notepad++ does not have the feature to do this but indentation can be done easily using a plugin called TextFX Characters.
Install TextFX Characters Plugin
If TextFX Characters plugin is not installed, then following these steps to install that. If the plugin is already installed, skip these steps.
- Open the Plugin Manager by selecting “Plugins->Plugin Manager->Show Plugin Manager” menu.
- Select the “Available” Tab of the “Plugin Manager” window. You’ll see the available plugins that are not yet installed. They are alphabetically sorted. Select the “TextFX Characters” plugin and then press “Install” button. Follow the instruction to successfully install the plugin.
- Once the plugin is successfully installed the “TextFX” menu will appear on the menu bar. Please remember that you need to restart (close and reopen) the Notepad++ editor to make the plugin function.
Indent Your Code
In this example, we have unindented code like this.
We’ll see how this code will be properly indented using the “TextFX Characters” plugin.
To indent this sample code, select the “TextFX->TextFX Edit->Reindent C++ code” menu. Your code is already indented. The indented code will look like.
Hi: The latest NotePad++ (version 8-5-4) textFX plugin does not have a “TextFX Edit” dropdown selection for “Reindent C++ Code”. Where has the reindent function been moved? Thanks.
Apparently TextFX plugin is no longer available for latest version of Notepad++. Thanks for notifying this. I’ll try to figure out if any other plugin can serve this purpose.
Doesn’t indent correctly with code like this:
if (something)
for(blah)
count++;
Will become:
if (something)
for(blah)
count++;
The best explanation i could find
This is exactly what I was looking for. Anyway thanks.