📜 ⬆️ ⬇️

CTRL + G - hot key, 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 increase your productivity. The cases described here are most often encountered when refactoring a ready-made code, therefore I recommend thoroughly studying the article and learning the hotkeys described.

Warning: 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 see:
')
" Proper setup of Android Studio
» Grouping plugin for Android Studio

Multi-cursor What do you need to know to understand that this is really powerful?


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



CTRL + G

An important feature is that the function of the multi-cursor treats the code as plain text, so you can also select the Java keyword, and create a multi-cursor based on it.



Shortcut Keys for Highlighting


Examine these three key combinations:




I could try to explain what they are doing, but it's better to try it yourself.

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

Real-life examples


I use multi-cursor all the time. Sometimes for big tasks, sometimes for small ones. Below are some examples of using this shortcut.

@IntDef


I really love Support Annotations and use them all the time. @IntDef allows you to refuse to use enums, and simply create a bunch of ints instead of enum. See how a multi-cursor can help me with this.

This is what I need:



Here is how I can get this:

Standard way





Easy copy-paste



And renaming

Multi-cursor





CTRL + G

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

Creating a sequence


If you do not want to use the String Manipulation plugin, you can do it manually. Here’s what it looks like with a plugin:



The latter may have been done with SHIFT + ←



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

Copy modified row version


And here is where the “miracles” really happen:



Is done.

Retrieving Styles from an xml Layout


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

In this example, I used a multi-cursor twice, in two different ways.

Suppose there is such a layout:



Here's how a multi-cursor can help me with the extraction process:



And this is how I apply the extracted style to XML (also with a multi-cursor):



Onclick in butterknife


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

I 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 keep links to these buttons. I just need to handle click on the buttons. Here is how I handled this with a multi-cursor:



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, while working, I found more and more uses for it, and suddenly I caught myself thinking, “How could I live without it before?”.

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

Source: https://habr.com/ru/post/310392/


All Articles