Visual Studio Code多行选择直到字符。

huangapple go评论64阅读模式
英文:

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> 关闭查找小部件。

Visual Studio Code多行选择直到字符。

英文:
  • 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.

Visual Studio Code多行选择直到字符。

答案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:

  {
    &quot;key&quot;: &quot;shift+alt+]&quot;,  // or any other combo
    &quot;command&quot;: &quot;selectby.regex&quot;,
    &quot;when&quot;: &quot;editorTextFocus&quot;,
    &quot;args&quot;: {
      &quot;forward&quot;: &quot;(&#39;&#39;&#39;|\&quot;\&quot;\&quot;|&#39;|\&quot;|`)&quot;,
      &quot;forwardNext&quot;: &quot;{{1}}&quot;,
      &quot;forwardInclude&quot;: false,
      &quot;forwardNextInclude&quot;: 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",

并在您想要更改的任何行上放置光标 - 光标可以放在行的任何位置。

Visual Studio Code多行选择直到字符。

通过 line

Visual Studio Code多行选择直到字符。

英文:

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:

{
  &quot;key&quot;: &quot;alt+d&quot;,                 // whatever keybinding you want
  &quot;command&quot;: &quot;findInCurrentFile&quot;,
  &quot;args&quot;: {
    &quot;find&quot;: &quot;(?&lt;=`)(.*)(?=`)&quot;,
    &quot;restrictFind&quot;: &quot;selections&quot;,
    &quot;isRegex&quot;: 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:

&quot;restrictFind&quot;: &quot;line&quot;,

and just put a cursor on any lines you want changed - the cursor can go anywhere on the line.

Visual Studio Code多行选择直到字符。

By &quot;line&quot;:

Visual Studio Code多行选择直到字符。

huangapple
  • 本文由 发表于 2023年2月6日 16:51:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/75359110.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定