Using Sublime Text as a script editor

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(Syntax highlighting)
(changed basic setup for OS X)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Sublime Text is a popular cross-platform text and source code editor. It is extendable and its community has contributed numerous packages(plugins/extensions/addons) for Sublime Text.
+
'''''Sublime Text''''' is a popular cross-platform text and source code editor. It is extendable and its community has contributed numerous packages (plugins/extensions/addons) for Sublime Text.
  
== Directions ==
+
== Basic setup ==
# Sublime Text can be found at the [http://www.sublimetext.com/ Official Website]. Download and install.
+
# Sublime Text can be found at its [http://www.sublimetext.com/ official website]. Download and install.
# ''(Mac users should look at 4th step before proceeding)'' Change your External Script Editor to Sublime Text. (In Unity, '''"Edit"''' -> '''"Preferences"''' -> '''"General"''')
+
# Change your External Script Editor to Sublime Text:
# Unity should now open Sublime Text whenever you double-click a script (or any text file).
+
#* '''Windows''': In Unity: Edit > Preferences > External Tools > edit "External Script Editor" and navigate to Sublime Text, file subl.exe
# Make Sublime Text jump to line that causes an error/warning:
+
#* '''Mac OS X''': Open a Terminal window and run:<br><code>defaults write com.unity3d.UnityEditor5.x kScriptsDefaultApp "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl"</code>
 +
# To make Sublime Text jump to the file and line that causes an error/warning set the ''[http://docs.unity3d.com/Manual/Preferences.html#External-Tools External Script Editor Args]'' field to: <code>"$(File)":$(Line)</code>.
 +
#* '''Mac OS X''': If the previous ''[http://docs.unity3d.com/Manual/Preferences.html#External-Tools External Script Editor Args]'' is not available in your version of Unity, there is a workaround using a shell script, save this to a file, make it executable (if required) and set that file as the script editor in Unity (Linux users running the Windows version using Wine may also do this):
  
