Dark theme

Notepad++
[Tutorial and Download]


Notepad++ is a basic text editor. We could use the built in Windows Notepad (which has many similar generic features), but Notepad++ has some nice features specifically for programmers. You can download it for free from the Notepad++ website.

Notepad++ is nicely set up for basic editing, as it gives you line numbers (as do compilers and interpreters when they warn you of code errors), and syntax colouring - that is, it colours different bits of code different colours, so you can see what they mean in the code progression. Later in the units we'll talk about Integrated Development Environments, which are more sophisticated editors, but for the moment we'll get used to using something simple so we always have something to fall back on.


Where is it?

On Windows 7 or 10 in the University, it should appear on the Start Screen. Alternatively search 'apps' for 'Notepad++'.

On other Windows, click on the Windows button at the bottom of the screen. Then click on 'All programs' and, when the menu pops up, click on 'Notepad++'. When the next menu pops up, Notepad++ should be on it.

Alternatively...

Click on the Windows button at the bottom of the screen (or right-click left end of task-bar in Windows 7 desktop). Click on 'Run...'. Type 'Notepad++' into the long box, and hit 'OK'.


The five important features of Notepad++:


'Cut and paste'

Most Windows programs use the same keys to do common functions, and most use the 'Control' key (labeled 'Ctrl') pushed at the same time as a letter key. The most common are...

  • 'Ctrl' + 'A' To select everything.
  • 'Ctrl' + 'C' Copy text highlighted by dragging the mouse.
  • 'Ctrl' + 'X' Cut out the text highlighted by dragging the mouse and save it.
  • 'Ctrl' + 'V' Paste the text cut or copied into the space where the mouse was last clicked.
  • 'Ctrl' + 'Z' Undo the last action.

To highlight text, drag the mouse across it while keeping the left button depressed. When you get to the end of the text you want, release the mouse button. The text should stay highlighted until you next click the mouse button. If you cut and copy text it goes into the 'clipboard'. You can usually only have one thing at a time in there, but it can be text, pictures or other objects.

Try copying the paragraph above out of your browser and pasting it into Notepad++.


Find and Replace functions

As with most Windows programs, these are...

  • 'Ctrl' + 'F' Find a word.
  • 'Ctrl' + 'H' Find a word and replace it with another.

These are useful for finding a particular place in a long program, and replacing a lot of instances of a word all at once.

[Note that the find/replace in Notepad++ is much more sophisticated than most; for example, if you know how to write regular expressions you can do this in these dialogs]


Save as text with a .xxx extension

If you're writing programs, you'll want to save the source files as plain text, rather than something with a lot of colours and font formatting like a Word file (compilers and interpreters only work with plain text files). Once Notepad++ knows you're dealing with a specific language it will colour syntax and keywords, but it won't save these colours in the file - it recognises them automatically.

However, you'll need to call the file 'yourname.xxx' rather than 'yourname.txt' which is more usual for plain text files. Each language has its own file extension/suffix (for example, in Java it is ".java"; in Python ".py"). The compiler or interpreter will only recognises specific file extensions (though the file itself will usually just be a text file).

If you've got some text in Notepad++ now you can do this by following these instructions...

  • From the menu at the top of Notepad++, choose 'File'.
  • Click on 'Save As...' and a box of options will appear.
  • In the folders displayed, find a suitable one in your personal space to put a temporary file into.
  • In the long box next to 'File name' type 'MyFirstBigNotepadFile.xxx'; where xxx is the language file extension.
  • Click in the long box next to 'Save as type:' - a drop down list will appear.
  • From the list, select either 'All files', 'Normal text file', or 'Java source file', 'Python file', etc.
  • Click 'OK'.

Line numbers

One really useful aspect of Notepad++ is that it shows line numbers. Any given language compiler or interpreter will display the line numbers of any issues, so it is really useful to be able to see these.

If the line numbers aren't showing down the left-hand side of the editor, you can turn these on by going to the Settings menu, selecting Preferences..., finding the Editing tab, and turning on Display line number.


Formating

Note that for programmers a really helpful feature is that you can select a whole set of lines (click and drag mouse), and then push the Tab key to indent the lines, that is, to push all the lines over left to right.

To pull lines the other way (dedent), push Tab while holding the Shift key.

In some languages (Python, for example), tabs and spaces have special meanings, especially in terms of indenting. In Python, for example, the level of indenting is involved in determining the flow of the code. In Python you can use both tabs and spaces, but using both becomes quite error prone and confusing. The Python Software Foundation recommends using 4 spaces for each indent. You can set this up for Notepad++. Do this before editing a file (you'll need to make sure you save the file as .py before it will pick up the formating).

  • Go to Settings -> Preferences... -> Tab Settings (tab).
  • Scroll down the list of Tab Settings to python.
  • Unclick Use default value, check Tab size is set to 4, and click Replace by space. Click the Close button.

When you're ok with this lot, head back using your browser's back button.