Auto-indent in Notepad++

Notepad++IndentationCode Formatting

Notepad++ Problem Overview


We always write code like this formal:

void main(){
  if(){
    if()
    }

Alt text

But when I use Notepad++, the display is:

void main(){
if(){
if()
}

Alt text

How do I use Notepad++ to auto indent?

Thanks to Jonathan, I have set it, but it does not take any effect. The snapshot is below:

Alt text

I am using Notepad++ version 5.1.3.

Notepad++ Solutions


Solution 1 - Notepad++

Notepad++ will only auto-insert subsequent indents if you manually indent the first line in a block; otherwise you can re-indent your code after the fact using TextFX > TextFX Edit > Reindent C++ code.

Solution 2 - Notepad++

If the TextFX menu does not exist, you need to download & install the plugin. Plugins->Plugin Manager->Show Plugin Manager and then check the plugin TextFX Characters. Click 'install,' restart Notepad++.

In version Notepad++ v6.1.3, I resolve with: Plugin Manager->Show Plugin Manager** and then check the plugin "Indent By Fold"

Solution 3 - Notepad++

There seems to be an option for auto-format of XML at least. It can be found at TextFX -> TextFX HTML Tidy -> Tidy: reindent XML.

Solution 4 - Notepad++

Most developers of text editing programs misuse this name (auto-indent). The correct name is "maintain indentation". Auto-indent is what you actually want, but it is not implemented.

I would also like to see this feature in Notepad++.

Solution 5 - Notepad++

In the latest version (at least), you can find it through:

  • Settings (menu)
  • Preferences...
  • MISC (tab)
  • lower-left checkbox list
  • "Auto-indent" is the 2nd option in this group

[EDIT] Though, I don't think it's had the best implementation of Auto-indent. So, check to make sure you have version 5.1 -- auto-indent got an overhaul recently, so it auto-corrects your indenting.


Do also note that you're missing the block for the 2nd if:

void main(){
  if(){
    if() { }  # here
  }
}

Solution 6 - Notepad++

You can use 'Indent by fold' plugin. Install it from the plugin manager. It works fine for me.

Solution 7 - Notepad++

In the 6.6.8 version I installed the NppAutoIndent plugin from Plugins > Plugin Manager > Show Plugin Manager. Then I selected the Smart Indent option in Plugin > NppAutoIndent. Hope this helps.

Solution 8 - Notepad++

For those who use Notepad++ v6.8.1 and later, the auto-indent setting now is placed in menu SettingsPreferencesMISC.Auto Indent.

Enter image description here

Solution 9 - Notepad++

For those who using version 7.8.5, the Auto-indent settings is now located at "Settings" -> "Preferences..." -> "Auto-Completion".

enter image description here

Solution 10 - Notepad++

A little update: You can skip the TextFX Plugin and just use Tidy2. Here you can configure your own formating-rules for different types of codes. Easy to install and remove within

Notepad++ > Plugins > Plugin Manager > Show Plugin Manager

and just search for Tidy2 and install it. Done.

Solution 11 - Notepad++

You can add "Text FX Character" plugin. Download it from https://sourceforge.net/projects/npp-plugins/files/TextFX/ and install it via

Plugins → Plugin Manager → Show Plugin Manager.

Then you will find a new "TextFX" menu:

Menu TextFX → TextFX Edit → Reindent C++ code

enter image description here

To add shortcut for Indentation.

Click on SettingsShortcut Mapper... set the shortcut key you prefer. I prefer Ctrl + =.

Enter image description here

Solution 12 - Notepad++

Try the UniversalIndentGUI plugin for Notepad++. It re-indents code based on some parameters. It worked well for me.

Solution 13 - Notepad++

This may seem silly, but in the original question, Turion was editing a plain text file. Make sure you choose the correct language from the Language menu

Solution 14 - Notepad++

Install Tidy2 plugin. I have Notepad++ v6.2.2, and Tidy2 works fine so far.

Solution 15 - Notepad++

First download plugin manager this link then unzip the zip folder and copy this inside your program/ notepad++ folder . then restart your notepad++. then you see plugin manager inside plugin menu . then click plugin manager then click show plugin manager . It shows all your plugin list . from the list in bottom find XML tools , checked it and install it. then restart your notepad++. After open a document then plugins/xml tools/pretty plain(indent text) then enjoy.

Solution 16 - Notepad++

Try to save the file before, then it will indent.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTurionView Question on Stackoverflow
Solution 1 - Notepad++scronideView Answer on Stackoverflow
Solution 2 - Notepad++Moose5View Answer on Stackoverflow
Solution 3 - Notepad++AbhishekView Answer on Stackoverflow
Solution 4 - Notepad++JoeyView Answer on Stackoverflow
Solution 5 - Notepad++Jonathan LonowskiView Answer on Stackoverflow
Solution 6 - Notepad++Aki143SView Answer on Stackoverflow
Solution 7 - Notepad++TheRSView Answer on Stackoverflow
Solution 8 - Notepad++LukeView Answer on Stackoverflow
Solution 9 - Notepad++ooi18View Answer on Stackoverflow
Solution 10 - Notepad++Sven YaView Answer on Stackoverflow
Solution 11 - Notepad++Saurav SahuView Answer on Stackoverflow
Solution 12 - Notepad++imrissView Answer on Stackoverflow
Solution 13 - Notepad++kurdtpageView Answer on Stackoverflow
Solution 14 - Notepad++user9717890View Answer on Stackoverflow
Solution 15 - Notepad++tapos ghoshView Answer on Stackoverflow
Solution 16 - Notepad++Sh13View Answer on Stackoverflow