• Stars
    star
    204
  • Rank 192,063 (Top 4 %)
  • Language
    Python
  • License
    MIT License
  • Created over 8 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

SendCode for Sublime Text

Send code and text to macOS and Linux Terminals, iTerm, ConEmu, Cmder, Tmux, Terminus; 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
  • Sublime Plugin: Terminus

Installation

You could install SendCode via Package Control.

  • If you don't have Package Control installed, follow the installation instructions on the Package Control website.
  • In Sublime Text, type cmd+shift+p (Mac) or ctrl+shift+p (Windows/Linux) to bring up the command palette.
  • Into the command palette start typing Package Control: Install Package and select the option when in pops up.
  • In the Install Package window start typing SendCode and select the option when it pops up.
  • SendCode should then be installed.

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:

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

  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:

  • $file, the full path to the file
  • $file_path, the directory contains the file
  • $file_name, the file name
  • $file_base_name, 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. 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.

  • Expand current line to match (), [] and {}.
  • R:
    • backward expand if the previous line ends with a pipe opeartor %>%
    • # %% decorators
    • #+ spin decorators
    • #' roxygen decorators
  • Julia
    • begin, end indented pairs.
    • # %% decorators
  • Python:
    • indentations
    • # %% decorators.
  • (See the settings block_start_pattern and block_end_pattern)
  • Markdown fenced code blocks
    • put the cursor at the line of ``` to send the whole block.

More Repositories

1

radian

A 21 century R console
Python
1,976
star
2

Terminus

Bring a real terminal to Sublime Text
Python
1,382
star
3

AlignTab

An alignment plugin for Sublime Text using regular expression
Python
626
star
4

ProjectManager

Project Manager for Sublime Text
Python
323
star
5

R-Box

R package for Sublime Text 3
Python
172
star
6

collections

High-performance container datatypes for R
R
102
star
7

remote-atom

rmate for atom
CoffeeScript
85
star
8

LaTeXYZ

Better LaTeX experience with Sublime Text
Python
74
star
9

AutoWrap

Auto (Hard) Wrap for Sublime Text 2/3
Python
63
star
10

arrangements

Fast Generators and Iterators of Permutations, Combinations and Partitions
R
52
star
11

rchitect

Interoperate R with Python
Python
51
star
12

LaTeXBox

A lightweight but deprecated LaTeX Plugin for Sublime Text 3
Python
46
star
13

Whitespace

Remove Trailing Whitespace for Sublime Text
Python
41
star
14

AutomaticPackageReloader

Automatically reload submodules while developing a Sublime Text package.
Python
37
star
15

shiny-cloudrun-demo

Running Shiny app on Google Cloud Run
R
34
star
16

UnitTesting-example

A getting started example for UnitTesting
Python
32
star
17

dotfiles

some of my dotfiles
Python
30
star
18

ChangeList

DEPRECATED: The missing Change List for Sublime Text 2/3 - History List, Last Edit ...
Python
30
star
19

SyntaxManager

Applying settings to a given syntax/extension
Python
29
star
20

homebrew-r

Homebrew formulas for R and related tools
Ruby
25
star
21

UnicodeCompletion

Insert Unicode LaTeX δ and Emoji 🍻 to Sublime Text
Python
24
star
22

LaTeXTab

Excel/CSV to LaTeX Table
Python
18
star
23

SendTextPlus

SendTextPlus is deprecated in favour of https://github.com/randy3k/SendCode
Python
17
star
24

otp

One Time Password Generation and Verification
R
16
star
25

retry

Repeated Evaluation
R
15
star
26

rpy2

Deprecated: use the official mirror: https://github.com/rpy2/rpy2
Python
15
star
27

xptr

Manipulating External Pointer
R
13
star
28

GitStatusBar

A more compact Git StatusBar
Python
13
star
29

rango

Calling R from Go and a better cli for the R console (WIP, nothing is working now)
Go
12
star
30

osascript

some useful apple scripts
AppleScript
9
star
31

iterpc

iterpc: deprecated in favour of https://github.com/randy3k/arrangements
R
9
star
32

sublime-default

Sublime Text 3 Default Package - This rpeo is outdated, check https://github.com/twolfson/sublime-files
Python
9
star
33

OpenHere

Open Finder, Terminal and iTerm in Sublime Text
AppleScript
5
star
34

GitHubChecks

Show GitHub checks result in Sublime Text
Python
5
star
35

sess

R
3
star
36

closure

Tools to create and manipulate closures
R
3
star
37

LSP-julia

Julia config for Sublime Text LSP
Python
3
star
38

netlify-deploystatus

JavaScript
3
star
39

random-scripts

some random scripts
Python
2
star
40

R-Extended

Improved R syntax files for Sublime Text
JavaScript
2
star
41

Keypress

Simulate Keypress in Sublime Text
Python
2
star
42

shiny-appengine-demo

Running Shiny app on Google App Engine
R
1
star
43

lineedit

lineedit: a readline library based on prompt_toolkit which supports multiple modes
Python
1
star
44

gh-actions

Shell
1
star
45

juliatalk

Jupyter Notebook
1
star
46

workbench

Bootstrapping my workbench on unix machines
Shell
1
star
47

randylai.info

source of randylai.info
HTML
1
star
48

UnitTesting-docker

Go to https://github.com/SublimeText/UnitTesting/tree/master/docker
Shell
1
star
49

ustring

Tools For Unicode Strings
R
1
star
50

RSpace

A Cocoa GUI for R on OSX
Objective-C
1
star
51

submit

A webapp for submitting project
HTML
1
star