Jam*_*mes 5 c++ visual-studio-code vscode-snippets
在 Visual Studio 2019 中,我可以使用Alt++多行编辑“虚拟”空白,然后按任意键使所有行都用空格填充到所选列,我经常使用它来使初始化代码更易于阅读Shift。(Arrow Keys)然而,当我切换到 Visual Studio Code 时,我找不到等效的东西。我能找到的最接近的东西是Ctrl+ Alt+ (Arrow Keys)。这并不是我所需要的,因为它只将每行光标放在末尾,而不是前面示例中的“虚拟”空白。
这是 Visual Studio 2019 中的可视化示例(我不知道如何制作 GIF):
VSCode 中有类似的东西吗?还是我现在没有它?
好问题,我找不到在 VScode 中执行相同操作的方法,但这里有一个小技巧可以达到相同的效果:
显然,这不是一个很好的工作流程……但它确实有效。您还可以研究 VScode 扩展,以使其更快或制作您自己的
您可以使用宏很好地完成此操作。使用像多命令这样的宏扩展将其放入您的settings.json:
"multiCommand.commands": [
{
"command": "multiCommand.padTrailingSpaces",
"sequence": [
"editor.action.insertCursorAtEndOfEachLineSelected",
"cursorHomeSelect",
{
"command": "editor.action.insertSnippet,
// pad end of each line with lots of spaces's'
"args": {
"snippet": "$TM_SELECTED_TEXT ",
}
},
"cursorHomeSelect",
{
"command": "editor.action.insertSnippet",
"args": {
// keep first 30 characters, increase if you typically need more
"snippet": "${TM_SELECTED_TEXT/(.{30}).*/$1/g}",
}
}
]
}
]
Run Code Online (Sandbox Code Playgroud)
上面的代码将光标放在每行末尾,添加了比您需要的更多的空格,然后仅保留每行的前 30 个字符。
选择一些键绑定(在 keybindings.json 中):
{
"key": "alt+s",
"command": "extension.multiCommand.execute",
"args": { "command": "multiCommand.padTrailingSpaces" },
"when": "editorTextFocus"
},
Run Code Online (Sandbox Code Playgroud)
首先选择您想要填充的所有行,然后触发您的键绑定。那么至少所有光标都用填充对齐,并且可以轻松地同时向左或向右移动所有光标。
您可能可以将30我仅用于演示目的的 减少一些 - 取决于您最长的队伍通常有多长。
| 归档时间: |
|
| 查看次数: |
1947 次 |
| 最近记录: |