WebStorm 2021.2 Help

Multiple carets and selection ranges多个插入符号和选择范围

When typing, copying, or pasting, you can toggle multiple carets so that your actions apply in several places simultaneously. 键入、复制或粘贴时,可以切换多个插入符号,以便您的操作同时应用于多个位置。Advanced editor actions, such as code completion and live templates are supported as well and will apply to each caret.还支持高级编辑器操作,例如代码补全活动模板,并将应用于每个插入符号。

The number of carets that you can add in a file is limited to 1000.可以在文件中添加的插入符号数量限制为1000。

The most recently added caret is considered primary. 最近添加的插入符号被视为主要插入符号。Highlighting of the current editor line, completion lists, and other visual assistance features will apply to the primary caret. 突出显示当前编辑器行、完成列表和其他视觉辅助功能将应用于主插入符号。This caret will also remain when you turn off multiple carets.关闭多个插入符号时,此插入符号也将保留。

Add and remove carets添加和删除插入符号

You can add carets in two different ways:可以通过两种不同的方式添加插入符号:

To existing characters现有字符Using virtual spaces使用虚拟空间
If there is no character, tab, or whitespace at the position where you want to add a new caret, the new caret will be added to the last character position in the target line.如果要添加新插入符号的位置没有字符、制表符或空格,则新插入符号将添加到目标行中的最后一个字符位置。This way you can add new carets anywhere after the last character in any line. 这样,您可以在任何行中最后一个字符之后的任何位置添加新的插入符号。As soon as you start typing at a position beyond the end of the line, the necessary number of spaces will be added between the end of the line and the beginning of your input. 一旦您开始在行尾以外的位置键入,行尾和输入开始之间将添加必要数量的空格。
You can enable virtual spaces on the Editor | General page of the IDE settings Ctrl+Alt+S and they are also enabled in the column selection mode.可以在IDE设置Ctrl+Alt+S“编辑器”|“常规”页面上启用虚拟空间,也可以在列选择模式下启用虚拟空间。

Add or remove carets at selected locations using mouse使用鼠标在选定位置添加或删除插入符号

  • Alt+Click at the target location to add another caret.Alt+单击目标位置以添加另一个插入符号。

  • Alt+Click at one of the multiple carets to remove it. Alt+单击多个插入符号之一可将其删除。The last caret will not be removed.最后一个插入符号将不会被删除。

Add carets above or below the current caret using keyboard使用键盘在当前插入符号的上方或下方添加插入符号

  • Press Ctrl twice, and then without releasing it, press up or down arrow keys.Ctrl键两次,然后在不释放的情况下,按向上或向下箭头键。

    If virtual spaces are enabled, new carets will be added exactly above or below the current caret position. 如果启用了虚拟空间,将在当前插入符号位置的正上方或下方添加新的插入符号。Otherwise, in lines, which are shorter than the current offset, carets will be added at line ends.否则,在比当前偏移短的行中,将在行尾添加插入符号。

  • Enable the column selection mode (press Alt+Shift+Insert) and then press Shift+Up/ Shift+Down.启用列选择模式(按Alt+Shift+Insert),然后按Shift+Up/Shift+Down

  • Press Ctrl+Shift+A, type Clone caret, and choose the desired action from the suggestion list:Ctrl+Shift+A,键入“克隆插入符号”,然后从建议列表中选择所需的操作:

    Clone caret

    Note that by default these actions are not associated with keyboard shortcuts. 请注意,默认情况下,这些操作与键盘快捷键不关联。You can assign your custom shortcuts to these actions as described in configuring keyboard shortcuts.您可以将自定义快捷键指定给这些操作,如配置键盘快捷键中所述。

Add carets at each line of the current document在当前文档的每一行添加插入符号

  • Press Ctrl+Home to set the caret at the beginning of the first line, enable the column selection mode (press Alt+Shift+Insert), and then press Ctrl+Shift+End.Ctrl+Home将插入符号设置在第一行的开头,启用列选择模式(按Alt+Shift+Insert),然后按Ctrl+Shift+End

Add carets to the end of each line in the selected block将插入符号添加到选定块中每行的末尾

  • Select a code block in the editor and then press Alt+Shift+G.在编辑器中选择一个代码块,然后按Alt+Shift+G

Remove multiple carets删除多个插入符号

  • Press Esc to delete all existing carets, except the one that was added last.Esc键删除所有现有的插入符号,但上次添加的插入符号除外。

  • Alt+Click at one of the multiple carets to remove it. 按住Alt键并单击多个插入符号之一可将其删除。The last caret will not be removed.最后一个插入符号将不会被删除。

Select multiple non-contiguous ranges选择多个非连续范围

When you select multiple text ranges (non-contiguous selection), note the following:选择多个文本范围(非连续选择)时,请注意以下事项:

  • Each selection range is associated with its own caret, so you can start typing to replace all selected ranges with your input, or you can press Left Arrow or Right Arrow to remove the selection ranges but keep multiple carets at beginnings/ends of the ranges.每个选择范围都与自己的插入符号相关联,因此您可以开始键入以使用输入替换所有选定范围,也可以按向左箭头向右箭头删除选择范围,但在范围的开头/结尾保留多个插入符号。

  • As soon as selection ranges overlap, they are merged into a single selection range with a single caret.一旦选择范围重叠,它们就会用一个插入符号合并为一个选择范围。

  • Selection works independently of the code structure, that is selection ranges can include any characters, identifiers, words in string literals, comments, or their parts. 选择工作独立于代码结构,也就是说,选择范围可以包括任何字符、标识符、字符串文字中的单词、注释或其部分。So you have to be careful when changing the selected ranges as they may include different identifiers or their parts.因此,更改选定范围时必须小心,因为它们可能包含不同的标识符或其部分。

Select multiple words or text ranges选择多个单词或文本范围

  • While Alt+Click will add a new caret, double-clicking words or dragging the mouse over text ranges (keeping the same keys pressed) will add new carets with the corresponding selections.按住Alt键并单击将添加新的插入符号,双击单词或将鼠标拖动到文本范围上(保持按住相同的键)将添加带有相应选择的新插入符号。

    WebStorm: Select multiple text fragments.png

Select multiple occurrences of a word or a text range选择单词或文本范围的多次出现

  1. If you want to select words, set your caret at an occurrence of the desired word. 如果要选择单词,请将插入符号设置为所需单词的出现位置。Otherwise, select the desired range with the mouse or with keyboard shortcuts.否则,用鼠标或用键盘快捷键选择所需的范围。

  2. Do one of the following:执行以下操作之一:

    • Successively press Alt+J to find and select the next occurrence of case-sensitively matching word or text range.依次按Alt+J查找并选择下一个出现的区分大小写的匹配单词或文本范围。

    • Press Ctrl+Alt+Shift+J to select all case-sensitively matching words or text ranges in the document.Ctrl+Alt+Shift+J选择文档中所有区分大小写的匹配单词或文本范围。

  3. To remove selection from the last selected occurrence, press Alt+Shift+J.要从上次选定的引用中删除所选内容,请按Alt+Shift+J

  4. After the second or any consecutive selection was added with Alt+J, you can skip it and select the next occurrence with F3. 使用Alt+J添加第二个或任何连续选择后,可以跳过它并使用F3选择下一个引用。To return the selection to the lastly skipped occurrence, press Shift+F3.要将选择返回到最后跳过的事件,请按Shift+F3

Find and select multiple occurrences of a string查找并选择字符串的多个匹配项

  1. Press Ctrl+F or choose Edit | Find | Find from the main menu. Ctrl+F或从主菜单中选择“编辑”|“查找”|“查找”The search pane appears at the top of the active editor.搜索窗格显示在活动编辑器的顶部。

  2. Enter the string that you want to find and select. 输入要查找并选择的字符串。To the right of the search string, you will see the number of occurrences in the current document.在搜索字符串的右侧,您将看到当前文档中出现的次数。

  3. Optionally, restrict your search by case Match case Alt+C or to match only whole words Words Alt+W.(可选)按大小写Match caseAlt+C限制搜索,或仅匹配整个单词WordsAlt+W

  4. Press Ctrl+Alt+Shift+J or click Select All Occurrences Select All Occurrences on the toolbar.Ctrl+Alt+Shift+J或单击工具栏上的“选择所有引用Select All Occurrences

