Qt Creator 代码编辑器中的双文本选择

Double text selection in code editor of Qt Creator

如何在 Qt Creator 代码编辑器中进行双重(三重)文本选择,与从 Parameters[=23= 插入 code snippet 后相同] 菜单,这将允许我在不同的地方同时进行编辑?

例如:在插入 for snippet

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

我可以改index,在的其他地方改成 ]的声明。

在 Qt 编辑器中,您可以使用重构选项 Rename Symbol 更改变量名称、类、函数等。它允许您在所有地方一步更改它。

您可以通过以下方式激活它:

  • 鼠标右键 > 重构 > 重命名光标下的符号;
  • 或在菜单中:工具 > C++ > 重命名光标下的符号;
  • 或Shift-Ctrl-R.

编辑: 在文本不是 'symbol' (variable/class/etc.) 的情况下 最好的选择是 Find/Replace 同时更改某些文本。但是,要将其限制为变量位于 for 标题中的行,您需要一个正则表达式,这会使它变得有点复杂。

例如:

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

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

您可以使用正则表达式:

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

并将其替换为:

for( i; i; i)

这导致:

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

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