Visual studio code 如何将多行代码段的一部分粘贴到特定行,将其余部分粘贴到另一行
我想为自己的使用创建一个自定义代码段,目前我想为@emotion/core创建一个代码段 我总是希望/**@jsx jsx*/位于我的jsx文件的顶部。因此,当我在第9行导入模块时,从“@emotion/core”导入{css,jsx}在第9行,/**@jsx jsx*/在第0行。 我如何做到这一点 当前代码段:Visual studio code 如何将多行代码段的一部分粘贴到特定行,将其余部分粘贴到另一行,visual-studio-code,code-snippets,vscode-snippets,Visual Studio Code,Code Snippets,Vscode Snippets,我想为自己的使用创建一个自定义代码段,目前我想为@emotion/core创建一个代码段 我总是希望/**@jsx jsx*/位于我的jsx文件的顶部。因此,当我在第9行导入模块时,从“@emotion/core”导入{css,jsx}在第9行,/**@jsx jsx*/在第0行。 我如何做到这一点 当前代码段: "Import emotion":{ "prefix":"ime", "description": "Import emotion", "body":
"Import emotion":{
"prefix":"ime",
"description": "Import emotion",
"body":
[
"/** @jsx jsx */",
"import {css, jsx} from '@emotion/core';"
]
},
您必须将代码段分解为单独的命令,以便在中间步骤中移动光标。这将需要一个宏扩展,如 将其放入您的settings.json:
"multiCommand.commands": [
{
"command": "multiCommand.insertImports",
"sequence": [
{
"command": "editor.action.insertSnippet",
"args": {
"snippet": "import {css, jsx} from '@emotion/core';"
}
},
// "editor.action.setSelectionAnchor", // see note below
"cursorTop",
{
"command": "editor.action.insertSnippet",
"args": {
"snippet": "/** @jsx jsx */\n"
}
},
// "editor.action.goToSelectionAnchor",
// "editor.action.cancelSelectionAnchor",
"cursorDown"
]
}
]
和一些键绑定来触发该宏:
{
"key": "ctrl+shift+i", // whatever keybinding you wish
"command": "extension.multiCommand.execute",
"args": {
"command": "multiCommand.insertImports"
},
"when": "editorTextFocus"
},
关于锚定命令的说明
这些命令在内部人员的构建中,因此可能在2020年6月初的v1.46版本中。它们位于宏中只是为了方便将光标返回到开始位置。出于某种原因,命令workbench.action.navigateToLastEditLocation在这里对我不起作用-我认为这就足够了
如果没有这些新命令,光标将不会返回到开始的位置-也许这对您来说不是问题。无论如何,他们很快就会来。一旦你有了这个版本,它们就会包含在那些命令中。下面是使用这些命令的演示:
editor.action.setSelectionAnchor
editor.action.goToSelectionAnchor
editor.action.cancelSelectionAnchor