CTRL + G - hotkey that completely changed the principle of my work



    In this article I will talk about one of the very important and necessary hotkeys in Android Studio, which will allow you to significantly improve your performance. The cases described here are most common when refactoring ready-made code, so I recommend that you thoroughly study the article and learn the described hotkeys.

    Note: This post is a very free translation of this article. The goal was to convey the meaning of the text, so in some places the text may not coincide with the original.

    I also advise you to look:

    " Proper setup of Android Studio
    " Grouping plugin for Android Studio

    Multicursor. What do you need to know to understand that it is really powerful?


    CTRL + G (Alt + J for Windows) . Select the text and press CTRL + G. Thus, you select the occurrence of the selected text further in the code (thus creating a new cursor):



    CTRL + G

    An important feature is that the multicursor function treats the code as plain text, so you can also select the key the word Java, and create a multicursor based on it.



    Keyboard shortcuts for highlighting


    Explore these three key combinations:




    I could try to explain what they do, but it’s best to try it myself.

    Important: combinations can be used without holding down the Shift key to easily move the code.

    Examples of real use


    I use multicursor constantly. Sometimes for large tasks, sometimes for small ones. The following are some examples of using this keyboard shortcut.

    @IntDef


    I really love Support Annotations and use them all the time. @IntDef eliminates the use of enumerations, and simply creates a bunch of ints instead of enum. See how a multi-cursor can help me with this.

    Here is what I need:



    Here is how I can get this:

    Standard way





    Easy copy-paste



    & rename

    Multicursor





    CTRL + G

    I could use it to highlight other things ("=", "1", ";", etc.), for example, I chose "int".

    Create a sequence


    If you do not want to use the String Manipulation plugin, you can do this manually. Here's what it looks like using the plugin:



    The latter could have been done with SHIFT + ←



    (I usually use the keyboard shortcut C + 5, but here I did it with the mouse for clarity)

    Copying a modified version of strings


    And here, where “miracles” really happen:



    Done.

    Extract styles from xml layout


    A multicursor can easily work with an XML layout as well. In my particular case, it was a bit more complicated - I needed to extract styles from several View.

    In this example, I used multicursor twice, in two different ways.

    Suppose there is such a layout:



    Here is how a multicursor can help me with the extraction process:



    And here is how I apply the extracted style to XML (also with multicursor):



    OnClick at Butterknife


    This is an example of what happened to me a few days ago.

    It had 5 buttons in the form of a complex View. I used the Android Studio plugin to generate variables with Bind . But later I realized that I did not need to store links to these buttons. I just need to handle the click on the buttons. Here's how I dealt with this with the help of the multicursor:



    Easy and fast

    And much more...


    For me, it started as a little trick that I use once or twice. But, as it happens with new things, during work I found more and more applications for him, and suddenly I caught myself thinking: “How could I live without him before?”

    If you are not using it yet, I highly recommend you try it!

    Also popular now: