⌥+⌃AltPlusCtrl

Android Studio Editing and Refactoring Shortcuts

Beyond basic text editing, Android Studio's IntelliJ-platform foundation provides a genuinely powerful refactoring engine that understands code structure semantically rather than just as text, letting several common maintenance tasks happen safely and automatically rather than through risky manual find-and-replace. Extract Method and its inverse, Inline, round out the refactoring toolkit alongside Rename, Reformat, and Optimize Imports, covering the common back-and-forth between pulling code into its own named unit and collapsing it back down when that separation no longer pays for itself.

ActionWindowsMacDescription
Rename (Refactor)Shift+F6Shift+F6Renames the symbol under the cursor everywhere it's referenced throughout the project, not just the current file, inherited directly from IntelliJ's refactoring engine.
Reformat CodeCtrl+Alt+LCmd+Option+LAutomatically reformats the current file's indentation, spacing, and line breaks according to the project's configured code style settings.
Optimize ImportsCtrl+Alt+OCtrl+Option+ORemoves unused import statements and organizes the remaining ones according to the project's import ordering rules, keeping a file's imports section clean without manual review.
Generate code (constructors, getters, overrides)Alt+InsertCmd+NOpens a menu for auto-generating boilerplate code like constructors, getter/setter methods, equals/hashCode implementations, or overriding a superclass method, saving manual typing of repetitive, mechanically-derivable code.
Extract MethodCtrl+Alt+MCmd+Option+MCarves the highlighted lines out into a brand-new method, working out which parameters it needs from the variables the selection actually references. Kotlin gets an extra bit of intelligence here that Java doesn't: if the selected block's last line is an expression, Android Studio infers a sensible return type from it directly, something Java extraction in the same IDE can't do since Java requires an explicit return statement to know a value is even being returned.
Inline variable or methodCtrl+Alt+NCmd+Option+NUndoes an Extract by replacing every place a variable or method gets called with its actual value or body inlined directly, useful for stripping out a layer of indirection that's stopped pulling its weight.
Rename (Shift+F6) is the flagship example of this semantic understanding — renaming a method, class, or variable updates every actual reference to it throughout the entire project, correctly distinguishing your target symbol from other unrelated text that happens to share the same name (a local variable named 'name' in one function versus a completely different, unrelated 'name' variable elsewhere), something a blind text-based find-and-replace could never safely guarantee. Reformat Code (Ctrl+Alt+L / Cmd+Option+L) automatically applies the project's configured code style rules — indentation, spacing, brace placement — to the current file, commonly reached for after pasting in code from an external source with different formatting conventions, or as a final cleanup pass before committing changes to keep the codebase's style consistent across contributors. Optimize Imports (Ctrl+Alt+O) cleans up a file's import statements specifically, removing ones that are no longer actually used (common after deleting code that previously required them) and reordering the remaining imports according to project convention, a small but genuinely time-saving piece of routine maintenance that would otherwise require manual review of every import line. Generate (Alt+Insert / Cmd+N) opens a context-aware menu for auto-generating mechanically derivable boilerplate — constructors matching a class's fields, getter and setter methods, an equals/hashCode implementation, or stub method overrides for an implemented interface or extended superclass — sparing you from typing repetitive code that follows a predictable pattern the IDE can construct correctly on its own. Beyond the four core refactoring shortcuts covered above, Android Studio's IntelliJ-based refactoring menu (accessible via right-click > Refactor, or Ctrl+Alt+Shift+T / Cmd+Option+Shift+T for the full refactor menu) includes several more specialized operations without dedicated single-key shortcuts of their own — Extract Method (pulling a block of code out into its own named method), Extract Variable (naming an inline expression as a variable), and Change Signature (safely adding, removing, or reordering a method's parameters across every call site) among the most commonly used. These are worth knowing exist even without memorizing individual shortcuts for each, since reaching for the Refactor menu by name is often faster than manually performing the equivalent multi-step edit by hand. A good habit when learning Android Studio's refactoring tools: always let Find Usages (Alt+F7 / Option+F7) run to completion and actually review its results before performing a Rename or larger structural refactor on a symbol used in many places, particularly one that might be referenced by test code, XML layout files, or other modules in a multi-module project that a quick visual scan of the main source folder alone wouldn't reveal. Safe Delete, a related refactoring accessible from the same Refactor menu, checks for existing usages of a method, class, or field before deleting it and warns you if removing it would break other code — a safer alternative to simply deleting code manually and discovering the breakage only when the project next fails to compile. Extract Method (Ctrl+Alt+M / Cmd+Option+M) takes a selected block of code and moves it into a newly created method, automatically inferring what parameters that new method needs based on which outside variables the selected code actually references, and replacing the original inline code with a single call to the new method. This is one of the most frequently reached-for refactorings in daily development, commonly used to break an overly long method into smaller, individually named and testable pieces, or to eliminate duplicated logic by extracting it once and calling that extracted method from multiple places instead. Inline (Ctrl+Alt+N / Cmd+Option+N) does the reverse, replacing every call to a variable or method with its actual underlying value or implementation directly at each call site — useful when a previously extracted method or named variable turns out to be used in only one place and no longer justifies the extra indirection, or when reviewing a specific call site benefits more from seeing the actual logic inline rather than needing to jump to a separate definition to understand what's happening. Extract and Inline are natural opposites, and experienced developers move between them fluidly rather than treating either as a permanent decision — extracting a method to clarify a long function's structure, later inlining it back if it turns out to only ever be called from that one place and the separate name adds more indirection than clarity, is a completely normal part of iteratively refining a codebase's structure over time rather than a sign either refactoring was applied incorrectly the first time.