Add multiple cursors at next occurrence?

Hi, was wondering if there is currently a way to add multiple cursors for each next occurrence of a piece of text? Basically the Command+D shortcut in Sublime on Mac.

4 Likes

I'm trying to set this up myself at the moment and not having much luck :frowning: The closest shortcut I can find is "Select or Find Next" (Alt+H) and "Select or Find Previous" (Shift+Alt+H), but they merely move the cursor to the next instance and select it—they don't create an additional cursor. If anyone knows how to replicate Sublime/VSCode-style multiple cursors with selections, I'd be really happy!

1 Like

We have a command called Quick Add Next for this, but it's not bound to any keyboard shortcut by default. You could rebind it with Tools -> Modify Keyboard Shortcuts..., search for Quick Add Next, then select your preferred keybinding.

12 Likes

Thanks, @kevinushey! That's exactly what I'm looking for :smiley:

Hi there: I am going to re-open this thread rather than posting a new one.
The command Quick Add Next is really great. Unfortunately, though, it does not reproduce fully the behavior of Ctrl+D (or command+D) in Sublime, that is important for the workflow of many.
The main problem for me is the following: Ctrl+D in Sublime recognizes all subsequent occurrences of a text block/piece of text that is currently selected, e.g. all four occurrences of CVD will be selected in the following text block:

CVD
Tab1.CVD
Tab1CVD
Tab1_CVD

Whereas command Quick Add Next would only select the first two: it appears to only recognize text blocks that are bordered by either spaces or dots, but not text blocks that are bordered by anything else, including underscores.
This can be a problem: in my workflow I produce different versions of the same objects that differ only by a couple letters (say, the above objects may refer to CardioVascular Disease and I might want to quickly produce another set of objects where CVD becomes PD, Pulmonary Disease; or simply change Tab1, Regression1 into Tab2, Regression2 and so on).
The fact that a dot is recognized as a "valid border" does not fit well any of R's coding style guides (Hadley Wickham's, Google's, etc.), because, as people more expert than I am know well, dots are meaningful in R and should only be used for class-specific S3 functions. Underscores are preferred by Hadley, camelcase by most other guides.

My questions are:

  1. Is it possible to reconfigure the "bordering character" used by Quick Add Next from dot to, say, underscore?
  2. Is there any solution for this problem that I am not aware of or you could suggest?

In addition, Ctrl+D / command+D in Sublime also have two other awesome features which are being able to go back one step when you select by mistake one occurrence too many (using Ctrl+U for "Undo") and even skipping one occurrence and going on to the next (using Ctrl+K for "Kill" ), as described here. But I guess that that would be asking for too much (would it?) and I would be already extremely happy with solving the issue above!

Thanks in advance :slight_smile:

1 Like

It's interesting you mention this, @Luca: I'd actually been having similar trouble with Quick Add Next, but I hadn't quite joined the dots yet (I'd gotten as far as, "This doesn't always seem to work..." :laughing:).

Implementing a really complete version of it might be possible if we were to write an Add-In? (I say rhetorically: I'm trying very hard not to volunteer for things until my thesis is in in March!)

I'm not an IDE dev, so this should be taken with a grain of salt, but, given RStudio is built on top of Ace Editor, a good starting point might be to figure out if there's a native Ace implementation (e.g. see the options at the link below)
https://defkey.com/ace-editor-shortcuts

1 Like

Thanks! We wanted to model the behavior of Sublime Text in Quick Add Next but missed this case -- it should be fixed in the next daily builds of RStudio.

4 Likes

Supporting the other actions (Ctrl + U, Ctrl + K) is not yet done, though. You might consider filing a feature request so that it stays on our radar.

2 Likes

Thanks for your reactions!

rensa, mara: your suggestions are intriguing, but because @kevinushey and colleagues are indulging us (we really, really appreciate this!) it is probably not necessary for us to take further action.
@kevinushey: fantastic. I will add the feature request for those extra features!

Cheers everybody,
Luca

2 Likes

Can you try Ctrl + Alt + K It selects all occurrences of the currently selected word/phrase but the only caveat is it is case insensitive. This shortcut is not mentioned in keyboard shortcuts page or cheat sheet. I am using RStudio 1.2.1206

I created an account just to thank you for this feature!

2 Likes