Auto-indent in Notepad++
Asked Answered
T

17

198

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.

Thomson answered 5/1, 2009 at 6:36 Comment(0)
C
142

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.

Coo answered 5/1, 2009 at 7:26 Comment(7)
If your version is missing the DLL you can get it from the ZIP 5.9.0 version. Some of the later versions did not include this DLL. notepad-plus-plus.org/download/v5.9.0.htmlFiann
I actually found this while looking for a way to format javascript code. Turns out, this works for .js files as well!Deprecatory
@Fostah: you can also install the "Text FX Character" via >Plugins>Plugin Manager>Show Plugin ManagerOsteoarthritis
@scronide, Is there a shortcut key for this?Wolgast
Note that despite the name, it absolutely also correctly re-indented the javascript code I was trying to fix the indentation of. No reason I would expect it not to, just mentioning, since the name is rather specific. Dunno why the author of that library felt he had to give special preference to C++... :DUxmal
It doesn't work with User-Defined Languages, I'm trying to use it with GLSL which is mostly C-like.Pericardium
So how does one get started going TextFX > ? I've checked all the menus, plugins, and help file and I don't see anything that looks like that. I can tell Notepadd++ is powerful, but I barely use it because it's so complicated it's almost a no-starter.Shalom
A
108

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"

Akeylah answered 5/1, 2009 at 6:36 Comment(3)
Indent by fold is awesome. The fact that it works in arbitrary formatting (XML, C/++/#, etc.) is great. Only problem with it is the "undo" stack. When used, if you wish to undo to a point before when you indented, you have to undo through every line re-indentation, as it doesn't get added to the stack as a single command. Basically, be careful when working with long files.Diskson
Hi @Dan the undo problem seem to have been fixed in newer version of indent by fold...Comprise
Yes, It doesn't exist and there's no Plugin Manager.Pericardium
S
31

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.

Sphincter answered 5/1, 2009 at 6:36 Comment(1)
you need TextFx plugin for thisInure
O
29

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++.

Obsequious answered 5/1, 2009 at 6:36 Comment(0)
C
22

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
  }
}
Crisper answered 5/1, 2009 at 6:57 Comment(2)
Note that this auto-indent setting in Notepad++ assumes you do the first indent in a block manually; it doesn't auto-format the code for you.Coo
I got your meaning just now,please forgive my poor Eng... My mother language is Chinese...Thomson
S
16

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

Shang answered 5/1, 2009 at 6:36 Comment(1)
Indent by fold is great, except that it only indents by fold ;) In situations where you've indented a list initialization, unless the language uses a folding character to delimit the initializer, it'll end up un-indenting. An example is a multi-line array initialization in PHP using array( ... ), where () are non-folding.Diskson
M
7

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

enter image description here

Mendymene answered 5/1, 2009 at 6:36 Comment(0)
B
5

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

Boabdil answered 5/1, 2009 at 6:36 Comment(0)
H
5

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.

Hellenistic answered 5/1, 2009 at 6:36 Comment(0)
C
3

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

Canaday answered 5/1, 2009 at 6:36 Comment(1)
This plugin is no longer availableMeagher
M
3

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.

Mattoid answered 5/1, 2009 at 6:36 Comment(3)
Can you explain a bit more?Renfrew
More information about configuration can be found here: https://mcmap.net/q/129871/-using-tidy2-for-notepadMattoid
its quite difficult to use this compare to other pluginsLiggett
C
3

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

Cooky answered 5/1, 2009 at 6:36 Comment(1)
Note that the link is direct to the download. The website is: universalindent.sourceforge.net. Also, this appears to be a GUI for configuring a reformating tool, rather than automatically formatting the text correctly to start with.Connelley
M
2

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

Mancino answered 5/1, 2009 at 6:36 Comment(0)
P
0

Tab and Shift+Tab are actually mapped to Edit => Indent => Increase Line Indent / Decrease Line Indent.

Protolithic answered 5/1, 2009 at 6:36 Comment(0)
L
0

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.

Lafontaine answered 5/1, 2009 at 6:36 Comment(0)
I
0

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

Insectivore answered 5/1, 2009 at 6:36 Comment(0)
L
-1

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

Liveryman answered 5/1, 2009 at 6:36 Comment(2)
It could be comment!Dryclean
Can you elaborate on this a little more?Outrage

© 2022 - 2024 — McMap. All rights reserved.