CTRL + G

a shortcut that completely changed the way I work.

Bartek Lipinski
Sep 8, 2016 · 5 min read
Image for post
Image for post

It all started with the video:

(you don’t really need to watch it to understand this post, I will explain everything you need to know, although if some day you find some time for it, I would highly suggest you do, there’s a lot of awesome stuff there)

As soon as I got to about 7:23 and I started listening about Android Studio feature I have never heard before, I became really, really intrigued.

Multicursor.

CTRL + G (ALT + J for Windows/Linux).

It was such a nifty feature, such a cool think to have at your hand at all times. Immediately I thought:

Boy, am I getting some more monkey-jobs copying code. I will click the hell out of my CTRL and G buttons.

At that moment I did not even consider it could change my coding style so much.

Multicursor toolkit. What do you really have to know to feel its true power?

CTRL+G. If you use it while having a particular text selected, it will select the next occurrence of this text in your code (creating a new cursor).

Image for post
Image for post
CTRL + G

The important part is, the Multicursor feature perceives your code just as a text, so you can also select a java-specific keywords, and build your Multicursor based on that.

Image for post
Image for post
CTRL + G (on the case keyword)

Three shortcuts to learn here:

Image for post
Image for post
Image for post
Image for post

(I could try to explain what they do but it’d be the best if you just tried them… seriously, it’ll take you like 30 seconds… at most)

IMPORTANT: I also use them without SHIFT just to jump around the code.

This one is not really required, but it can speed up your work significantly.

Image for post
Image for post

I find myself using mostly the Create Sequence feature, but there’s much more you can utilize on a daily basis. An awesome plugin to have installed in your Android Studio.

Real life usage examples

I’m using Multicursor all the time. Sometimes for bigger tasks, sometimes for smaller ones. Here are some cases I used this shortcut in.

I’m a huge fan of Support Annotations. I use them all the time. With the @IntDef at my fingertips, I sometimes give up on using enum, and just grab a handful of ints instead. Take a look at the way Multicursor can help me with that.

Here’s where I wanna get:

Image for post
Image for post

Here’s how I can get there:

Setup:

Image for post
Image for post
Just a regular copy-pasting
Image for post
Image for post
And renaming

Multicursor:

Image for post
Image for post
CTRL + G

I could’ve used it on multiple different things (“=”, “1”, “;” or some sort of set of those), I chose “int” for some unknown reason.

Creating sequence:

If you don’t want to use String Manipulation plugin you can do that manually. Here’s with the plugin:

Image for post
Image for post
The last could’ve been just SHIFT + ← as well
Image for post
Image for post
(I usually just click C and 5 in the plugin menu, here using mouse for better readability)

Copying modified version of rows:

And here’s where the true magic happens:

Image for post
Image for post

And the @IntDef is up and running. Done.

Extracting style from layout xml

Multicursor can easily work in layout xml as well. My exact case was a bit more complicated but the main issue was the same. I decided to extract a style from few Views in layout xml file.

In this example I used Multicursor twice. In two different ways.

Let’s assume this is the layout:

Image for post
Image for post

That’s how Multicursor can help me with the extraction process:

Image for post
Image for post

And that’s how I apply the extracted style to the xml (also with the Multicursor):

Image for post
Image for post

This example is something that happened to me few days ago.

I had 5 buttons in the compound View I was working on, and I added them to the class using another Android Studio plugin (that generates @Bind statements). But then I decided that I don’t really need to store references to those Buttons. I just needed to handle the OnClickListener. This is how I handled the change with the help of Multicursor:

Image for post
Image for post

Quick and easy.

And many many more…

And those are just three simple examples. I also had to “copy” a ton of (~3k lines of code) Swift code into Java. It was significantly less painful with the multicursor feature. I did it about 2 weeks ago and I would probably be still doing it if there was no multicursor feature.

For me it started as a cool little trick that I thought I would probably use once or twice. But as with most new things you learn, as you work along you find more and more usages for it, and all of a sudden you can’t believe how you could have lived without it before.

If you’re not using it yet, I highly suggest you try!

If you enjoyed this post, please show your support! Recommend, follow, comment. This means a lot!

Image for post
Image for post

HackerNoon.com

#BlackLivesMatter

Sign up for Get Better Tech Emails via HackerNoon.com

By HackerNoon.com

how hackers start their afternoons. the real shit is on hackernoon.com. Take a look.

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

Bartek Lipinski

Written by

senior android engineer @reddit | former android tech lead @getthefabulous | recovering feature creep 💉 | https://github.com/blipinsk

HackerNoon.com

Elijah McClain, George Floyd, Eric Garner, Breonna Taylor, Ahmaud Arbery, Michael Brown, Oscar Grant, Atatiana Jefferson, Tamir Rice, Bettie Jones, Botham Jean

Bartek Lipinski

Written by

senior android engineer @reddit | former android tech lead @getthefabulous | recovering feature creep 💉 | https://github.com/blipinsk

HackerNoon.com

Elijah McClain, George Floyd, Eric Garner, Breonna Taylor, Ahmaud Arbery, Michael Brown, Oscar Grant, Atatiana Jefferson, Tamir Rice, Bettie Jones, Botham Jean

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store