'''Windows''': You should set the ''[http://docs.unity3d.com/Manual/Preferences.html External Script Editor Args]'' field to: <code>"$(File)":$(Line)</code>, so that Sublime Text jumps to the line where the error, warning or notice occurs, when they are double clicked upon.
+
<pre>
 
+
#!/bin/sh
'''Mac OS X''': If the previous ''[http://docs.unity3d.com/Manual/Preferences.html External Script Editor Args]'' is not available in your version of Unity, there is a workaround using a shell script, save this to a file, make it executable(if required) and set that file as the script editor in Unity(Linux users running the Windows version using Wine may also do this):
+
 
+
<pre>#!/bin/sh
+
 
   
 
   
 
# Change '/opt/sublime_text/sublime_text' to the path to your executable of Sublime Text.
 
# Change '/opt/sublime_text/sublime_text' to the path to your executable of Sublime Text.
Line 22: Line 21:
 
   
 
   
 
echo "Opening '$1' on line '$2' column '$3' with Sublime Text"
 
echo "Opening '$1' on line '$2' column '$3' with Sublime Text"
exit 0</pre>
+
exit 0
 +
</pre>
  
==Project Setup==
+
== Project feature setup ==
  
 
Creating a project file has some advantages:
 
Creating a project file has some advantages:
Line 30: Line 30:
 
* Settings - filter out irrelevant files (e.g., .meta files)
 
* Settings - filter out irrelevant files (e.g., .meta files)
  
To create a project use '''"File"''' -> '''"Open Folder"''' from the header menu and open your Unity3D project's folder(parent of the "Assets" folder). Then use '''"Tools"''' -> '''"Save Project As"''' to create a my_project.sublime-project file in your project root directory (outside Assets).
+
To create a project, use '''File > Open Folder...''' to open your Unity project folder (parent of the <code>Assets</code> folder). Then, create a <code>My Awesome Game.sublime-project</code> file in your Unity project folder with '''Project > Save Project As...'''.
 +
 
 +
Now edit that .sublime-project file with '''Project > Edit Project'''.  For example, the following edit will include only the <code>Assets/Scripts</code> folder and exclude .meta and .dll binary files:
  
For example, this will include only the Assets/Scripts folder and exclude .meta and .dll binary files:
 
 
<pre>
 
<pre>
 
{
 
{
Line 49: Line 50:
 
</pre>
 
</pre>
  
==Package Control==
+
== Package Control ==
  
Sublime Text has a package called '''"Package Control"''' that allows to easily search and manage installed packages. Follow the few instructions described by the official maintainer of package:
+
'''[https://packagecontrol.io/ Package Control]''' is a Sublime Text package that allows for easy package management to find and install other packages. Follow the [https://packagecontrol.io/installation installation instructions on their site].
https://sublime.wbond.net/installation
+
  
"Package Control" for Sublime Text 3 uses "Git" distributed revision control and source code management (SCM) system to retrieve and update packages, so if you use ST3 install [http://git-scm.com/ Git] for your operating system.
+
To access the Package Control functions:
 +
* '''Preferences > Package Control''' menu (ST3), or
 +
* Open the Command Palette
 +
** By one of:
 +
*** '''Tools > Command Palette''' menu
 +
*** Mac: '''Command+Shift+P''' shortcut
 +
*** Windows/Linux '''Ctrl+Shift+P''' shortcut
 +
** Then start typing in "Package Control" (without the quotes).
  
To access "Package Control" functions from within Sublime Text:
+
== Syntax highlighting ==
# Open the "Command Palette" through '''"Tools"''' -> '''"Command Palette"''' from the header menu or use the default Command+Shift+P(OS X) or Ctrl+Shift+P(Windows/Linux) shortcut.
+
# Write "Package Control"(without quotes) and you will see functions made available by the package including installing and removing packages.
+
  
==Syntax highlighting==
+
=== Unity C# and JavaScript syntax highlighting ===
  
===Unity C# and JavaScript Syntax highlighting===
+
Install the '''C#''' package (if not installed already) and the '''[https://packagecontrol.io/packages/Unity3D Unity3D Syntax Highlighting]''' package, either by using Package Control or by cloning the package using Git from [https://github.com/UnicornForest/Unity3D/ Github].
  
Install the '''"C#"'''(could be installed by default) and '''[https://github.com/UnicornForest/Unity3D "Unity3D Syntax Highlighting"]''' package either by using the Package Control or by cloning the package using Git from [https://github.com/UnicornForest/Unity3D/ Github].
+
Once installed you can select '''View > Syntax > Unity3D''' and then either '''Unity C#''' or '''Unity JavaScript'''. You may also want to select '''View > Syntax > Open all with current extension as...''' so that Sublime Text will always use Unity syntax highlighting when viewing C# or JavaScript Files.
  
'Once installed you can select '''"View"''' -> '''"Syntax"''' -> '''"Unity3D"''' and then either '''"Unity C#"''' or '''"Unity JavaScript"'''.
+
=== Other C# syntax highlighting compatibility ===
You may also want to select the '''“Open all with current extension”''' option so that Sublime Text 2 will always use Unity syntax highlighting when viewing C# or JavaScript Files.' - Jacob Pennock
+
  
===For plain C# Syntax highlighting compatibility===
+
Note that using '''Unity C#''' with '''Open all with current extension as...''', Sublime Text will not differentiate between Unity C# files and non-Unity C# files (both use the .cs extension). One way to avoid this is to install the '''[https://packagecontrol.io/packages/ApplySyntax ApplySyntax]''' package and add the following to its settings:
 
+
Note that using "Unity C#" with Sublime Text's built-in "Open all with current extension" will not differentiate between C# scripts that use Unity API and external ones that do not, since they both have the "cs" file extension. One way to avoid this is to use a package called '''[https://github.com/facelessuser/ApplySyntax "ApplySyntax"]''' and add the following to its settings:
+
  
 
<pre>
 
<pre>
Line 88: Line 90:
 
]
 
]
 
</pre>
 
</pre>
 +
 
(The "Unity3D" package might still lay compressed within Sublime Text's "Installed Packages" folder, which contains "UnityC#.tmLanguage" file that ApplySyntax will be looking for within non-existant "Packages/Unity3D" folder)
 
(The "Unity3D" package might still lay compressed within Sublime Text's "Installed Packages" folder, which contains "UnityC#.tmLanguage" file that ApplySyntax will be looking for within non-existant "Packages/Unity3D" folder)
  
===Boo Syntax highlighting===
+
=== Boo syntax highlighting ===
  
Install the [https://github.com/Shammah/boo-sublime "Boo"] package using Package Control.
+
Install one of:
 +
* '''[https://packagecontrol.io/packages/Boo Boo]'''
 +
* '''[https://packagecontrol.io/packages/Boo%20%26%20BooJs Boo & BooJs]''' (includes code completions)
  
===Unity Shader Syntax highlighting===
+
=== Unity Shader syntax highlighting ===
  
Install the [https://github.com/petereichinger/Unity3D-Shader "Unity3D ShaderLab"] Sublime Text package.
+
Install one of:
 +
* '''[https://packagecontrol.io/packages/Unity3D%20Shader%20Highlighter%20and%20Snippets Unity​3​D Shader Highlighter and Snippets]'''
 +
* '''[https://packagecontrol.io/packages/Unity%20Shader Unity Shader]''' (includes code completions)
  
==Code Autocompletion==
+
== Code completions ==
  
===Setting C# Unity API Classes Autocompletion===
+
For simple, predefined completions, install one or more of:
 +
* '''[https://packagecontrol.io/packages/Unity%20Completions Unity Completions]''' - C#, JavaScript, and Boo
 +
* '''[https://packagecontrol.io/packages/Unity%20Completions%20Light Unity Completions Light]''' - C#, JavaScript, and Boo (if the full package is too slow to startup)
 +
* '''[https://packagecontrol.io/packages/Unity3D%20Snippets%20and%20Completes Unity3D Snippets and Completes]'''
  
Install the following Sublime Text packages by following the instructions on their respective Github README:
+
The above completions, however, are less than satisfying because they do not work across dot notation. Please read the other options below for ST2 and ST3 before deciding what to do.
* '''[https://github.com/oferei/sublime-unity-completions-light "Unity Completions Package Light"] ''or'' [https://github.com/oferei/sublime-unity-completions "Unity Completions Package"]''' for Unity API element autocompletion
+
* '''[https://github.com/etic/CSharpSnippets "C# Snippets"]''' for inserting useful C# snippets
+
* '''[https://github.com/TwoHeadedAnt/Unity3DSnippets/tree/a949fc8d7c0accb926582d731cdb5411f35ce9a1 "Unity3D Snippets and Completes"]''' for inserting useful Unity related snippets
+
* '''[https://github.com/ewilde/CompleteSharp "CompleteSharp"]''' for dynamic autocompletion
+
  
Sublime Text package by following the instructions on Github README. User "quarnster" was the original author of CompleteSharp, but has discontinued working on it. "ewilde" version is a bit more up to date and includes a already compiled "CompleteSharp.exe" file which the package uses, which otherwise has to be compiled using Mono(gmcs command).
+
=== Advanced C# completions for Sublime Text 2 ===
  
Add extra assemblies for CompleteSharp to the settings either through '''"Preferences"''' -> '''"Settings - User"''' or '''"Project"''' -> '''"Edit Project"'''(opens project settings file) so that Unity3D classes are recognized ("..." represent other possible content between JSON elements):
+
Instead of—or in addition to—the above Unity-specific completions, you can also install the following package for dynamically reading .dll files for completion data:
<pre>
+
"folders": [
+
...
+
], //<- comma required
+
...
+
"settings": {
+
...
+
  
// Uncomment the next line for OS X/Linux, if "mono" does not launch Mono in the Terminal.
+
* '''[https://github.com/ewilde/CompleteSharp "CompleteSharp"]'''
//"completesharp_mono_path": "/Applications/Unity/MonoDevelop.app/Contents/MacOS/bin/MonoDevelop",
+
  
// Possible default directory paths for Unity:
+
Do not install the CompleteSharp version available through Package Control.  The one on Package Control is the original one by "quarnster" but the version by "ewilde" (linked above) includes an already-compiled "CompleteSharp.exe" which makes it easier overall to install.
// Windows: C:\Program Files\Unity\Editor\Data\
+
// Windows 64-bit: C:\Program Files (x86)\Unity\Editor\Data\
+
// Mac OS X: /Applications/Unity/Unity.app/Contents/Frameworks/
+
  
"completesharp_assemblies": [
+
You can install CompleteSharp via Git as described on its Github page, or you can download the Zip files and reassemble the sub-projects into their respective folders:
"<path-to-Unity-folder>\\Managed\\UnityEngine.dll",
+
  
"<path-to-Unity-folder>\\Managed\\UnityEditor.dll",
+
* Note that these links are to the latest master version of each project and each contains newer code than what just a Git clone of the top project will get you:
 +
** [https://github.com/ewilde/CompleteSharp/archive/master.zip CompleteSharp-master.zip] - Unzip to <code>Packages\CompleteSharp</code>
 +
** [https://github.com/quarnster/SublimeCompletionCommon/archive/master.zip SublimeCompletionCommon-master.zip] - Unzip to <code>Packages\CompleteSharp\sublimecompletioncommon</code>
 +
** [https://github.com/quarnster/parsehelp/archive/master.zip parsehelp-master.zip] - Unzip to <code>Packages\CompleteSharp\sublimecompletioncommon\parsehelp</code>
  
"<path-to-Unity-folder>\\Mono\\lib\\mono\\unity\\UnityScript.dll",
+
<blockquote>'''Sublime Text 3 note:''' If you are trying to get CompleteSharp to work in ST3, you will need the latest code from each sub-project listed above (the latest are already linked for you above). A better option for ST3, however, is described in the next section.</blockquote>
  
"<path-to-Unity-folder>\\Mono\\lib\\mono\\unity\\System.Core.dll",
+
To find your <code>Packages</code> folder to install to, go to '''Preferences > Browse Packages...'''.
  
"<path-to-Unity-folder>\\Mono\\lib\\mono\\unity\\System.dll",
+
After CompleteSharp is installed, edit either your user settings or your project settings to add in the Unity assemblies and other libraries your project uses.  To edit CompleteSharp settings:
 +
* If using Sublime Text project feature: '''Project > Edit Project'''
 +
* If not using Sublime Text project feature: '''Preferences > Settings - User'''
  
"<path-to-Unity-folder>\\Managed\\nunit.framework.dll",
+
The code below represents a typical minimal setup.  More .dll files can be added if using packages that include them.  '''''Make sure, however, that all these files still exist in your project and your version of Unity.'''''  This list is outdated regarding the <code>ScriptAssemblies</code> folder. CompleteSharp may not work at all until the list of .dll files is entered without error.
  
"<path-to-Unity-folder>\\Mono\\lib\\mono\\unity\\mscorlib.dll",
+
<code>...</code> represents other possible content between JSON elements.
  
"<path-to-Unity-folder>\\Mono\\lib\\mono\\unity\\System.Core.dll",
+
Replace <code><path-to-Unity-folder></code> with the path to your Unity folder (double slashed like the rest) such as <code>C:\\Program Files\\Unity\\Editor\\Data</code>.
  
"<path-to-Unity-folder>\\Mono\\lib\\mono\\unity\\System.dll",
+
<pre>
 +
{
 +
...
 +
"folders":
 +
[
 +
...
 +
], //<- comma required
 +
...
 +
"settings":
 +
{
 +
...
  
"${project_path:Library}\\ScriptAssemblies\\Assembly-CSharp.dll",
+
// Uncomment the next line for OS X/Linux, if "mono" does not launch Mono in the Terminal.
 +
//"completesharp_mono_path": "/Applications/Unity/MonoDevelop.app/Contents/MacOS/bin/MonoDevelop",
  
"${project_path:Library}\\ScriptAssemblies\\Assembly-CSharp-Editor.dll",
+
// Possible default directory paths for Unity:
 +
// Windows: C:\Program Files\Unity\Editor\Data\
 +
// Windows 64-bit: C:\Program Files (x86)\Unity\Editor\Data\
 +
// Mac OS X: /Applications/Unity/Unity.app/Contents/Frameworks/
  
"${project_path:Library}\\ScriptAssemblies\\Assembly-UnityScript-Editor.dll",
+
"completesharp_assemblies": [
 +
"<path-to-Unity-folder>\\Managed\\UnityEngine.dll",
 +
"<path-to-Unity-folder>\\Managed\\UnityEditor.dll",
 +
"<path-to-Unity-folder>\\Mono\\lib\\mono\\unity\\UnityScript.dll",
 +
"<path-to-Unity-folder>\\Mono\\lib\\mono\\unity\\System.Core.dll",
 +
"<path-to-Unity-folder>\\Mono\\lib\\mono\\unity\\System.dll",
 +
"<path-to-Unity-folder>\\Managed\\nunit.framework.dll",
 +
"<path-to-Unity-folder>\\Mono\\lib\\mono\\unity\\mscorlib.dll",
 +
"${project_path:Library}\\ScriptAssemblies\\Assembly-CSharp.dll",
 +
"${project_path:Library}\\ScriptAssemblies\\Assembly-CSharp-Editor.dll",
 +
"${project_path:Library}\\ScriptAssemblies\\Assembly-UnityScript-Editor.dll",
 +
"${project_path:Library}\\ScriptAssemblies\\Assembly-CSharp-firstpass.dll"
 +
],
 +
"completioncommon_inhibit_sublime_completions": true,
 +
"completioncommon_shorten_names": true
  
"${project_path:Library}\\ScriptAssemblies\\Assembly-CSharp-firstpass.dll"
+
...
],
+
}
 +
...
 +
}
 +
</pre>
  
"completioncommon_inhibit_sublime_completions": true,
+
After saving these settings, this should automatically reload CompleteSharp's python scripts and have its autocompletion ready.  To see any errors, open the console by using Ctrl+` (tilde key).
  
"completioncommon_shorten_names": true
+
=== Advanced C# completions for Sublime Text 3 ===
  
...
+
In ST3, you can replace all of the above completion packages (Unity Completions and CompleteSharp, etc.) with a far better tool that will give Sublime Text capabilities similar to MonoDevelop or Visual Studio—including dynamic interpretation of .cs source files for code completion (but most notably missing are the API documentation excerpts next to the autocomplete hints):
 +
 
 +
* '''[http://www.omnisharp.net/ OmniSharp]'''
 +
 
 +
Go to the OmniSharp web page (linked above) and follow their instructions for installing it for Sublime Text.  (Currently, this requires two packages available via Package Control, and other settings.)
 +
 
 +
* The listed requirement for the Mono Development Kit does not appear to be required (perhaps because Unity is installed).
 +
 
 +
Restart ST3 for the OmniSharp local server to start running correctly.
 +
 
 +
Note that if you are using the Project feature of Sublime Text (strongly recommended), you '''must''' add the location of your Unity project .sln file to the .sublime-project file ('''Project > Edit Project'''):
 +
 
 +
<pre>
 +
{
 +
"folders":
 +
[
 +
{
 +
"follow_symlinks": true,
 +
"path": "Assets/Scripts",
 +
"file_exclude_patterns":
 +
[
 +
"*.dll",
 +
"*.meta"
 +
]
 +
}
 +
],
 +
"solution_file": "./My Awesome Game.sln",
 
}
 
}
 
</pre>
 
</pre>
  
After saving these settings, this should automatically reload CompleteSharp's python scripts and have its autocompletion ready. Note that the default behavior of Sublime Text's autocompletion is to take elements available within the opened file, compare against that. To see if any errors pop-up open the console by using Ctrl+`(Tilde key).
+
OmniSharp adds several commands to the context menu in Sublime Text. Note, however, that when clicking through a bunch of these commands in a row, the OmniSharp server can stop functioning (as of v1.9.6).  Thus, be careful and on the lookout for things that may stop the server. Restarting ST3 should restart the server.
  
===Boo and JavaScript Unity API AutoCompletion===
+
== Other packages of interest ==
* Install '''[https://github.com/oferei/sublime-unity-completions-light Unity Completions Package Light] ''or'' [https://github.com/oferei/sublime-unity-completions Unity Completions Package]''' packages, which also support Boo and JavaScript.
+
* Author: [[User:tortoise|Ofer Reichman]]
+
Easy installation: using [https://sublime.wbond.net Package Control] => Install Package => Unity Completions
+
  
==Community Support==
+
* [https://packagecontrol.io/packages/C%23%20Snippets C# Snippets]
 +
* [https://github.com/titoBouzout/SideBarEnhancements Side Bar Enhancements] - Provides extra options when right-clicking on a file or folder on the sidebar.
 +
* [http://sublimelinter.readthedocs.org/en/latest/# Sublime Linter 3] - A framework for creating [http://sublimelinter.readthedocs.org/en/latest/about.html#what-is-a-linter linters] for a variety of programming languages. An in development [https://github.com/Pendrokar/SublimeLinter-contrib-csharplint csharplinter] is available.
 +
 
 +
== Community Support ==
  
 
See [http://forum.unity3d.com/threads/128352-Using-Unity-with-Sublime-Text-2-(How-to-get-everything-set-up) "Using Unity with Sublime Text" forum thread]
 
See [http://forum.unity3d.com/threads/128352-Using-Unity-with-Sublime-Text-2-(How-to-get-everything-set-up) "Using Unity with Sublime Text" forum thread]
  
===Helpful Sublime Text packages===
 
* [https://github.com/titoBouzout/SideBarEnhancements Side Bar Enhancements] - Provides extra options when right-clicking on a file or folder on the sidebar.
 
* [http://sublimelinter.readthedocs.org/en/latest/# Sublime Linter 3] - A framework for creating [http://sublimelinter.readthedocs.org/en/latest/about.html#what-is-a-linter linters] for a variety of programming languages. An in development [https://github.com/Pendrokar/SublimeLinter-contrib-csharplint csharplinter] is available.
 
 
[[Category: Tutorials]]
 
[[Category: Tutorials]]

Latest revision as of 14:30, 3 October 2019

Sublime Text is a popular cross-platform text and source code editor. It is extendable and its community has contributed numerous packages (plugins/extensions/addons) for Sublime Text.

Contents

[edit] Basic setup

  1. Sublime Text can be found at its official website. Download and install.
  2. Change your External Script Editor to Sublime Text:
    • Windows: In Unity: Edit > Preferences > External Tools > edit "External Script Editor" and navigate to Sublime Text, file subl.exe
    • Mac OS X: Open a Terminal window and run:
      defaults write com.unity3d.UnityEditor5.x kScriptsDefaultApp "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl"
  3. To make Sublime Text jump to the file and line that causes an error/warning set the External Script Editor Args field to: "$(File)":$(Line).
    • Mac OS X: If the previous External Script Editor Args is not available in your version of Unity, there is a workaround using a shell script, save this to a file, make it executable (if required) and set that file as the script editor in Unity (Linux users running the Windows version using Wine may also do this):
#!/bin/sh
 
# Change '/opt/sublime_text/sublime_text' to the path to your executable of Sublime Text.
 
# Sublime Text 2:
# "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" $1:$2:$3
 
# Sublime Text 3:
"/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" $1:$2:$3
 
echo "Opening '$1' on line '$2' column '$3' with Sublime Text"
exit 0

[edit] Project feature setup

Creating a project file has some advantages:

  • Context - specify your script folder(s) for easy search & navigation between your files
  • Settings - filter out irrelevant files (e.g., .meta files)

To create a project, use File > Open Folder... to open your Unity project folder (parent of the Assets folder). Then, create a My Awesome Game.sublime-project file in your Unity project folder with Project > Save Project As....

Now edit that .sublime-project file with Project > Edit Project. For example, the following edit will include only the Assets/Scripts folder and exclude .meta and .dll binary files:

{
	"folders":
	[
		{
			"path": "Assets/Scripts",
			"file_exclude_patterns":
			[
				"*.dll",
				"*.meta"
			]
		}
	]
}

[edit] Package Control

Package Control is a Sublime Text package that allows for easy package management to find and install other packages. Follow the installation instructions on their site.

To access the Package Control functions:

  • Preferences > Package Control menu (ST3), or
  • Open the Command Palette
    • By one of:
      • Tools > Command Palette menu
      • Mac: Command+Shift+P shortcut
      • Windows/Linux Ctrl+Shift+P shortcut
    • Then start typing in "Package Control" (without the quotes).

[edit] Syntax highlighting

[edit] Unity C# and JavaScript syntax highlighting

Install the C# package (if not installed already) and the Unity3D Syntax Highlighting package, either by using Package Control or by cloning the package using Git from Github.

Once installed you can select View > Syntax > Unity3D and then either Unity C# or Unity JavaScript. You may also want to select View > Syntax > Open all with current extension as... so that Sublime Text will always use Unity syntax highlighting when viewing C# or JavaScript Files.

[edit] Other C# syntax highlighting compatibility

Note that using Unity C# with Open all with current extension as..., Sublime Text will not differentiate between Unity C# files and non-Unity C# files (both use the .cs extension). One way to avoid this is to install the ApplySyntax package and add the following to its settings:

"syntaxes": [
...
{
	// Unity 3D C# format detection.
	"name": "Unity3D/UnityC#",
	"match": "all",
	"rules": [
		{"file_name": ".*\\.cs$"},
		{"contains": "using UnityEngine;\n"}
	]
}
...
]

(The "Unity3D" package might still lay compressed within Sublime Text's "Installed Packages" folder, which contains "UnityC#.tmLanguage" file that ApplySyntax will be looking for within non-existant "Packages/Unity3D" folder)

[edit] Boo syntax highlighting

Install one of:

[edit] Unity Shader syntax highlighting

Install one of:

[edit] Code completions

For simple, predefined completions, install one or more of:

The above completions, however, are less than satisfying because they do not work across dot notation. Please read the other options below for ST2 and ST3 before deciding what to do.

[edit] Advanced C# completions for Sublime Text 2

Instead of—or in addition to—the above Unity-specific completions, you can also install the following package for dynamically reading .dll files for completion data:

Do not install the CompleteSharp version available through Package Control. The one on Package Control is the original one by "quarnster" but the version by "ewilde" (linked above) includes an already-compiled "CompleteSharp.exe" which makes it easier overall to install.

You can install CompleteSharp via Git as described on its Github page, or you can download the Zip files and reassemble the sub-projects into their respective folders:

  • Note that these links are to the latest master version of each project and each contains newer code than what just a Git clone of the top project will get you:
Sublime Text 3 note: If you are trying to get CompleteSharp to work in ST3, you will need the latest code from each sub-project listed above (the latest are already linked for you above). A better option for ST3, however, is described in the next section.

To find your Packages folder to install to, go to Preferences > Browse Packages....

After CompleteSharp is installed, edit either your user settings or your project settings to add in the Unity assemblies and other libraries your project uses. To edit CompleteSharp settings:

  • If using Sublime Text project feature: Project > Edit Project
  • If not using Sublime Text project feature: Preferences > Settings - User

The code below represents a typical minimal setup. More .dll files can be added if using packages that include them. Make sure, however, that all these files still exist in your project and your version of Unity. This list is outdated regarding the ScriptAssemblies folder. CompleteSharp may not work at all until the list of .dll files is entered without error.

... represents other possible content between JSON elements.

Replace <path-to-Unity-folder> with the path to your Unity folder (double slashed like the rest) such as C:\\Program Files\\Unity\\Editor\\Data.

{
	...
	"folders":
	[
		...
	],  //<- comma required
	...
	"settings":
	{
		...

		// Uncomment the next line for OS X/Linux, if "mono" does not launch Mono in the Terminal.
		//"completesharp_mono_path": "/Applications/Unity/MonoDevelop.app/Contents/MacOS/bin/MonoDevelop",

		// Possible default directory paths for Unity:
		// Windows: C:\Program Files\Unity\Editor\Data\
		// Windows 64-bit: C:\Program Files (x86)\Unity\Editor\Data\
		// Mac OS X: /Applications/Unity/Unity.app/Contents/Frameworks/

		"completesharp_assemblies": [
			"<path-to-Unity-folder>\\Managed\\UnityEngine.dll",
			"<path-to-Unity-folder>\\Managed\\UnityEditor.dll",
			"<path-to-Unity-folder>\\Mono\\lib\\mono\\unity\\UnityScript.dll",
			"<path-to-Unity-folder>\\Mono\\lib\\mono\\unity\\System.Core.dll",
			"<path-to-Unity-folder>\\Mono\\lib\\mono\\unity\\System.dll",
			"<path-to-Unity-folder>\\Managed\\nunit.framework.dll",
			"<path-to-Unity-folder>\\Mono\\lib\\mono\\unity\\mscorlib.dll",
			"${project_path:Library}\\ScriptAssemblies\\Assembly-CSharp.dll",
			"${project_path:Library}\\ScriptAssemblies\\Assembly-CSharp-Editor.dll",
			"${project_path:Library}\\ScriptAssemblies\\Assembly-UnityScript-Editor.dll",
			"${project_path:Library}\\ScriptAssemblies\\Assembly-CSharp-firstpass.dll"
		],
		"completioncommon_inhibit_sublime_completions": true,
		"completioncommon_shorten_names": true

		...
	}
	...
}

After saving these settings, this should automatically reload CompleteSharp's python scripts and have its autocompletion ready. To see any errors, open the console by using Ctrl+` (tilde key).

[edit] Advanced C# completions for Sublime Text 3

In ST3, you can replace all of the above completion packages (Unity Completions and CompleteSharp, etc.) with a far better tool that will give Sublime Text capabilities similar to MonoDevelop or Visual Studio—including dynamic interpretation of .cs source files for code completion (but most notably missing are the API documentation excerpts next to the autocomplete hints):

Go to the OmniSharp web page (linked above) and follow their instructions for installing it for Sublime Text. (Currently, this requires two packages available via Package Control, and other settings.)

  • The listed requirement for the Mono Development Kit does not appear to be required (perhaps because Unity is installed).

Restart ST3 for the OmniSharp local server to start running correctly.

Note that if you are using the Project feature of Sublime Text (strongly recommended), you must add the location of your Unity project .sln file to the .sublime-project file (Project > Edit Project):

{
	"folders":
	[
		{
			"follow_symlinks": true,
			"path": "Assets/Scripts",
			"file_exclude_patterns":
			[
				"*.dll",
				"*.meta"
			]
		}
	],
	"solution_file": "./My Awesome Game.sln",
}

OmniSharp adds several commands to the context menu in Sublime Text. Note, however, that when clicking through a bunch of these commands in a row, the OmniSharp server can stop functioning (as of v1.9.6). Thus, be careful and on the lookout for things that may stop the server. Restarting ST3 should restart the server.

[edit] Other packages of interest

[edit] Community Support

See "Using Unity with Sublime Text" forum thread

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox