英文:
Visual Studio Code multiline select until a character
问题
apples
int(200) NOT NULL,
bananas
int(100) NOT NULL,
mangos
int(100) NOT NULL,
kiwi
int(100) NOT NULL,
raspberry
int(100) NOT NULL,
Is there a way I can select until some character is found in the line where the cursor is placed?
In this case, the expected selection is:
apples
bananas
mangos
kiwi
raspberry
英文:
I would like to select all the words at once between the backtick. In MACOSX use <kbd>alt</kbd>+ <kbd>shift</kbd> and the cursor put a multi cursor at the beginning of the words but I can't stop the selection to the "`" character where the word ends.
`apples` int(200) NOT NULL,
`bananas` int(100) NOT NULL,
`mangos` int(100) NOT NULL,
`kiwi` int(100) NOT NULL,
`raspberry` int(100) NOT NULL,
Is there a way I can select until some character is found in the line where the cursor is placed?
In this case, the expected selection is:
`apples`
`bananas`
`mangos`
`kiwi`
`raspberry`
答案1
得分: 1
如果有一种专门的方法可以选择到特定字符,我不知道它。
然而,您这里有一个非常规则的“输入”(水果单词中没有空格)。如果这代表了您的真实情况,那么要选择苹果、香蕉、芒果、奇异果、覆盆子,只需将光标放在“apple
”的开头,然后按住alt+shift并单击“raspberry”开头,然后按ctrl+shift+right,然后shift+right(对于Windows和Ubuntu。我认为对于MacOS来说,是option+shift+right,然后shift+right,但我不是100%确定)。
如果水果单词中有空格,这种方法将不起作用。在这种情况下,如果您正在执行查找和替换操作,可以使用查找和替换功能的正则表达式模式。类似于查找^`([^`]+)`
,然后用$1的某种用法进行替换。
英文:
If there is a dedicate way to select until a specific character, I am not aware of it.
However, you have a very regular "input" here (none of the fruit words have spaces in them). If that's representative of your real scenario, then to select apples, bananas, mangos, kiwi, raspberry, then put the caret right at the beginning of "`apple`", then hold <kbd>alt</kbd>+<kbd>shift</kbd> and click the beginning of "raspberry", then press <kbd>ctrl</kbd>+<kbd>shift</kbd>+<kbd>right</kbd>, then <kbd>shift</kbd>+<kbd>right</kbd> (Windows and Ubuntu. I think for MacOS it's <kbd>option</kbd>+<kbd>shift</kbd>+<kbd>right</kbd> then <kbd>shift</kbd>+<kbd>right</kbd>, but I'm not 100% sure).
This doesn't work if the fruit words have spaces in them. In that case, if you happen to be doing this because you want to do find and replace, you can use the regular expression mode of the find and replace feature. Something like find ^ `([^`]+)`
and then replace withsome usage of $1
.
答案2
得分: 1
-
按下<kbd>command</kbd>+<kbd>F</kbd> 打开查找小部件。
-
在正则表达式模式 (
.*
图标) 中键入`.*?`
。 -
按下<kbd>command</kbd>+<kbd>shift</kbd>+<kbd>L</kbd> 选择所有匹配项。
-
按下<kbd>esc</kbd> 关闭查找小部件。
英文:
-
Press <kbd>command</kbd>+<kbd>F</kbd> to open the find widget.
-
Type
`.*?`
in regex mode (.*
icon). -
Press <kbd>command</kbd>+<kbd>shift</kbd>+<kbd>L</kbd> to select all occurrences.
-
Press <kbd>esc</kbd> to close the find widget.
答案3
得分: 1
您可以使用扩展 Select By
创建一个键绑定:
{
"key": "shift+alt+]", // 或者其他组合键
"command": "selectby.regex",
"when": "editorTextFocus",
"args": {
"forward": "('''|\"\"\"|'|\"|`)",
"forwardNext": "{{1}}",
"forwardInclude": false,
"forwardNextInclude": false
}
}
在您想要选择的字符串之前放置多个光标,然后按下键绑定。
英文:
You can use the extension Select By
Create a keybinding:
{
"key": "shift+alt+]", // or any other combo
"command": "selectby.regex",
"when": "editorTextFocus",
"args": {
"forward": "('''|\"\"\"|'|\"|`)",
"forwardNext": "{{1}}",
"forwardInclude": false,
"forwardNextInclude": false
}
}
Place multiple cursors before the strings you want to select, and press the key binding.
答案4
得分: 1
如果您经常进行此选择,可以使用此扩展进行按键绑定:查找和转换(我编写的)。示例按键绑定 - 在您的 keybindings.json
中:
{
"key": "alt+d", // 任何您想要的按键绑定
"command": "findInCurrentFile",
"args": {
"find": "(?<=`)(.*)(?=`)",
"restrictFind": "selections",
"isRegex": true
},
}
对于此操作,您只需选择要更改的行 - 可以是一个选择,参见演示。或者,您可以使用以下选项:
"restrictFind": "line",
并在您想要更改的任何行上放置光标 - 光标可以放在行的任何位置。
通过 line
:
英文:
If you do this selection frequently you can make a keybinding for it using this extension: Find and Transform (which I wrote). Sample keybinding - in your keybindings.json
:
{
"key": "alt+d", // whatever keybinding you want
"command": "findInCurrentFile",
"args": {
"find": "(?<=`)(.*)(?=`)",
"restrictFind": "selections",
"isRegex": true
},
}
For this you just need to select the lines you want changed - it can be one selection, see demo. Or you could use this option:
"restrictFind": "line",
and just put a cursor on any lines you want changed - the cursor can go anywhere on the line.
By "line"
:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论