简体   繁体   English

VSCode 键绑定导航到渲染方法

[英]VSCode keybinding to navigate to render method

so I am using VSCode for react development and I was wondering if I could jump to the render function with a shortcut.所以我正在使用 VSCode 进行反应开发,我想知道是否可以使用快捷方式跳转到渲染 function。 Naturally there is no preconfigured way.自然没有预配置的方式。 So I looked into it and found a GitHub issue .所以我调查了一下,发现了一个GitHub 问题

{
    "key": "shift+alt+p",
    "command": "workbench.action.quickOpen",
    "args": "@:render"
},

Problem is, that the shortcut opens up the vscode window.问题是,快捷方式打开了 vscode window。 Which is prefilled and I have to press the enter button to do the actual "navigate to".这是预填充的,我必须按 Enter 按钮才能执行实际的“导航到”。 Does anyone know how to do this without pushing enter?有谁知道如何在不推入的情况下做到这一点?

I think the only way is to use a macro to run both the quickOpen command and selecting with one keystroke.我认为唯一的方法是使用宏来运行quickOpen命令并通过一次击键进行选择。

Using a macro extension like multi-command , put this into your settings:使用诸如multi-command 之类的宏扩展,将其放入您的设置中:

  "multiCommand.commands": [

    {
      "command": "multiCommand.goToRender",
      "sequence": [
        {
          "command": "workbench.action.quickOpen",
          "args": "@:render"
        },
        "workbench.action.acceptSelectedQuickOpenItem"
      ]
    }
  ]

and some keybinding to trigger that macro (in your keybindings.json):和一些键绑定来触发该宏(在您的 keybindings.json 中):

{
    "key": "shift+alt+p",
    "command": "extension.multiCommand.execute",
    "args": { "command": "multiCommand.goToRender" },
    "when": "editorTextFocus"
}

Of course, if you have multiple render objects the first will be selected and navigated to.当然,如果您有多个render对象,第一个将被选中并导航到。


An alternative is to use the selectBy extension which you could configure to jump to the next or previous occurrence of the word render .另一种方法是使用selectBy扩展,您可以将其配置为跳转到下一个或上一个出现的单词render The extension can move to occurrences of words (and not select anything).扩展名可以移动到单词的出现处(而不是 select 任何东西)。 In your settings:在您的设置中:

 "selectby.regexes": {    

    "goToRender": {
      "moveby": "render",
    }
  }

And some keybindings (whatever bindings you want):还有一些键绑定(无论你想要什么绑定):

  {
    "key": "shift+alt+p",          // go up to the previous `render` 
    "when": "editorTextFocus", 
    "command": "moveby.regex",
    "args": ["goToRender", "moveby", "prev", "start"]
  },

  {
    "key": "alt+p",            // go to the next `render`
    "when": "editorTextFocus",
    "command": "moveby.regex",
    "args": ["goToRender", "moveby", "next", "start"]
  },

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM