Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Is there a shortcut for "select next occurrance"?



  • Lately I had to use a lot other IDEs (such as Visual Studio Code) and I've discovered a magic keybinding for selecting the next occurrence of the currently selected text, which is extremely useful to rapidly find and select the nearby occurrences of text and change them all at the same time without having to do a "find and replace".

    Now I've returned to my beloved QtCreator, but I cannot find this keybinding anywhere (I'm using the latest version, 4.13.2). Is it really missing? If so, is there a workaround, like a macro that could be written or a plugin that does something like this?

    Thanks a lot in advance!


  • Moderators

    I don't know if it exists, but you can quite easily work around it:

    • select a word
    • Ctrl+F
    • F3 will cycle through all occurences


  • @Beriol
    Same as in VS, I think: select text, Ctrl+F3. (And Shift+Ctrl+F3 for backward search.)



  • Thank you for your anwser, but I'm looking for a "1 key to do it all" type of thing. The main problem with that approach though is that even if you cycle the occurrences, it doesn't select them for editing.

    Sample example of what I'm looking for: say I have this text "hello, hi, bye, hello, hello, bye, hello, hi".

    I select the 'hello' in bold, then press once the magic keybinding I'd like, and the 'hello' in italics gets selected. Then I press the keybinding again, and the 'hello' with the strikethrough is also selected. Then, if I start typing 'good morning', all the selected occurrences get modified "live".

    Ideally, I'm looking for something like this :)



  • @Beriol
    Which is exactly what Ctrl+F3 does?

    Then, if I start typing 'good morning', all the selected occurrences get modified "live".

    You need to use Refactor > Rename, which will work on code but not your example. And/or to accomplish what you want get used to selecting the desired area and pressing Ctrl+F. I don't know what editor you're talking about which changes all occurrences of a string without some kind of scoped or global "Replace".



  • @JonB (I noticed your message when I finished writing the last one) sadly that wouldn't work too, because it doesn't actually select the occurrences, it just "highlights" them.

    In the example I mentioned above, if I use Ctrl+F3 as keybinding, when at the end of the example I start typing, it would only change the last occurence, not all of them.


  • Qt Champions 2019

    @JonB said in Is there a shortcut for "select next occurrance"?:

    Ctrl+F3

    But it is 2 key? :-)



  • @jsulm
    No, it is 1.5 keys.



  • @JonB said in Is there a shortcut for "select next occurrance"?:

    @jsulm
    No, it is 1.5 keys.

    Haha, it counts as a key for what I need. But still, it wouldn't work.

    Here's an example of what I need (taken from Visual Studio Code)

    (testgif.gif

    Here's the same example in QtCreator (with CTRL+F3):
    testgif2.gif

    See what I mean?


  • Moderators

    Ah, what you are looking for is Ctrl+Shift+R. No need to select whole word, just have cursor inside of it.



  • @Beriol
    First, since you have picked to rename a variable in code, this tells me nothing about whether VS is doing a textual replacement or a symbol replacement. Your example is quite different from the earlier one of formatted text/sequence of words. Where does VS Code support formatted text?

    Anyway. I've told you what your two choices are in Creator here:

    • Refactor > Rename.

    • Select an area and Ctrl+F.

    [EDIT @sierdzio's Ctrl+Shift+R is just a shortcut for Refactor > Rename. Note that this may change multiple files.]



  • @sierdzio

    That's not it either :(

    That would change all occurrences in the file (and in the project actually), and it seems to work only for variables (but maybe I'm doing something wrong). What I'm looking for is for any string, not just variables. It should just select occurrences of the selected text, no matter what it is (just like the famous CTRL+F3, but that it actually selects the occurrences for editing).



  • @JonB My bad with the example, it's a textual replacement. Any text can do, doesn't have to be a variable.

    Yeah, I know of Ctrl+F of course, same as rename. That doesn't solve it though :(

    Isn't there a way to create a macro or is there a plugin that could help?

    EDIT: so, Just to recap, I literally need a version of the CTRL+F3 that also selects the occurrences it's processing, that's it.


  • Moderators

    @Beriol said in Is there a shortcut for "select next occurrance"?:

    That would change all occurrences in the file (and in the project actually)

    Depends on scope. If you select a local variable (like in the GIF you posted) it will only rename it inside of that function.



  • @Beriol said in Is there a shortcut for "select next occurrance"?:

    Yeah, I know of Ctrl+F of course, same as rename.

    If you mean going via Ctrl+F is same as Rename, it is not. For a start, Ctrl+F will do your "textual" replace, which Rename will not.



  • @JonB I didn't mean that, I meant that it doesn't solve the problem. Come on, I know you're trying to help and I really appreciate it (I do), but it sohuld be clear what I need right now, isn't it? No point in marking these problems, it's not helpful...

    EDIT: yes, it does the textual search, but it doesn't "easily" allow to replace the strings, unless you're replacing them one at the time or all of them at once.

    So, Just to recap, I literally need a version of the CTRL+F3 that also selects the occurrences it's processing, that's it.



  • @Beriol
    It lets you do them one at a time if you want.

    Anyway, you don't find my answers helpful because Creator does not allow you to do what you show from VS. Best of luck.



  • @JonB You misunderstood, I do find them helpful. We've established that there is no "standard" way to do it. So the next bit: is there a way to "extend" QtCreator to do it, such as with a macro or a plugin, that you know of?


  • Lifetime Qt Champion

    Hi @Beriol,

    so it seems what you want to do is an extension or special mode of QTCREATORBUG-16013. You may comment and vote there.

    Regards



  • @aha_1980 Yes, I've just read the report and yes, that's exactly want I wanted to do! I'll definitely vote there, tank you! :)


Log in to reply