Saleem
Saleem

Reputation: 75

How to use the console in Sublime Text 3

There is Hide/Show console option in "View" menu of Sublime Text 3. I tried shell, Python and Ruby commands in it but it always returns an error.

What is this console used for?

Upvotes: 4

Views: 9705

Answers (2)

gehbiszumeis
gehbiszumeis

Reputation: 3711

The Unofficial Documentation (which I prefer to the official documentation) states in the "Basic Concepts" section:

Sublime Text exposes its internals via an Application Programming Interface (API) that programmers can interact with using the Python programming language.

It uses an internal Python interpreter which is not the one in your system's PYTHONPATH variable. So, basic Python commands should be possible for you as it is working for me. The console output is:

...
   skipping some console output before
...
plugins-loaded
>>> x = 1
>>> y = 2
>>> f = x * y
>>> print(f)
2

The purpose of the console is to interact with an API to control Sublime Text 3 internal settings:

>>> sublime.version()
'3211'

or:

>>> sublime.message_dialog("test")

which opens a clickable dialog with the text "test".

See the API reference for more information.

Upvotes: 4

OdatNurd
OdatNurd

Reputation: 22791

The console in Sublime is a window into the internal workings of Sublime in order to see the state of plugins and interact with the plugin host; the most important distinction to make is that the Sublime console IS NOT a Terminal; if you want access to arbitrary commands, you need to install a package such as Terminus to achieve that.

Most of the functionality in Sublime (including default functionality out of the box) is defined in Python plugins, and third party packages can also define Python plugins as well. The console is a window into that Python environment; if a plugin fails (like if the code is broken in some fashion), then the error that the code is generating ends up in the console.

Sublime also displays its own status into the console as well; the console contains output that indicates when plugins are being loaded and unloaded, how long it took Sublime to start up, what version you're running, etc. Any time you see an error dialog pop up, there's also a message added to the console (and in some cases errors go only to the console without being visible elsewhere).

Besides the major distinction that the console isn't a Terminal, it's also important to note that although you can enter arbitrary Python into the console and have it run, it's not meant to be your gateway to running a Python program (unless you want to evaluate single expressions and the like).

Many people fall into the trap of thinking that because Sublime uses Python for plugins that you can also use that environment to run your Python programs as well, but this is not the case. The Python environment that Sublime provides is for its own use, and is distinct from any version of Python you may or may not have installed on your computer.

Upvotes: 3

Related Questions