SlickEdit Community

SlickEdit Product Discussion => SlickEdit® => Did you know? => Topic started by: Dennis on August 25, 2020, 03:00:37 PM

Title: Ctrl + Shift + | (vertical bar)
Post by: Dennis on August 25, 2020, 03:00:37 PM
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: [Select]
#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);
}

"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: [Select]
#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;
}

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: [Select]
    switch (sen) {
    SEN_Ottawa,
    SEN_Washington,
    SEN_Rome,
    default:
       break;
    }

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

You now have this:
Code: [Select]
    switch (sen) {
    case SEN_Ottawa:
       return "SEN_Ottawa";
    case SEN_Washington:
       return "SEN_Washington";
    case SEN_Rome:
       return "SEN_Rome";
    default:
       break;
    }