SlickEdit Product Discussion > Did you know?

Ctrl + Shift + | (vertical bar)

(1/1)

Dennis:
More multi-cursor magic.

Ctrl+Shift+|, that is vertical bar, in most emulations, can be used to create multiple cursors.  Place your cursor in the first location you want a cursor, hit Ctrl+Shift+|, then move to the next location, and do it again, now you have two cursors, move it to yet another location, now you have three cursors.

For example:

--- Code: ---#include <stdio.h>
int main(int c, char *argv[])
{
    for (int a=0; a<c; a++) {
        printf("arg[%d of %d] = %s\n", a, c, argv[a]);
    }
    printf("printed c=%d args\n", c);
}

--- End code ---

"c" is a lousy name, suppose you want to change it to "argc", like every other C program in the galaxy uses.

Start with your cursor at the beginning of the file, then search for "c" using a exact case word match.
Hit Ctrl+Shift+|, then do a find-next (Ctrl+G), and hit Ctrl+Shift+|, until you have a cursor on each instance
of "c", including the one within a string.

Then type "arg" to transform it to "argc", and hit Escape to cancel the multiple cursors.

You may ask, why is the key combination Ctrl+Shift+| ?  How am I supposed to remember that?  Pretty easy, a vertical bar looks like a cursor.

Bonus tip:  If you have a multi-line selection, hitting Ctrl+Shift+| will transform it to multiple cursors.

For example:

--- Code: ---#include <stdio.h>
enum SillyEnumName {
    SEN_Ottawa,
    SEN_Washington,
    SEN_Rome,
};
const char *enum_to_name(const SillyEnumName sen)
{
    switch (sen) {
    default:
       break;
    }
    return nullptr;
}

--- End code ---

Suppose you want to finish filling in the switch statement.  Start by selecting the 3 lines in the enumeration to grab the enumerator names, then paste them inside the switch statement, so now you have:

--- Code: ---    switch (sen) {
    SEN_Ottawa,
    SEN_Washington,
    SEN_Rome,
    default:
       break;
    }

--- End code ---

Now select the three lines you just pasted, and hit Ctrl+Shift+|, you now have three cursors.

* Hit Home to get to to the beginning of the line, then type "case "
* Cursor right then do a select-word (Ctrl+W in some emulations), then copy that for later (Ctrl+C)
* Hit Delete to remove the trailing comma
* Type ":" and hit return
* Type 'return "', paste (Ctrl+V), and then type the trailing quote and semicolon ";
* Hit Escape to cancel the multiple cursors
You now have this:

--- Code: ---    switch (sen) {
    case SEN_Ottawa:
       return "SEN_Ottawa";
    case SEN_Washington:
       return "SEN_Washington";
    case SEN_Rome:
       return "SEN_Rome";
    default:
       break;
    }

--- End code ---

Navigation

[0] Message Index

Go to full version