Alex Nevskiy
Alex Nevskiy

Reputation: 407

Double text selection in code editor of Qt Creator

How to make a double (triple) text selection in Qt Creator Code Editor, the same as is after inserting code snippet from Parameters menu, which will allow me to do edit simutaneously in different places?

For example: After inserting for snippet

for (int ***index*** = 0; ***index*** < count; ++***index***) {
}

I can change index, and it'll be changed in other places of fors declaration.

Upvotes: 1

Views: 251

Answers (1)

agold
agold

Reputation: 6276

In the Qt Editor you can change names of variables, classes, functions, etc. with the Refactor option Rename Symbol. It allows you to change it at all places in one step.

You can activate it through:

  • either right mouse > Refactor > Rename Symbol Under Cursor;
  • or in the menu: Tools > C++ > Rename Symbol Under Cursor;
  • or Shift-Ctrl-R.

Edit: In the case of the text not being a 'symbol' (variable/class/etc.) the best option would be Find/Replace to simultaneously change certain text. However to limit it to lines in which the variable is in a for heading you would need a regular expression, which makes it a bit more complex.

For example for:

void func1() {   
    for(int index=0; index<10; index++) {
        //some code...
    }
}

void func2()
{    
    for(int index=0; index<10; index++) {
        \\code
    }
}

You could use the Regular expression:

for\s*\(\s*(\w+)\s+index([^;]*);\s*index([^;]*);\s+index(.*)\)

and replace it with:

for(\1 i\2; i\3; i\4)

Which results in:

void func1() {   
    for(int i=0; i<10; i++) {
        //some code...
    }
}

void func2()
{    
    for(int i=0; i<10; i++) {
        \\code
    }
}

Upvotes: 1

Related Questions