[how to run code by using cmd from sublime text 3 ]
Sublime text default build system for python is “Python”, which uses the “python” alias.
So if you’d like to use python3 for instance, you have to create a new build system.
Go to Tools > Build system > New build system…
There you have a command to specify, use the binary you’d like to be used by sublimeText, like so :
{
"cmd": ["python3.7", "-u", "$file"]
}
Save the file to python[X].sublime-build
, [X] being the version you’d like to use.
Now in your source file, specify the build system to that version of python.
To test that sublime text is using the interpreter you chose, you can use this code :
import sys
print(sys.version_info)
Check this for more informations : https://www.sublimetext.com/docs/3/build_systems.html
Sublime text 2 – open cmd prompt at current or project directory (windows)
- Go to
Menu
>Preferences
>Browser Packages
. - Open the
user
directory. - Create a new file
cmdRunFromDIR.sublime-build
and open in Sublime Text. Paste the following…
{ "cmd": ["C:\\Windows\System32\cmd.exe", "/C START &"], "working_dir": "$file_path" }
The above will open the current folder but if you want the project directory then there’s a whole host of different methods here.
Note: That the&
afterSTART
will then pass on the$file_path variable
which can be changed to any of those below. I couldn’t see any documentation for this. It was just trial and error on my behalf and makes sense if you think about it. So, if you try to pass"cmd": ["C:\\Windows\System32\cmd.exe", "/C START & $file_path"]
to will get anERROR
if the path has any whitespaces in it.$file_path The directory of the current file, e.g., C:Files. $file The full path to the current file, e.g., C:FilesChapter1.txt. $file_name The name portion of the current file, e.g., Chapter1.txt. $file_extension The extension portion of the current file, e.g., txt. $file_base_name The name-only portion of the current file, e.g., Document. $folder The path to the first folder opened in the current project. $project The full path to the current project file. $project_path The directory of the current project file. $project_name The name portion of the current project file. $project_extension The extension portion of the current project file. $project_base_name The name-only portion of the current project file. $packages The full path to the Packages folder.
For the keyboard shortcut go to
Menu
>Preferences
>Key Bindings
and paste the following code. This shortcut isCTRL C
,D
.{ "keys": ["alt c,alt d"], "command": "build", "args": { "file": "{packages}/User/cmdRunFromDIR.sublime-build" } }
Add
,
at the end of this line if it’s not the last line in that file.There’s no requirement to restart Sublime Text.
You also access this via
Menu
>Tools
>Build System
>cmdRunFromDIR
.
Once this is doneCTRL B
will run the command also.
Useful links:See 1st link below for how to run .bat
files directly from Sublime Text. Very little modification of the code above.
Build System – Sublime Text 3
In Sublime Text 3, how to have shortcuts for “Build and Run” and “Build only” separately like it was in Sublime Text 2
How to Add a Shortcut for Any Command in Sublime Text
Build Systems – Configuration
Sublime text 3. открытие скомпилированного .exe файла в windows cmd?
Суть: Уже настроил ST3 под C , уже умеет компилировать код и даже выводит результаты в консоли редактора. Но хочется сделать так, чтобы ST автоматически открывал скомпилированные .exe файлы в командной строке (хотя бы для того, чтобы можно было вводить пользовательские значение.
Мой файл .sublime-build:
{
"cmd": ["g ", "${file}", "-o", "${file_path}/${file_base_name}"],
"file_regex": "^(..[^:]*):([0-9] ):?([0-9] )?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.c ",
"variants":
[
{
"name": "Run",
"cmd": ["${file_path}/${file_base_name}.exe"]
}
]
}
Windows cmd terminal setting for sublime text 3! · issue #147 · wbond/sublime_terminal
Как в sublime text 3 запускать код python-a?
Есть много вариантов, первый это ctrl b, но он не поддерживает ввод. Поетому советую использовать SublimeRELP, установить его не так сложно, просто воспользуйтесь Package Control -> Install Package -> SublimeRELP. Теперь ви можете Tools -> SublimeRELP -> Python -> Run Current file. Но это поддерживает только Python2.7 и пользоваться не удобно. Для того что бы исправить это все открываем Preferences -> Key Bindings -> User и добавляем такое:
{ "keys": ["ctrl b"], "command": "repl_open",
"caption": "Python - RUN current file",
"id": "repl_python_run",
"mnemonic": "d",
"args": {
"type": "subprocess",
"encoding": "utf8",
"cmd": ["python3", "-u", "$file_basename"],
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"external_id": "python",
"extend_env": {"PYTHONIOENCODING": "utf-8"}
}
}
(в квадратние скобки).
Теперь при Ctrl b все должно работать.
The gist you linked to has a lot of misinformation in it. Terminal Settings should not have any key binding information in them (e.g.
keys
,command
) as those aren’t respected — that should be done for any key bindings. To set a default title for all newcmd.exe
, the settings would look like:General settings reference: https://msconfig.ru/wbond/sublime_terminal/tree/1.14.0#package-settings
Key binding reference: https://msconfig.ru/wbond/sublime_terminal/tree/1.14.0#custom-parameters
For setting it as a key binding only, that would look like: