Using Notepad++ as external editor in Unity 3D

Summary:

  • Notepad++ (version 6.3 at the time of writing this)
  • UnitEd Redirector
  • Keywords file for Unity 4 (for Add the keywords to Notepad++ below)
  • Auto-completion info for Unity 4  (for Enable auto-completion and hints for function parameters below, file is already parsed with the Python script)
  • Edy.xml, cs.xml and javascript.xml files for Notepad++:
    – Edy.xml is my own theme which includes the keywords for CS and JS. Move to the themes folder.
    – cs.xml and javascript.xml are the auto-completion and function hint information files. Move to plugins\APIs overwriting the existing ones.

Configuring Unity 3D for using Notepad++

If you choose Notepad++ as external editor in Unity’s Preferences, clicking on an error message will open the file but will NOT move the focus to the offending line.

  1. Download UnitEd Redirector (original by Yggy King, updated by me, source included) and unzip it to a folder of your choice.
  2. Choose the monodevelop.exe file of the redirector as the external editor in Unity3D.
  3. Set the environment variable UNITYEDITOR in Windows as follows:
    UNITYEDITOR=<full-path-to-notepad++>\notepad++.exe -n{line} {file}

It’s worth mention that Unity only sends the line information to the external editor when the name of the executable is monodevelop.exe. Any other executable name won’t receive this information.

Configuring the Language Help

This enables Ctrl-F1 to search for information on the word under the cursor at the Unity help page.

  1. Plugins > Plugin Manager > Show Plugin Manager
  2. Find Language Help, select its checkbox, click Install.
    If automatic install fails you can download it here and install it manually.
  3. Plugins > Language Help > Options
  4. Click Add, enter the following data, and Ok:
    Name: Unity 3D
    Extensions/file mask: *.cs;*.js;*.boo;*.shader;*.compute
    Extended help file path: http://docs.unity3d.com/Documentation/ScriptReference/30_search.html?q=$word$
  5. Optional: Show entry in context menu (allow search by right clicking a word in the editor)

Optional: Create your own theme

This prevents future updates of Notepad++ to override your changes. They will be persistently stored in your own theme:

  1. Settings > Style Configurator
  2. Select Theme: choose the theme that better fits your style. This will be your base theme.
  3. Find the theme name in the Themes folder inside the Notepad++ folder and make a duplicate. Give the file a proper name (i.e. My Style). This is the name that will be shown at the themes list.
    If you want to use the default theme then make a duplicate of the file stylers.xml
    and place it inside the Themes folder.
  4. Restart Notepad++
  5. Settings > Style Configurator. Choose your theme. Click Save&Close.

Hints:

  • Some times you will prefer to edit directly the file My Style.xml instead of using the Style Configurator. For instance: a custom background color can be configured in Global Overrides, but if you want to use background colors in some of your styles then you should change the background globally on all styles using search & replace in the xml file.
  • Set the global styles first, then focus on a single language each time.
  • Information on the Style Configurator an the global styles.

Enabling syntax highlight

Unity keywords are located in this file (use “Program Files (x86)” on 64-bit systems):

C:\Program Files\Unity\Editor\Data\Tools\UniSciTE\unitykeywords.properties

Open it at Notepad++. The line 2 contains all the keywords.

Optional: Ensure that Notepad++ will recognize all keywords (also the ones inside the enums)

The enums are composed like in KeyCode.Keypad0, with the dot. Notepad wouldn’t recognize Keypad0 as keyword, not even when used with KeyCode.

This can be fixed with some massaging to the unitykeywords.properties file. The TextFX plugin for Notepad++ helped a lot. This may be somewhat advanced and I won’t go into the details. You can always use the keywords as they come but some of them won’t be highlighted.

  1. Use a macro (record & repeat) for removing all dots and the each word preceding a dot.
    (if you are good with RegEx you’ll surely find an easier way using the Search & Replace function)
  2. Select a single space character and copy it to the clipboard
  3. TextFX > TextFX Edit > Split lines at (clipboard characer) or , (VB)
    A this time you may want to search for KeyCode and remove the spare letters A to Z. I don’t see the point of having these highlighted, but it’s up to you.
  4. Select All (and keep all selected for the next operations)
  5. TextFX Tools > check Sort outputs only UNIQUE (at column) lines
  6. TextFX Tools > Sort lines case sensitive (at column)
  7. TextFX Edit > Unwap text

All keywords are now unique, without dots, sorted, and grouped in a single line.

Add the keywords to Notepad++

