T
T
th3mis2016-06-08 12:09:50
Sublime Text
th3mis, 2016-06-08 12:09:50

Sublime Text 3, auto select Build System?

Sublime has an automatic build system selection, but it only works for pre-installed Build Systems.
I have two of my own Build Systems, but they do not automatically switch for files, and I cannot edit the standard ones, because can't find configuration files.
How to comfortably run python code in one tab and C++ code in another tab? Without manually switching Build System every time.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sasha Chernykh, 2016-07-16
@th3mis

You can set hotkeys for those builds (hereinafter also "builds", etc.) that you use.
When it was already necessary to enter hotkeys into this file with JSON syntax, [square brackets] should be placed only at the beginning and end, but not between commands separated by commas. File example:

[
// Clickable URL — открыть URL, на которую наведён курсор
    { "keys": ["alt+enter"], "command": "open_url_under_cursor" },
// Открыть PowerShell
    { "keys": ["ctrl+7, ctrl+t"], "command": "open_terminal" },
// Наш Build
    { "keys": ["ctrl+alt+b"], "command": "build", "args": {"build_system": "Packages/User/SashaIsMyIdol.sublime-build", "variant": "" }
]

keys — an arbitrary but unoccupied shortcut,
build_system— the path to your build file with the extension .sublime-build, starting from the folder Packages.
We press hotkeys - in the example it is Ctrl+Alt+B, → build should start.
The principle is the same: set hotkeys in the Key Bindings - User. We also need to find out where the build files are located.
Suppose we are working with Ruby. Ctrl+Shift+PPackageResourceViewer: Open Resource(thanks to fuzzy-search it is enough to enter prv) → RubyRuby.sublime-build. In the title of the page, we look at the path to the build file, and enter it:
Similarly, we find the paths to builds for other programming languages: for Python, this is Packages/Python/Python.sublime-build, plus Packages/C++/C++ Single File.sublime-build.
Didn't work for me at first due to a typo by the author of Sublime Text Power User.
We make it so that when we have open files for Python, for example, with the .py extension , Build Python would be launched, files for C ++, for example, with the .ex extension , respectively, for C ++. In your build file with the .sublime-build extension, you need to add the selector parameter, the value of which will be the part of the so-called common for your markup / programming language or programming tool. "scope" (scope). How to get scopes is described in detail here . We only need what's up to the first space; suppose if we got
source.python meta.function.python entity.name.function.python
, it will be necessary to substitute only source.python. Python build example:
{
    "cmd": ["python", "-u", "$file"],
    "file_regex": "^[ ]*File

quot;(...*?)

quot;, line ([0-9]*)",
    "selector": "source.python"
}

For C++:
{
      "cmd": ["g++", "$file", "-o", "$file_base_name", "-I/usr/local/include"],
      "selector": "source.c++",
      "windows": {
         "cmd": ["cl", "/Fo${file_path}", "/O2", "$file"]
      }
  }

Thank you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question