【问题标题】:Need VSCode sendSequence keybindings for previous command, next command, move to start of line, move to end of line terminal commands需要 VSCode sendSequence 键绑定上一个命令,下一个命令,移动到行首,移动到行尾终端命令
【发布时间】:2020-08-27 18:04:19
【问题描述】:

我当前的自定义键绑定

    {
        "key": "alt+b",
        "command": "workbench.action.terminal.sendSequence",
        "when": "terminalFocus",
        "args": {
            "text": "\u0017"
        }
    },
    {
        "key": "alt+j",
        "command": "workbench.action.terminal.sendSequence",
        "args": { "text": "\u001bb" }
      },
      {
        "key": "alt+l",
        "command": "workbench.action.terminal.sendSequence",
        "args": { "text": "\u001bf" }
      },
    {
        "key": "alt+n",
        "command": "workbench.action.terminal.sendSequence",
        "when": "terminalFocus",
        "args": {
            "text": "\u001bd"
        }

这些适用于 1.45 更新(集成终端更新)

Reference - 但我需要更多信息

我想使用 'ijkl' 键,如 'wasd' 游戏标准,如我的自定义项目 intuiter

所以我的想法是

  • 我们能否将序列发送到终端以显示上一个命令/下一个命令(就像我们单击向上/向下箭头时)

  • moveToLineStart/moveToLineEnd 序列在此次更新中被移除(抱歉我找不到或无法制作序列)我们可以通过sendSequence获得这个效果吗?

【问题讨论】:

    标签: visual-studio-code terminal


    【解决方案1】:

    “我们可以sendSequence 到终端以显示上一个命令/下一个命令(就像我们单击向上/向下箭头时一样)”

      {
        "key": "alt+x",    // or whatever you choose
        "command": "workbench.action.terminal.sendSequence",
        "args": {
          "text": "\u001b[A\n"
      }
    
    //  1 up arrow or previous command, works in cmd, git bash and powershell
    //  the \n at the end makes it execute the previous command immediately, 
    //  leave it off if you don't want to do that
    //  \u000d, a carriage return, is equivalent to \n if you prefer to use that, so
    //  \u001b[A\u000d does the same thing as \u001b[A\n
    
    >    /** Carriage Return (Caret = ^M, C = \r) */   
    >      export const CR  = '\x0d';
    
    
    
    
      {
        "key": "alt+y",    // or whatever you choose
        "command": "workbench.action.terminal.sendSequence",
        "args": {
          "text": "\u001b[B\n"
      }  
    
    //  1 down arrow
    //  see comment above about immediate command execution
    

    有关这些箭头命令,请参阅https://invisible-island.net/xterm/ctlseqs/ctlseqs.html

    使用 CSI 的函数,按最终字符排序

    CSI Ps A光标向上 Ps 次(默认 = 1)(CUU)。

    CSI Ps B 光标向下 Ps 时间(默认 = 1)(CUD)。

    这部分\u001b[是文档中提到的转义序列或CSI。紧随其后的是A 向上箭头(向上箭头)所以\u001b[A 或跟随转义序列B 向下箭头,所以\u001b[B

    [理论上,您应该可以同时使用 2 个(上面提到的Ps 部分)向上箭头,但这似乎在 vscode 中对我在 vscode 中不起作用。]


    {
        "key": "ctrl+e",
        "command": "workbench.action.terminal.sendSequence",
        "args": { "text": "\u0005" },   // move cursor to end of line, bash at least
        "when": "terminalFocus"
      },
    
      {
        "key": "ctrl+a",
        "command": "workbench.action.terminal.sendSequence",
        "args": { "text": "\u0001" },   // move cursor to start of line, bash at least
        "when": "terminalFocus"
      },
    

    我使用通常的键绑定 - 至少在 bash 中 - 用于转到命令行的开头或结尾。参见,例如,http://teohm.com/blog/shortcuts-to-move-faster-in-bash-command-line/

    来自这个文档https://github.com/xtermjs/xterm.js/blob/0e45909c7e79c83452493d2cd46d99c0a0bb585f/src/common/data/EscapeSequences.ts

    我们看到 Ctrl+A 是:

    /** 标题开始(插入符号 = ^A)*/ [即 Ctrl+A] 导出常量 SOH = '\x01';

    所以我使用\u0001 unicode 序列来替换列出的\x01,它不适用于sendSequence 命令。

    同样,发送 Ctrl+E 到终端以转到命令行末尾,我们看到 Ctrl +E 是:

    /** 查询 (Caret = ^E) */ [即 Ctrl+E] 导出常量 ENQ = '\x05';

    或 unicode \u0005.

    现在,您的终端 shell 可能会使用 Ctrl+ACtrl+E 以外的其他内容来执行 go开始/结束命令行。如果我的键绑定对您不起作用,请找出您的 shell 用于 go to start/end 的内容,看看它们是否在 https://github.com/xtermjs/xterm.js/blob/0e45909c7e79c83452493d2cd46d99c0a0bb585f/src/common/data/EscapeSequences.ts

    【讨论】:

      猜你喜欢
      • 2023-04-08
      • 1970-01-01
      • 1970-01-01
      • 2010-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-29
      相关资源
      最近更新 更多