ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

Send​Code

by randy3k ST3

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

Details

Installs

  • Total 9K
  • Win 3K
  • OS X 4K
  • Linux 2K
Oct 23 Oct 22 Oct 21 Oct 20 Oct 19 Oct 18 Oct 17 Oct 16 Oct 15 Oct 14 Oct 13 Oct 12 Oct 11 Oct 10 Oct 9 Oct 8 Oct 7 Oct 6 Oct 5 Oct 4 Oct 3 Oct 2 Oct 1 Sep 30 Sep 29 Sep 28 Sep 27 Sep 26 Sep 25 Sep 24 Sep 23 Sep 22 Sep 21 Sep 20 Sep 19 Sep 18 Sep 17 Sep 16 Sep 15 Sep 14 Sep 13 Sep 12 Sep 11 Sep 10 Sep 9 Sep 8
Windows 5 5 5 7 17 8 11 6 2 8 9 8 3 3 6 2 0 6 8 8 8 6 3 8 9 13 4 7 4 3 6 5 8 8 9 10 7 9 15 6 6 5 3 5 10 9
OS X 1 4 3 8 7 12 6 8 2 6 9 5 10 15 8 3 4 8 1 10 9 4 7 5 4 8 13 11 4 6 7 10 9 7 10 12 7 7 15 19 10 11 6 1 2 7
Linux 3 1 1 6 5 5 4 3 0 4 2 7 1 2 5 2 0 1 1 6 0 0 2 2 2 1 1 3 3 2 3 6 10 10 3 7 3 6 6 2 3 3 8 0 1 0

Readme

Source
raw.​githubusercontent.​com

SendCode for Sublime Text


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

Following Programs are supported

  • Mac: Terminal, iTerm (>=2.9), R GUI, RStudio Desktop, RStudio and Jupyter running on Chrome and Safari
  • Windows: Cmder, ConEmu, R GUI, RStudio Desktop
  • Linux: Tmux, Screen, Gnome-Terminal, Pantheon-Terminal, Mate-Terminal, Konsole, RStudio Desktop
  • Others: TerminalView, SublimeREPL (deprecating)

Installation

You could install SendCode via Package Control. If you are using Linux, the respective platform dependency xdotool will also be installed automatically.

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:

  • cmd+enter (Mac) or ctrl+enter (Windows/Linux)

    If text is selected, it sends the text to the program selected. If no text is selected, then it sends the current block (if found). Finally, it moves the cursor to the next line.

  • cmd+b (Mac) or ctrl+b (Windows/Linux): source current file (R, Julia and Python (IPython) only)

    SendCode uses Sublime build system to source files, you might have to choose the Source File option in a pop up window.

Troubleshooting

  1. Python console

IPython (5.0 or above, or any repls which support bracketed paste mode) are assumed to be used. IPython 4.0 is still supported, but users need to disable bracketed_paste_mode in the settings.

  1. RStudio on Windows

If the code is pasted on the console but it is not being executed, you need to open an empty RScript file from the menu File -> New File -> R Script. This is a quick fix to a RStudio issue on Windows.

Alternatively, you could upgrade to RStudio preview in which this bug has been fixed.

  1. R Gui on Windows

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

  1. 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.

  1. 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:

  • $file, the full path to the file
  • $file_path, the directory contains the file
  • $file_name, the file name
  • $file_basename, the file name without extension
  • $file_extension, the file extension
  • $folder, the first folder of current window
  • $project_path, the directory where sublime-project is stored
  • $current_folder, the folder of the window which contains the current view
  • $selection, the text selected, or the word under cursor
  • $line, the current line number

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

Block expansion

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

  • Expand current line to match (), [] and {}.
  • R: multiline code seperated by operators and knitr-spin #+ decorators.
  • Julia: begin, end pairs with indentations.
  • Python: indentations or # %%/# In[] decorators.
  • Markdown fenced code blocks of Markdown Extended and R Markdown: put the cursor at the line of ``` to send the whole block.