Place multiple cursors with the same word prefix in VS code vim plugin
Asked Answered
D

2

7

In the vscode vim plugin, I use gb to select multiple words. I have four functions starting with handle but they are not exactly the same word. How can I put multi cursor for selecting them? Thanks in advance!

  handleSearchTermOnChange 
  handleActivateSearch 
  handleDeactivateSearch
  handleSearchQuery
Dundee answered 18/8, 2021 at 4:0 Comment(2)
Vim doesn't have a built-in gb command that does what you describe and it doesn't have "multi cursor" either. Are you sure you are using Vim?Chromatophore
@Chromatophore I use the vscode vim pluginDundee
G
12

With my understanding (in VsCodeVim) you can.

  1. v
  2. cover the desired word/prefix (in your case handle)
  3. gb as many times desired to choose all the instances you want.
  4. Then do whatever you like whit the chosen words.

Happy shortcut coding.

Gerlachovka answered 5/7, 2022 at 11:26 Comment(4)
Just forgot the visual mode select. Thanks!Dundee
@Dundee a small improvement: you can also change step 3 to ctrl+shift+L (which is command for "Select All Matches") if you know you want to select all occurrences. This way you can leave unnecessary gb clicks out and do the same thing even faster.Gerlachovka
To add on the selection hit shift+aNonintervention
ctrl-shift-L doesn't work for me, but ctrl-d (cmd-d) does this as well. I tried to give some more detail on step 4 as well in below answerSurbase
S
3

Expanding on this a bit more, there is multi cursor support with the below method:

  1. With cursor in desired location enter visual mode. Can do this with either CMD-D/CTRL-D (Mac/other platforms) or regular vim shortcut with the V key

enter image description here

  1. Select text with arrow/navigation keys.

enter image description here

  1. Now hit CMD-D/CTRL-D to select the next occurrence and repeat as needed to select more. Similarly gb can also be used as stated in Hessuew's answer.

enter image description here

  1. Now regular vim commands in visual mode can be used (replace, delete, etc.) or you can enter insert mode with multiple cursors by hitting: shift+i or shift+a (shown below for shift+a)

enter image description here

Surbase answered 29/5, 2023 at 15:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.