【问题标题】:VS Code execute current line or selection to in the integrated consoleVS Code 在集成控制台中执行当前行或选择
【发布时间】:2018-01-21 20:43:13
【问题描述】:

这位习惯于 elpy 的 Emacs 老用户正在尝试使用 Scala 以及更具体的 Ammonite repl 迁移到 VSCode。

我使用 Ctrl+' 打开集成终端 & 我所要做的就是在 bash shell (ubuntu) 上键入 amm 来打开 repl;但是,我仍然怀念能够使用 Ctrl+Enter 将编辑器中的行或选择发送到集成 shell。

我想这意味着一些编码。我可以从哪里开始?有没有人完成类似的?

非常感谢,

【问题讨论】:

  • Aluan:至少需要一些调整,但看起来很有希望。至少我应该能够将其用作样本。非常感谢,

标签: scala visual-studio-code vscode-extensions vscode-settings ammonite


【解决方案1】:

如果您已经打开了终端和 REPL,则有一个名为“在活动终端中运行选定文本”/workbench.action.terminal.runSelectedText 的内置命令。

它没有默认的键绑定,所以你需要自己设置。这样的事情会起作用:

{
  "key": "ctrl+enter",
  "command": "workbench.action.terminal.runSelectedText",
  "when": "editorTextFocus && editorHasSelection"
}

【讨论】:

  • 是的,这行得通!我想真的像 elpy 一样工作。我想我需要使用任务添加多个命令。 "when": "editorTextFocus && !editorHasSelection" "commands": "expandLineSelection" & "workbench.action.terminal.runSelectedText" & "cancelSection" 但这真的很好。谢谢
  • 我刚刚发布了对我上面添加的评论 Q 扩展的回答。
  • 令人惊讶的是它没有run current line and move cursor to next 快捷方式(就像 spyder 中的 f9)。认为它非常常用的快捷方式
【解决方案2】:

实际上,我发现添加 VSCode Macros 扩展就可以了:

我刚刚更改了 settings.json:

{
    "window.zoomLevel": 1,
    "editor.fontSize": 11,
    "terminal.integrated.fontSize": 11,
    "macros": {
        "execCurLn": [
            "expandLineSelection",
            "workbench.action.terminal.runSelectedText",
            "cancelSelection"
        ]
    }
}

并添加(第一部分是纯 @kwood 并再次感谢你)到 keybindings.json

   {
        "key": "ctrl+enter",
          "command": "workbench.action.terminal.runSelectedText",
            "when": "editorTextFocus && editorHasSelection"
    }
    {
        "key": "ctrl+enter",
          "command": "macros.execCurLn",
            "when": "editorTextFocus && !editorHasSelection"
    },
{ "key": "ctrl+`", "command": "workbench.action.terminal.focus"},
{ "key": "ctrl+`", "command": "workbench.action.focusActiveEditorGroup", "when": "terminalFocus"}

【讨论】:

  • 当鼠标焦点在一行而不是当前行时,它会导致运行下一行。选择作品。
  • 如果它是文件的最后一行,有没有办法让它在之后插入一个新行?
【解决方案3】:

使用 CTRL+SHIFT+P 打开命令面板并查找 Terminal: Run Selected Text In Active Terminal。在左侧,您将看到键绑定或用于设置绑定的轮引擎。

【讨论】:

    【解决方案4】:

    关注另一个帖子VS Code move to next line on run ctrl + enter,运行当前行然后向下光标,避免意外运行下一行

    在settings.json中,添加

    "macros": {
        "pythonExecSelectionAndCursorDown": [
            "python.execSelectionInTerminal",
            "cursorDown",
        ]
    } 
    

    在 keybindings.json 中,添加

    {
        "key": "ctrl+enter",
          "command": "macros.pythonExecSelectionAndCursorDown",
            "when": "editorTextFocus && editorLangId == 'python'"
    }, 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-25
      相关资源
      最近更新 更多