Use mouse to select rectangular fragments of text in normal selection mode在正常选择模式下,使用鼠标选择文本的矩形片段

  1. Make sure that the column selection mode is disabled.确保列选择模式禁用

  2. To select ranges as a single rectangle, do one of the following:要将范围选择为单个矩形,请执行以下操作之一:

    • Set the caret at one corner of the rectangle, and then Alt+Shift+Middle-Click at the diagonally opposite corner.在矩形的一角设置插入符号,然后在对角点按住Alt+Shift+Middle键单击

    • Alt+Shift+Click and drag the mouse to make the selection.Alt+Shift+单击并拖动鼠标进行选择。

  3. To select ranges as multiple rectangular selections, Ctrl+Alt+Shift+Click and drag the mouse over the desired parts of code.要将范围选择为多个矩形选区,请Ctrl+Alt+Shift+单击并将鼠标拖动到所需的代码部分上。

  4. As a result, you will have multiple selection ranges in each affected document line. 因此,在每个受影响的文档行中都有多个选择范围。On lines that are shorter than the rectangle, the selection will only span to the last character.在比矩形短的行上,选择范围将仅限于最后一个字符。

    WebStorm: Selecting multiple rectangular fragments of text with the mouse

Column selection mode列选择模式

In the column selection mode, keyboard navigation and selection shortcuts in the current document work differently to simplify adding multiple carets and making rectangular selections:列选择模式下,当前文档中的键盘导航和选择快捷键以不同方式工作,以简化添加多个插入符号和进行矩形选择:

  • You will be able to set your caret anywhere after the last character in any line. 您可以在任何行的最后一个字符之后的任何位置设置插入符号。As soon as you start typing at a position beyond the end of the line, the necessary number of spaces will be added between the end of the line and the beginning of your input.一旦您开始在行尾以外的位置键入,行尾和输入开始之间将添加必要数量的空格。

  • Pressing Shift+Up/ Shift+Down or dragging the mouse up and down will add new carets above/below the current one instead of making a continuous selection.Shift+Up/Shift+Down或上下拖动鼠标将在当前插入符号的上方/下方添加新的插入符号,而不是进行连续选择。

  • The enabled column selection mode only affects the current editor tab. 启用的列选择模式仅影响当前编辑器选项卡。If you close or reopen the tab, it will switch back to the normal mode.如果关闭或重新打开选项卡,它将切换回正常模式。

If the column selection mode is enabled for the current document, the Column indicator is displayed on the status bar.如果为当前文档启用了列选择模式,则指示器将显示在状态栏上。

Toggle between normal and column selection modes在正常和列选择模式之间切换

  • Press Alt+Shift+Insert.Alt+Shift+Insert

  • From the main menu, choose Edit | Column Selection Mode.从主菜单中,选择“编辑”|“列选择模式”

  • From the context menu of the editor, choose Column Selection Mode.从编辑器的关联菜单中,选择“列选择模式”。

Copy and paste with multiple carets使用多个插入符号复制和粘贴

When text ranges selected with multiple carets are copied Ctrl+C or cut Ctrl+X, selections for each caret are placed to the clipboard as separate lines, even if the original selections were on the same line.当使用多个插入符号选择的文本范围按Ctrl+C进行复制或按Ctrl+X进行剪切时,每个插入符号的选择将作为单独的行放置到剪贴板上,即使原始选择位于同一行上。

If the column selection mode was enabled, the selection could also include empty spaces after ends of lines. 如果启用了列选择模式,则选择还可以在行结束后包含空格。These will be replaced with whitespaces in the clipboard if you copy the selection.如果复制所选内容,这些内容将被剪贴板中的空白替换。

When you paste any multi-line content from the clipboard, you can add multiple carets for each line in desired places, and then press Ctrl+V to paste each line at its own caret.从剪贴板粘贴任何多行内容时,可以在所需位置为每行添加多个插入符号,然后按Ctrl+V将每行粘贴到其自己的插入符号。

Last modified: 16 July 2021