Как в Sublime Text 3 запускать код Python-a? — Хабр Q&A

[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)

  1. Go to Menu > Preferences > Browser Packages.
  2. Open the user directory.
  3. Create a new file cmdRunFromDIR.sublime-build and open in Sublime Text.
  4. 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 & after START 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 an ERROR 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.
    
  5. For the keyboard shortcut go to Menu > Preferences > Key Bindings and paste the following code. This shortcut is CTRL C,D.

        { "keys": ["alt c,alt d"], "command": "build", "args": { "file": "{packages}/User/cmdRunFromDIR.sublime-build" } }
    
  6. Add , at the end of this line if it’s not the last line in that file.

  7. There’s no requirement to restart Sublime Text.

  8. You also access this via Menu > Tools > Build System > cmdRunFromDIR.
    Once this is done CTRL B will run the command also.

:/>  Включение и отключение компонентов Windows 10: где находится и как включать

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

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 new cmd.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:

Как в 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 все должно работать.

:/>  Изучаем структуры MBR и GPT / Хабр

Оставьте комментарий