58

I've just moved from Eclipse to Android Studio and am finding really weird behaviour when I try to do Ctrl+Z / Ctrl+Y to undo/redo code changes.

It hard to describe what happens exactly, but the end result is that I usually end up just losing my code and having to type it back in from memory...

The 'undo' and 'redo' buttons in the IDE do seem to work fine, so maybe something is wrong with my shortcut keys (which would be surprising as I should just have a standard installation / setup).

Can anyone advise what to do, so Ctrl and Z / Ctrl+Y will work in the expected manner.

Andrii Omelchenko
  • 13,183
  • 12
  • 43
  • 79
ban-geoengineering
  • 18,324
  • 27
  • 171
  • 253
  • 1
    possible duplicate of [how to configure intelliJ redo action for CTRL+Y instead of CTRL+Shift+Z](http://stackoverflow.com/questions/25244475/how-to-configure-intellij-redo-action-for-ctrly-instead-of-ctrlshiftz) – admdrew Aug 31 '15 at 19:54
  • 3
    Why you didn't researched 1 minute more that was the time to post an answer on your own question?.... – Skizo-ozᴉʞS ツ Aug 31 '15 at 19:55
  • 5
    It wasn't obvious to me that Android Studio is similar (or same as?) intelliJ. I'm sure I'm not the only one who wasn't aware of the similarity, so I'm sure other people will have the same question as I did and not know about intelliJ. – ban-geoengineering Aug 31 '15 at 19:57
  • 1
    @ban-geoengineering the description of the android-studio tag states "Android Studio is an official IDE targeted at Android development, based on IntelliJ IDEA from JetBrains". – admdrew Aug 31 '15 at 19:58
  • 1
    What I said in my previous message is still correct. – ban-geoengineering Aug 31 '15 at 20:00
  • 2
    ...i.e., I wasn't aware of that and nor, I suspect, will some others be. – ban-geoengineering Aug 31 '15 at 20:06
  • 2
    @ban-geoengineering I have been hit by this myself. Most programs use Ctrl-Y as an easy shortcut to Redo, but some _idiots who think they know better than everyone else_ make Ctrl-Y delete lines _([an outdated shortcut from the 1980s](https://en.wikipedia.org/wiki/Control-Y) irrelevant in the 21st century)_ **If you tried to redo what you just undid and found yourself deleting lines and panicking, you can minimize your loss by undoing the "delete line" action. But unfortunately, you will have to manually "redo" from memory what you undid.** And be sure to remap that damn keyboard shortcut. – ADTC Oct 15 '17 at 23:08

5 Answers5

152

With the help of this answer, I have worked it out...

  1. Go into Settings (Ctrl+Alt + S)
  2. Type Redo in the search box.
  3. Double-click on the Redo result
  4. Select Add Keyboard Shortcut
  5. Press Ctrl+Y
  6. Click OK
  7. Click OK
Rob
  • 26,989
  • 16
  • 82
  • 98
ban-geoengineering
  • 18,324
  • 27
  • 171
  • 253
  • 16
    My answer is better as it is quicker. Plus it is a valid because it's correct. If you don't like the question, then you should just downvote the question. – ban-geoengineering Aug 31 '15 at 19:59
  • 3
    upvote too... some users on stackoverflow just hate for the sake of hating now.... – yeahman Mar 11 '18 at 15:45
13

To undo an action, do one of the following:

  • On the menu bar, choose Edit -> Undo.
  • Press Ctrl+Z

To redo an action, do one of the following:

  • On the menu bar, choose Edit -> Redo.
  • Press Ctrl+Shift+Z
M Imam Pratama
  • 998
  • 11
  • 26
Areeb Mahmood
  • 131
  • 1
  • 2
8

ctrl+Y deletes line by default in Android. If you want to change this behaviour, go to Keymap under Settings and set your desired shortcut for Redo action

By the way, the same question: how to configure intelliJ/Android Studio redo action for CTRL+Y instead of CTRL+Shift+Z

Community
  • 1
  • 1
Vitaly Zinchenko
  • 4,871
  • 5
  • 36
  • 52
7

You can try this one. It is simple and default:
(CTRL + Z) This is for undo.
Just press (CTRL + SHIFT + Z) for redo.
(CTRL + Y) it has individual task. So it would be better if you don't bother this one.

1. CTRL + Z -> Undo
2. CTRL + SHIFT + Z -> Redo
3. CTRL + Y -> Delete line

Happy Coding

Mafujul
  • 1,090
  • 10
  • 15
0

CTRL + Z works fine and undo the work but CTRL + Y is a bit messy combo. Unlike most software CTRL + Y here doesn't mean redo but its infact a shortcut to delete the entire line, hence you loose your code.
So if you wanna REDO use CTRL + SHIFT+Z(as already told above) or change keymapping.

Dwhitz
  • 1,250
  • 7
  • 26
  • 38