Home

Awesome

SendCode for Sublime Text

<a href="https://packagecontrol.io/packages/SendCode"><img src="https://packagecontrol.herokuapp.com/downloads/SendCode.svg"></a> <a href="https://www.paypal.me/randy3k/5usd" title="Donate to this project using Paypal"><img src="https://img.shields.io/badge/paypal-donate-blue.svg" /></a>

Send code and text to macOS and Linux Terminals, iTerm, ConEmu, Cmder, Tmux, Terminus; R (RStudio), Julia, IPython.

Following Programs are supported

Installation

You could install SendCode via Package Control.

If you are using Linux, we might need to install xdotool to use some features. Ubuntu users can use

sudo apt-get install xdotool

If it cannot be found, you will be prompted to download a binary distribution.

Usage

Select a program using the command SendCode: Choose Program in command palette. The default program on macOS, windows and linux are Terminal, Cmder and tmux respectively. Each syntax binds to its own program. For instance, you could bind R to r files and tmux to python files.

There are two main keybindings:

Troubleshooting

  1. Python console

    IPython (5.0 or above, or any repls which support bracketed paste mode) are assumed to be used.

  2. radian console

    You might want to turn on bracketed_paste_mode if radian is used.

  3. RStudio on Windows

    Make sure RStudio v1.1.383 or above is used.

  4. R Gui on Windows

    Make sure the corresponding R program is opened when you are sending the text.

  5. Cmder/ Conemu on Windows

    You might need to set the path to ConEmuC.exe in SendCode settings. For Cmder, the file is located at <path to cmder folder>\\vendor\\conemu-maximus5\\ConEmu\\ConEmuC.exe.

  6. Safari-Jupyter on macOS

    Most likely you haven't enabled JavaScript for AppleScript. Check the option "Allow JavaScript from Apple Events" in the Develop menu (the Develope menu needs to be enabled in the preferences).

Custom Keybindings

It is fairly easy to create your own keybinds for commands which you frequently use. For example, the following keybinds execute changing working directory commands for R, Python and Julia.

[
    {
        "keys": ["ctrl+shift+h"], "command": "send_code",
        "args": {"cmd": "setwd(\"$file_path\")"},
        "context": [
            { "key": "selector", "operator": "equal", "operand": "source.r" }
        ]
    },
    {
        "keys": ["ctrl+shift+h"], "command": "send_code",
        "args": {"cmd": "%cd \"$file_path\""},
        "context": [
            { "key": "selector", "operator": "equal", "operand": "source.python" }
        ]
    },
    {
        "keys": ["ctrl+shift+h"], "command": "send_code",
        "args": {"cmd": "cd(\"$file_path\")"},
        "context": [
            { "key": "selector", "operator": "equal", "operand": "source.julia" }
        ]
    }
]

SendCode expands following variables in the cmd field:

It also supports placeholders for variables, details can be found in the unofficial documentation.

${file_path:$folder}

This will emit the directory of current file if there is one, otherwise the first folder of the current window.

You also don't have to worry about escaping quotes and backslashes between quotes, SendCode will handle them for you.

The prog argument determines which program to use

[
    {
        "keys": ["ctrl+shift+enter"], "command": "send_code",
        "args": {"cmd": "\n", "prog": "tmux"}
    }
]

User settings

A couple of settings can be found Preferences: SendCode Settings. Project-wise settings could also be specified in sublime-project as

{
    "settings": {
        "SendCode": {
            "prog": "terminus",
            "r" : {
                "bracketed_paste_mode": true
            }
        }
    }
}

Block expansion

SendCode uses the following logics to expand cursor when sending code.