Formatting code with line numbers

When the code is in Notepad++, you can use TextFX->TextFX Tools->Insert line numbers to put line numbers in front of all of the necessary lines. Then when you copy/paste, the line numbers will be there.


To avoid having to remove unnecessary leading zeros, you can use the Notepad++ column editor (Edit -> Column Editor or Alt+C) after you've done a column select at the first column. You'll get a window like this:

Column Editor Window

I like to use leading zeros, but you can just as well leave them out. Trailing spaces will be added instead. You will have to indent your code one extra time (or use a leading space), as this method won't automatically add one for you.


I just conjured up a way that works amazingly for myself:

  1. Copy your code from your IDE and paste it into Word.  If your IDE has colors enabled for different parts of the program, you can paste with formatting to retain that.
  2. Highlight all text (Ctrl+A).
  3. In the Styles section of the Home tab, click the dropdown arrow and select create a new style.
  4. Give your style a name and click modify.
  5. Choose your basic formatting settings such as font, size, and spacing, etc.  I recommend Consolas as the font and your size is up to you.
  6. Select format in the lower-left corner of the window and click numbering, and select the format that you like best.
  7. Save your style and it should mirror your IDE almost exactly, ready to export or print as needed.