How to pass a line to the console in sublime text 2 editor

后端 未结 3 1386
南旧
南旧 2021-02-04 08:46

I use RStudio for working with R programming language and find the ctrl+enter shortcut to send a line to the console extremely useful in troubleshooting my work.

相关标签:
3条回答
  • 2021-02-04 08:59

    Sending raw R code to SublimeREPL does work now:

    1. Bring up the Cmd/Ctrl+Shift+P menu
    2. Select R Application Switch
    3. Select SublimeREPL

    When you have SublimeREPL active, you'll be able to send raw R to it with Cmd/Ctrl+Enter.

    Note that by default, SublimeREPL won't display the code that gets sent in; it'll just show you the output. If you want to also see the code, you can change your user settings:

    1. Navigate to Preferences -> Package settings -> SublimeREPL -> Settings - User
    2. Turn on the show_transferred_text setting.

    For example, if you don't have any other settings, your settings should look like this:

    {
        "show_transferred_text": true
    }
    
    0 讨论(0)
  • 2021-02-04 09:00

    I don't know about the console, but this is possible with SublimeREPL.

    As long as you have a REPL and a file of the same language open at the same time, you can send a line (or a selection or file) to your open REPL via the SublimeREPL Source Buffer Keys. By default, Ctrl+, followed by l sends the current line to the REPL, but you can change the hotkey to Ctrl+Enter (in Python only, to protect other languages' default Ctrl+Enter functionality) by adding these lines to the top of your Preferences -> Key Bindings – User file:

    { "keys": ["ctrl+enter"], "command": "repl_transfer_current", "args": {"scope": "lines"}, "context":
        [
            { "key": "selector", "operator": "equal", "operand": "source.python", "match_all": true }
        ]
    },
    

    Other available scopes (from Preferences -> Browse Packages -> SublimeREPL/Default (Windows).sublime-keymap) are selection, file, and block (Clojure only). If you want to send a line to your REPL but not parse it immediately, you can add "action":"view_write" to the args object, like so:

    { "keys": ["ctrl+enter"], "command": "repl_transfer_current", "args": {"scope": "lines", "action": "view_write"}, "context":
        [
            { "key": "selector", "operator": "equal", "operand": "source.python", "match_all": true }
        ]
    },
    

    See the Unofficial Sublime Text 2 Docs for more information on key bindings.

    In the case that the REPL is open in a different tab than your source (rather than a separate view), the source buffer hotkeys will not focus the REPL. I'm sure it's possible to implement some sort of tab-swapping toggle key, but that sounds like a problem for another question.

    0 讨论(0)
  • 2021-02-04 09:02

    In addition to setting up your own key bindings, you can simply install Enhanced-R:

    In Sublime:

    • Cmd + Shift + P (to bring up the command palette)
    • type "Install Package"
    • Navigate to Enhanced-R

    If you are using Sublime for mostly just R, then you can set the default syntax for the whole app. Or you can change it per file (Cmd + Shift + P again, then start typing Syntax Enhanced R)

    Then, like you are used to in RStudio, you simply hit Cmd + enter to ship the code to the Console or R.app etc

    0 讨论(0)
提交回复
热议问题