4

I've found that if I copy C# code from off of a website, and paste it into Notepad++, it can look ugly. Basically it's all on 1 line. Is there a way to format code, e.g. a way to take something like 1 long line of C# code, and then properly indent the code?

7
  • 5
    You can paste it into Visual Studio (Express). Commented Nov 17, 2011 at 22:04
  • (VS Express is free by the way) Commented Nov 17, 2011 at 22:04
  • 1
    Visual studio has code autoformating with Ctrl-K-D. MonoDevelop and SharpDevelop probably have a similar feature. Commented Nov 17, 2011 at 22:05
  • 1
    Rather sounds like Rod would like to use Notepad++ Commented Nov 17, 2011 at 22:07
  • @DavidHeffernan well, once copied and reformatted in Visual Studio, the OP cound copy it out again into Notepad++ - the only good use for Visual Studio? Commented Nov 17, 2011 at 22:10

4 Answers 4

11

If you're trying to format a C-style language you can in fact use Notepad++ - but you'll need to install TextFX. You can do that via the Plugin Manager (Plugins -> Plugin Manager) or by downloading the ZIP from here. Once you've downloaded the ZIP just drop that DLL into the Plugins folder for Notepad++ (which is going to be under the install directory) and (re)start Notepad++.

Then when you want to use it use the TextFX -> TextFX Edit -> Reindent C++ Code option from the menu. It will make something like this:

namespace Hello { public class MyClass { } } 

look like this:

namespace Hello { public class MyClass { } } 
Sign up to request clarification or add additional context in comments.

Comments

2

In Visual Studio, when you paste the code, you can go to Edit --> Advanced --> Format Document

In Notepad++ you may be out of luck on the single line thing, but you can go to Language --> C --> C# (or language of code)

5 Comments

Setting thr Language in npp controls the syntax highlighting. I don't see how this answers the question.
It also sets regions / collapsible areas, but you're right, the main formatting would be done in VS using the Format Document (not in Npp)
@DavidHeffernan, npp does in fact do formatting of C type languages. Download TextFX from here and you can just drop the DLL in that ZIP into the Plugins folder.
@DavidHeffernan, yep, TextFX -> Edit -> Reindent C++ Code
@DavidHeffernan, hey thanks! I did that in fact. I really appreciate that and I'm glad I could be of assistance!
2

To add format and other C# specific benefits to notepad++ install a CS-Script Plugin via the Plugin Manager (Plugins -> Plugin Manager)

Comments

1

notepad++ won't format the code.

Follow this steps to do:-

  1. Open visual studio
  2. drag n drop the file on VS
  3. Click on Edit menu
  4. Click on Advanced
  5. Click on Format Document.

1 Comment

Actually, npp does format C style languages. Download TextFX from here and drop the DLL into the Plugins folder.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.