131

How to select multiple places in code in Android Studio ?

I want to insert the same text in multiple places in my source code. Like a have more than one mouse cursor. I used to do it in VS2012 so easily though not sure how to do it in Android Studio ?

11 Answers 11

309

I found how and lets share this cool feature with you. I found three cool features:

  1. For multiple selection just hold alt + shift then select whenever you want to change by mouse click then type some thing you can write at multiple places at the same time.

  2. Another cool feature is column selection. This lets you to click in a great manner and greatly of help especially when you are refactoring.

In most systems it works with holding middleMouseButton and dragging over your code and in others it works by holding alt and selecting code it acts like below:

It selects like this

  1. the third cool feature is sublime selection it finds the same word in code and let you change that or append that easily. you can do that by pressing alt + j on Windows / Linux and ctrl + g on mac. Look how it works:

its great for refactoring

Also as @Narayana said in comments, Ctrl + Shift + Alt + j selects all occurrences in one shot, for one-shot refactoring on windows. to do this on mac use Ctrl + Command + G.

7
  • 18
    Cool indeed! Thanks. Also discovered, Ctrl + Shift + Alt + j selects all occurrences in one shot, for one-shot refactoring.
    – Narayana J
    Dec 14, 2017 at 14:26
  • 1
    tnx . ill add it to my answer Dec 19, 2017 at 7:21
  • How undo this option in Mac
    – Savad
    Feb 27, 2020 at 11:32
  • Esc ought to do it. Feb 27, 2020 at 17:07
  • 1
    Control + Command + G for Mac.
    – TJ Olsen
    Apr 14, 2023 at 14:37
36

You can use Alt + Shift and click multiple locations to for multiple cursor.

To select similar occurrences in files use Alt + j.

For more details : Click Here

0
32

Multiline Caret (without mouse)

Windows: CTRL + CTRL(Hold) + ↑ / ↓

Mac: + (Hold) + ↑ / ↓

ESC will end multiline mode.

Change Multi-caret Hotkey

To add a custom Keymap, CTRL+SHIFT+A, type keymap and click on the one with Settings as subtext. Search for Clone Caret Above and Clone Caret Below.

I mapped mine to ALT+SHIFT+↑ / ↓.

Bonus

Try holding combinations of CTRL, SHIFT, and arrows for improved selection power.

2
  • 1
    Thanks, very useful! I mapped my "Clone Caret Above/Below" to CTRL + SHIFT + UP/DOWN, because with ALT as you suggested it's already for moving lines and I use it quite often.
    – Micer
    Sep 25, 2019 at 15:06
  • Mac: ⌘ + ⌘ (Hold) + ↑ / ↓ became ⌥ + ⌥ (Hold) + ↑ / ↓ on Monterey (maybe even earlier?). Jan 14, 2022 at 16:47
24

For both Mac and Windows, just open the Context Menu and click on the "Column selection mode" to enable or disable the behaviour..

enter image description here

1
  • You are my saviour! thanks
    – MUHINDO
    Jan 4 at 21:21
21

On a MacOS you can use:

Tap: Control + Command + G - Select all the same value

Tap: Control + G - Every tap combination select the new same value

Hold: Option + Mouse Click - Select multiline with a mouse

Hold: Option + Shift and Tap: Mouse Click - duplicate cursor for a each tap place

13

Press Shift + Alt + Insert combination to edit in Column selection mode.

4
  • good point. i didnt know that . you can toggle between column selection and normal selection using that Dec 26, 2017 at 8:01
  • 2
    Warning, press Shift + Alt + Insert again to exit edit mode :). In this case a cursor can move up-down in usual way, not over spaces.
    – CoolMind
    Feb 9, 2018 at 16:03
  • @CoolMind Yes I accept your comments. But i would say if column selection mode is enabled that is the expected behavior.
    – vgokul129
    Feb 15, 2018 at 4:44
  • 2
    @vgokul129, thanks. I wrote so because didn't know how to disable this behaviour.
    – CoolMind
    Feb 15, 2018 at 7:07
12

On a mac I like to do ⌥ (option) + shift + mouse click on multiple lines in Android Studio 3.1.3.

4

Use the following:

ALT + SHIFT

1

on Mac , hold OPTION + SHIFT then use the mouse to highlight what you want to select

0

On Windows, you can try a plugin whose name is ConyEdit. It has a great column mode based on regular expression.

0

I'm using android studio arctic fox and pressing Alt alone and then selecting code is working properly in windows.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.