Once you have the text line with all the keywords:

  1. Settings > Style Configurator.
  2. Select the language you want to add the keywords too (typically C# or Javascript).
  3. Select KEYWORD or INSTRUCTION WORD. A text area labeled User-defined keywords should appear.
  4. Type an unique word, whatever, at the User-defined keywords area. For instance, type myuniquekeyword. If the text area already contains keywords, add yours at the end.
  5. Save & Close.
  6. Open the xml file for your theme in Notepad++ (or stylers.xml if you’re modifying the default theme).
  7. Search (Ctrl-B) for myuniquekeyword (or whatever word you’ve typed at step 4).
  8. Replace that word with the entire keywords line obtained from the file unitykeyword.properties.
  9. Save the file and restart Notepad++.

Repeat for each language you want to set the keywords to.

Enabling auto-completion and hints for function parameters

Settings > Preferences > Backup/Auto-Completion > Enable auto-completion on each input
Settings > Preferences > Backup/Auto-Completion > Function parameters hint on input 

Word completion only completes keywords. Function completion completes keywords and functions. The lists of words that feed these features are at the folder <Notepad>\plugins\APIs, named as their corresponding language.

Unity auto-completion information is located here (use “Program Files (x86)” on 64-bit systems):

C:\Program Files\Unity\Editor\Data\Tools\UniSciTE\UnityCS.api

Needs to be converted to the Notepad++ XML format:

  1. Download the UnityJSapi_to_Npp.py script by AnomalousUnderdog.
  2. Edit the first lines for specifying the proper routes and files.
  3. Run the script with Python.

The resulting file Unity_to_Npp.txt can now be merged with the auto-complete files. Important: the Keyword tags of the merged file must be sorted by their name property.

  1. Open both Unity_to_Npp.txt and the auto-complete file (typically cs.xml or javascript.xml) in Notepad++.
  2. Copy all the contents of Unity_to_Npp.txt and paste them in the xml file somewhere inside the <AutoComplete> tag.
  3. Apply the same indentation to all <keyword> lines. You may do so by selecting the newly pasted lines and using TAB / Shift-TAB.
  4. Select all the <keyword> lines.
  5. TextFX > TextFX Tool > Sort lines case insensitive (at column).

Repeat for each language you want to set the auto-completion to.

Note that changes on files in the API folder are not persistent when updating Notepad++. You should make backup copies of the modified xml files.

Goodies for improved usability

Enabling Virtual Spaces / Cursor past end of line

Allows the cursor to be placed and moved anywhere in the workspace, not only over actual lines of text.

ScrollPastEOF plugin

Allows to scroll up to one page beyond the end of the file. Useful for not having to append text to files by watching at the very bottom of the screen (nor having to insert empty lines).

Use the Plugin Manager (Plugins > Plugin Manager) for install this one.

Ctrl-PageUp, Ctrl-PageDown: cursor to top / bottom of the current page

This is is a handy feature for quickly moving the cursor, and seems to have been “forgotten” to include in the default shortcuts:

  1. Settings > Shortcut Mapper > Scintilla commands
  2. SCI_STUTTEREDPAGEUP -> Ctrl + Page up
    SCI_STUTTEREDPAGEDOWN -> Ctrl + Page down
    SCI_STUTTEREDPAGEUPEXTEND -> Ctrl + Shift + Page up
    SCI_STUTTEREDPAGEDOWNEXTEND -> Ctrl + Shift + Page down

The last two allows to extend the text selection to the top/bottom of the page.

Bonus

Using Notepad++ as default editor for GIT

This will make GIT invoke Notepad++ for all its text editing tasks instead of the actual vi, or vim, or whatever thing is that:

git config --global core.editor "'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"

The command line switches makes Notepad++ to open the file requested by GIT in a separated, isolated instance that doesn’t interfere in any way with your current working session.

Adding code-formatting tools

http://www.blogetcetera.com/2012/adding-code-formatting-tools-notepad/

Bonus++: Configuring the appearance of MonoDevelop

You can completely customize the look and feel of MonoDevelop, so it’s more pleasant to use when you have to (i.e. for debugging Unity 3D code).

  1. Download the GTK+ Themes and GTK+ Theme Switcher zip files and extract both them to a temporary directory:

    http://downloads.sourceforge.net/gtk-win/gtk2-themes-2009-09-07-win32_bin.zip
    http://downloads.sourceforge.net/gtk-win/gtk2_prefs-0.4.1.bin-gtk2.10-win32.zip

  2. Copy the lib and share folders to the MonoDevelop’s folder, merging the contents with the existing lib and share folders.
  3. Copy the executable (gtk2_prefs.exe) to the bin folder of MonoDevelop and run it (gtk2_prefs, not MonoDevelop).

A list of the all available themes appear. Selecting them changes the theme of the window so you can preview them. Also, click the “show preview” button for an extended preview. Ensure to select the option “Use theme default font”! (or choose the font of your liking).

These themes look very nice with MonoDevelop:

  • Darklooks
  • LighthouseBlue
  • Nimbus (my personal favorite)
  • Unity

When done, click Ok and open MonoDevelop.

Enjoy!