Skip to content

Instantly share code, notes, and snippets.

@lf-araujo
Last active May 27, 2019 13:12
Show Gist options
  • Save lf-araujo/54f83fc7b851a39b8b6bd4e919216511 to your computer and use it in GitHub Desktop.
Save lf-araujo/54f83fc7b851a39b8b6bd4e919216511 to your computer and use it in GitHub Desktop.
Swift REPL with Sublime Text in Linux

Swift REPL with Sublime Text in Linux

Swift REPL works fine in Sublime Text. It is a simple three step process. First install the language either by downloading the latest version of it at swift.org and extracting it to /usr, or if you are in Arch by issuing yaourt -S swift-bin.

The second step is to add an option to Swift in Sublime Text REPL. Please note that you have to install Sulime Text REPL first. Launch the Command Palette and browse the packages. Find the SublimeREPL directory and create a config/Swift directory.

Inside this directory, create the file Default.sublime-commands with the following content:

[
    {
        "caption": "SublimeREPL: Swift",
        "command": "run_existing_window_command", "args":
        {
            "id": "repl_swift",
            "file": "config/Swift/Main.sublime-menu"
        }
    }
]

Finally, create a second file Main.sublime-menu with the contents:

[
    {
        "id": "tools",
        "children":
        [{
            "caption": "SublimeREPL",
            "mnemonic": "r",
            "id": "SublimeREPL",
            "children":
            [
                {"command": "repl_open",
                 "caption": "Swift",
                 "id": "repl_swift",
                 "args": {
                    "type": "subprocess",
                    "external_id": "swift",
                    "encoding": "utf8",
                    "cmd": {
                            "osx": ["/Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift"],
                            "linux":["swift"]},
                    "cwd": "$file_path",
                    "additional_scopes": ["swift"],
                    "syntax": "Packages/Swift/Syntaxes/Swift.tmLanguage"
                    }
                }
            ]
        }]
    }
]

And in the default keymap add this to user's preferences:

[
// Modified Sublime-REPL keybindings for an "R-friendly" set of shortcuts.
// Copy and paste this text into the Key Bindings - User (under Preferences menu).
// For more information, see http://tomschenkjr.net/2012/05/17/using-sublime-text-2-for-r/

// Executes a selection of text in REPL, latter only displays code and does not execute
{ "keys": ["ctrl+shift+enter"], "command": "repl_transfer_current", "args": {"scope": "selection"}},

// Executes the entire file (build) in REPL, latter only displays code and does not execute
{ "keys": ["ctrl + f7"], "command": "repl_transfer_current", "args": {"scope": "file"}},

// Executes line(s) of text in REPL terminal, latter only displays code and does not execute
{ "keys": ["ctrl+enter"], "command": "repl_transfer_current", "args": {"scope": "lines"}},

// Executes a block (e.g., a custom function) of text in REPL terminal, latter only displays code and does not execute
{ "keys": ["ctrl+shift+alt+enter"], "command": "repl_transfer_current", "args": {"scope": "block"}},
]

Source

@dmgl
Copy link

dmgl commented May 27, 2019

Wow, thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment