posit-dev / posit-dev/positron

"Run current line or selection" command

Open
#13,239 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

area: console area: editor enhancement support
Dominant language
TypeScript
Stars
4.3k
Forks
184
Avg merge
1d 11h
Merged PRs (30d)
206

Description

User request for a way to run the current line. This would work exactly the same as our current code execution gesture, except it would be much simpler: instead of using the statement range provider, it would advance by a single line.

This is already the fallback behavior when we don't have a statement range provider, or the provider doesn't return a range.

Discussed in https://github.com/posit-dev/positron/discussions/13226

Originally posted by adam-milton-morgan April 27, 2026
My favorite thing about RStudio is that I can send single lines to the console with one keyboard shortcut (I have it set to Cmd+Enter). I've been trying to replicate that behavior in Positron through various keybindings.json configurations, but can't quite seem to get it to work. Specifically, I want Cmd+Enter to behave like RStudio's "Run Current Line or Selection," which executes the selection if there's selected code (any number of lines), or if not, it executes just the current line, and moves the cursor to the beginning of the next line down. The closest I've come is this:

(NOTE: I didn't realize tabs wouldn't align the code properly below, so the code looks awful. Adding this a screenshot, which shows one of the keybindings I've tried (left) and the problem in console (right), where the first entry comes from hitting Cmd+Enter with the keybinding below and the second, which works the way I want, occurs when I type "if(TRUE){" directly into the console and hit "Enter".)
positron_example

[
{
"key": "cmd+enter",
"command": "workbench.action.positronConsole.executeCode",
"when": "editorTextFocus && editorLangId == 'r' && editorHasSelection"
},
{
"key": "cmd+enter",
"command": "runCommands",
"when": "editorTextFocus && editorLangId == 'r' && !editorHasSelection",
"args": {
"commands": [
"cursorHome",
"cursorEndSelect",
"workbench.action.positronConsole.executeCode",
"workbench.action.positronConsole.enter",
"cancelSelection",
"cursorDown",
"cursorHome"
]
}
}
]

The first entry executes highlighted code (if any) in console. The second is for when there's no highlighted code — this is when I want it to just send one line, not a block or the rest of the script. I couldn't find a way to directly execute the line, so I had it highlight the line by moving the cursor to the beginning of the line ("cursorHome"), selecting the rest of the line (cursorEndSelect), sending that to the console, then moving the cursor to the beginning of the next line. The problem is, the line of code appears in the console input line, but isn't executed. I have also tried the following, which is similar except that the second command leverages the executeCode command.

[ { "key": "cmd+enter", "command": "workbench.action.positronConsole.executeCode", "when": "editorTextFocus && editorLangId == 'r' && editorHasSelection" }, { "key": "cmd+enter", "command": "runCommands", "when": "editorTextFocus && editorLangId == 'r' && !editorHasSelection", "args": { "commands": [ "cursorHome", "cursorEndSelect", { "command": "workbench.action.positronConsole.executeCode", "args": { "languageId": "r", "advance": false, "allowIncomplete": true } }, "cancelSelection", "cursorDown", "cursorHome" ] } } ]

This works for a single line of code (e.g., "x = 10"), but it rejects incomplete input rather than sending it to the R console continuation prompt. For instance, if you try to run the following R code line-by-line by repeatedly pressing Cmd+Enter:

if(x){ print("hey!") }

it breaks on the first line: the console prints: "Error: Can't parse incomplete input" rather than "+" (indicating that the console is waiting for the rest of the as-yet incomplete code). The "+" is what RStudio does automatically, and, notably, what the console does when you just type

if(TRUE){

directly into the console in Positron and hit "Enter".

I would love a feature like one of these:

  • executePhysicalLine
  • sendTextToConsole
  • executeIncompleteCode

Does anyone know if something like that exists? Any other ideas? Thanks!!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the existing code-execution gesture and its statement range provider, including the fallback behavior described in the issue. Check how the executeCode command handles selections, single lines, cursor advancement, and incomplete input. Done means the new command executes a selection or current line, advances appropriately, and preserves continuation behavior for incomplete code.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
developer-experience
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
66/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.