Menu
- Sublime Text Commands
- Run Command On Sublime Text For Macos
- Sublime Run Command
- Run Command On Sublime Text For Macro Multiple Times
- Mac Sublime Text
- Install Sublime Text Mac
- Download Sublime Text For Mac
Active1 year, 7 months ago
Text below is a gist fork of gist by Artero with basic adjustments to use Sublime Text 3 from Command Line in OSX. A fork I have adjusted and updated some more in this blog post. It explains how you can get Sublime 3 to work from the command line.
I want to set up a complete Python IDE in Sublime Text 2.
I want to know how to run the Python code from within the editor. Is it done using build system? How do I do it ?
neoneo1,57433 gold badges1111 silver badges55 bronze badges
15 Answers
Tools -> Build System -> (choose) Python then:
To Run:
This would start your file in the console which should be at the bottom of the editor.
To Stop:
You can find out where your
Break
key is here: http://en.wikipedia.org/wiki/Break_key. Note:
CTRL + C
will NOT work.What to do when
Ctrl + Break
does not work:Go to:
Preferences -> Key Bindings - User
and paste the line below:
Now, you can use
ctrl+shift+c
instead of CTRL+BREAK
Community♦
matiitmatiit6,14855 gold badges3232 silver badges6060 bronze badges
On Mac OS X, save your file with a .py extension. Press ⌘ + B. It runs in a window below.
bobobobobobobobo37.1k4747 gold badges217217 silver badges308308 bronze badges
Edit %APPDATA%Sublime Text 2PythonPython.sublime-build
Change content to:
change the 'c:python27' part to any version of python you have in your system.
ppyppy
To RUN press CtrlB (answer by matiit)
But when CtrlBdoes not work, Sublime Text probably can't find the Python Interpreter. When trying to run your program, see the log and find the reference to Python in path.
The point is that it tries to run python via command line, the cmd looks like:
If you can't run python from cmd, Sublime Text can't too.
(Try it yourself in cmd, type python in it and run it, python commandline should appear)
(Try it yourself in cmd, type python in it and run it, python commandline should appear)
You can either change the Sublime Text build formula or the System
%PATH%
. - To set your
%PATH%
:
*You will need to restart your editor to load new%PATH%
- Run Command Line* and enter this command: *needs to be run as administrator
SETX /M PATH '%PATH%;<python_folder>'
for example:SETX /M PATH '%PATH%;C:Python27;C:Python27Scripts'
- OR manually: (preferable)
Add;C:Python27;C:Python27Scripts
at the end of the string.
- To set the interpreter's path without messing with System
%PATH%
see this answer by ppy.
Community♦
QwertyQwerty11.4k88 gold badges6363 silver badges8383 bronze badges
You can use SublimeREPL (you need to have Package Control installed first).
MattDMo79.6k1717 gold badges180180 silver badges191191 bronze badges
invisinvis47811 gold badge88 silver badges2424 bronze badges
If using python 3.x you need to edit the
Python3.sublime-build
(Preferences > Browse packages > Python 3)
to look like this:
Daniel Romero![Run Run](/uploads/1/2/6/0/126081909/780100722.png)
1,12011 gold badge1616 silver badges3030 bronze badges
[ This applies to ST3 (Win), not sure about ST2 ]
To have the output visible in Sublime as another file (+ one for errors), do this:
- Create a new build system:
Tools > Build Systems > New Build System...
- Use the following configuration:
- For your Python file select the above build system configuration file:
Tools > Build Systems > {your_new_build_system_filename}
- ctrl + b
- Now, next to your file, e.g.
'file.py'
you'll have'file.__STDOUT__.py'
and'file.__STDERR__.py'
(for errors, if any) - If you split your window into 3 columns, or a grid, you'll see the result immediately, without a need to switch panels / windows
1,03833 gold badges1313 silver badges2424 bronze badges
Cool U guys, I just found this:
It explains (like one of the answers above) how to edit this exec.py in the default directory.
I had the problem that my PYTHON UI APPLICATION would not start. I commented out the last line from the following snipped:
and, taaadaaaa, I could start my app by pressing Ctrl+B. Funny line anyways, uh? And a big thank you to whoever wrote that article ;-)
anhoppeanhoppe2,22233 gold badges3434 silver badges4545 bronze badges
In python v3.x you should go to :
Tools->Build System->New Build System
.Then, it pop up the untitled.sublime-build window in sublime text editor.Enter setting as:
To see the path,
Type following in terminal as
:You can make more than one Build System but it should default save inside Packages of Sublime text with .sublime-build extension.
Then, select the new Build System and press
cltr+b
or other based on your os. susan097susan097
You can access the Python console via “View/Show console” or Ctrl+`.
the Tin Man139k2727 gold badges181181 silver badges261261 bronze badges
pokepoke233k5151 gold badges362362 silver badges428428 bronze badges
I solved this problem :
Open the
exec.py
file, near line 41-42, the code should look like this :Sublime Text Commands
then delete it or edit it as :
Qwerty11.4k88 gold badges6363 silver badges8383 bronze badges
RheaRhea
I ran into the same problem today. And here is how I managed to run python code in Sublime Text 3:
- Press Ctrl + B (for Mac, ⌘ + B) to start build system. It should execute the file now.
- Follow this answer to understand how to customise build system.
What you need to do next is replace the content in
Python.sublime-build
to You can of course further customise it to something that works for you.
Community♦
Huang ChaoHuang Chao
I had the same problem. You probably haven't saved the file yet. Make sure to save your code with .py extension and it should work.
OnatOnat38411 gold badge55 silver badges1616 bronze badges
One thing to note about the aforementioned build system: you can write (and use) custom
.sublime-build
files or even per project build_systems
clause (in your project settings). This allows you to do useful things like a fancy test runner with ANSI colors output.For even more 'full IDE' features, you can use the excellent SublimePythonIDE package:
- code completion (intel)
- jump to definition & object description
- proper linting/pep8
- supports different interpreters with virtualenv
Disclosure: I've contributed a PR to that package, and I use it all the time, but thereareothers.
Community♦
tutuDajujututuDajuju6,95533 gold badges4848 silver badges7272 bronze badges
Run Command On Sublime Text For Macos
Use a real python console alongside Sublime
Both Sublime's build system and SublimeREPL (the answers above) are limited in that you can't easily interact with the workspace variables after you run your file.
If you want to run a script, then work in a REPL-like fashion (like you would in an IDE), then I recommend having Sublime open alongside an IPython console. Using AutoHotKey (Windows) or AutoKey (Linux), you can set this up such that a single shortcut will copy the filename (or just the selected code) and then paste this in the console to run the file.
Detailed instructions for Linux or Windows
hugke729hugke729
protected by MattDMoNov 17 '15 at 23:37
Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
Would you like to answer one of these unanswered questions instead?
Not the answer you're looking for? Browse other questions tagged pythonidesublimetext2sublimetext or ask your own question.
Commands are the basic method for interacting with Sublime Text. Key bindings, menu items, toolbar buttons and macros all work through the command system. If you are editing one of those files, this reference will come in handy.
Each command may take one or more parameters, which may be enclosed in quotes. For example, the command to insert the string Hello World!, followed by a newline, is:
insertCharacters 'Hello World!n'
Selection
move | move mode amount [extend]
| ||||||
moveTo | moveTo position
| ||||||
expandSelectionTo | expandSelectionTo feature
| ||||||
expandSelectionToParagraph | Expands each selection region to the enclosing paragraph | ||||||
selectAll | Selects the entire buffer | ||||||
invertSelection | Selects the non-selected portion of the buffer, and unselects the currently selected portion | ||||||
singleSelection | Remove all selection regions bar the first | ||||||
splitSelection | Replace each non-empty selection region with two empty regions, one for each end | ||||||
splitSelectionIntoLines | Split each selection region into subsets, one for each line |
Editing
insertCharacters | Insert the characters given in the first parameter | ||||||
insertAndDecodeCharacters | Insert the characters given in the first parameter, and apply automatic indentation | ||||||
leftDeleteCharacters | Erase the contents of each non-empty region, and the character to the left of every empty region. If spaces are being used for indentation, this will erase space characters until the next tab stop | ||||||
leftDeleteCharactersSingle | Erase the contents of each non-empty region, and the character to the left of every empty region. This has no special behavior when translateTabsToSpaces is on | ||||||
rightDeleteCharacters | Erase the contents of each non-empty region, and the character to the right of every empty region | ||||||
deleteWord | deleteWord direction
| ||||||
copy | Copies the current selection to the clipboard | ||||||
cut | Cuts the current selection to the clipboard | ||||||
paste | Replaces the current selection with the contents of the clipboard | ||||||
undo | Undoes the last action | ||||||
redo | Redoes the last action | ||||||
repeat | Repeats the last action | ||||||
redoOrRepeat | Redoes the last action if the redo stack isn't empty, otherwise repeats the last action | ||||||
join | Joins the following line to the current line, replacing all in between whitespace with a single space | ||||||
indent | Indents the lines currently intersecting the selection | ||||||
unindent | Unindents the lines currently intersecting the selection | ||||||
scroll | scroll amount
| ||||||
displayName | Show the syntax name of the text under the cursor in the status bar | ||||||
autoComplete | Complete the current word based on other words in the buffer | ||||||
toggleComment | Adds or removes comments around each selection region. If 'block' is supplied as a parameter, block comments will be preferred | ||||||
swapCase | Inverts the case of each selected character | ||||||
upperCase | Makes each selected character upper case | ||||||
lowerCase | Makes each selected character lower case | ||||||
wrapLines | wrapLines [column]
| ||||||
sortLines | sortLines [caseSensitive] [reverse] [removeDuplicates]
| ||||||
sortSelection | sortSelection [caseSensitive] [reverse] [removeDuplicates]
| ||||||
permuteLines | permuteLines method
| ||||||
permuteSelection | permuteSelection method
| ||||||
swapLines | swapLines direction
|
Find
findNext | Finds the next occurrence of the text in the find buffer |
findPrev | Finds the previous occurrence of the text in the find buffer |
findUnder | Places the current selection (or word if the selection is empty) in the find buffer, and finds the next occurrence |
findUnderPrev | Places the current selection (or word if the selection is empty) in the find buffer, and finds the previous occurrence |
findAllUnder | Places the current selection (or word if the selection is empty) in the find buffer, and finds all occurrences |
incrementalFind | Open the incremental find panel, and set the find direction to forward |
reverseIncrementalFind | Open the incremental find panel, and set the find direction to reverse |
Bookmarks
toggleBookmark | Adds / Removes the current selection to the set of bookmarks | ||
nextBookmark | Select the next bookmark | ||
prevBookmark | Select the previous bookmark | ||
allBookmarks | Selects all bookmarks | ||
clearBookmarks | Remove all bookmarks | ||
gotoBookmark | gotoBookmark n
|
Spelling
nextMisspelledWord | Selects the next misspelled word |
prevMisspelledWord | Selects the previous misspelled word |
Sublime Run Command
Macros
startRecord | Starts recording a macro | ||
stopRecord | Stops recording the current macro | ||
toggleRecord | Starts / Stops recording the current macro | ||
runMacro | Runs the last recorded macro | ||
saveMacro | Saves the last recorded macro to disk, prompting the user for a file name | ||
runMacroFile | runMacroFile filename
| ||
runMacroFileSilently | runMacroFileSilently filename
|
View and Window Management
new | Creates a new buffer | ||
open | Opens the file(s) given as parameters, or prompts the user for a file name if none are given | ||
openInCurrentTab | Opens the file(s) given as parameters, or prompts the user for a file name if none are given. The view in the current tab is first closed, and replaced with the newly opened vie | ||
openWithEncoding | openWithEncoding encoding [filename]
| ||
switchFile | switchFile extensions
| ||
clone | Creates a new view into the current buffer | ||
close | Closes the current view | ||
closeAll | Closes all views | ||
save | Saves the current buffer, prompting for a file name if it doesn't have one yet | ||
saveAll | Saves all buffers, prompting for a file name for any that don't yet have one | ||
saveAs | saveAs [encoding]
| ||
nextView | Selects the next tab | ||
prevView | Selects the previous tab | ||
copyPath | Copies the file name of the current buffer to the clipboard | ||
newWindow | Opens a new window | ||
closeWindow | Closes the current window | ||
exit | Closes all windows | ||
toggleFullScreen | Toggle the current window between full screen and windowed mode | ||
moveToGroup | moveToGroup group
| ||
focusGroup | focusGroup group
| ||
focusView | focusView view
| ||
layoutSingle | Sets the layout to a single group | ||
layoutDoubleHoriz | Sets the layout to two groups, one above the other | ||
layoutDoubleVert | Sets the layout to two groups, side by side | ||
layoutTriple | Sets the layout to three groups | ||
layoutTripleVert | Sets the layout to three groups, side by side | ||
layoutQuad | Sets the layout to four groups, in a grid | ||
layoutQuadVert | Sets the layout to four groups, side by side |
Projects
Run Command On Sublime Text For Macro Multiple Times
newProject | Creates a new project |
openProject | Open the project given as a parameter, or displays an open dialog if none are given |
closeProject | Closes the current project |
editProject | Opens the project as a file for editing. The project will be reloaded after save. |
scanProject | Reloads the project, to pick up new files that should be included |
openFileInProject | Shows a quick panel to select a file in the project |
Building
build | Builds using the current build system, which may be set globally or per-project. Build systems are defined by .sublime-build files. The format of these is simply to have two lines, one keyed on 'build' and the other 'lineNumberRegex'. These are then used to form an exec command, detailed below. | ||||||||||||||
terminate | Cancels any currently executing process in the output panel | ||||||||||||||
nextBuildError | Goes to the source of the next build error | ||||||||||||||
prevBuildError | Goes to the source of the previous build error | ||||||||||||||
exec | exec lineNumberRegex command
|
Mac Sublime Text
Snippets
insertSnippet | Inserts the snippet given as a parameter into the buffer |
insertInlineSnippet | As above, but the contents of the snippet are given as a parameter to the command, rather than the name of a .sublime-snippet file |
newSnippet | Creates a new snippet, pre-filled out with the basic structure |
nextField | Navigates to the next field (tabstop) in the snippet |
prevField | Navigates to the previous field in the snippet |
clearFields | Exits out of snippet mode |
Install Sublime Text Mac
Other
showPanel | showPanel panel
| ||
hidePanel | Hide the currently displayed panel | ||
openInBrowser | Opens a web browser displaying the current file | ||
terminate | Terminates the process currently running in the output window, if any | ||
browseUrl | browseUrl url
| ||
browseDir | browseDir path
| ||
sendEmail | sendEmail email
| ||
wordCount | Shows a status message with the number of words in the buffer | ||
rot13 | Applies a rot13 transformation to the selected text |
Not Yet Documented
Download Sublime Text For Mac
newPlugin |
set |
setApp |
setUser |
toggle |
setFileType |
setLineEnding |
markSelection |
prevInSelectionHistory |
nextInSelectionHistory |
clearSelectionHistory |
mergeSelection |
conflateSelection |
times |
sequence |