Friday, 19 August 2016

Android Studio Shortcuts - II


We spend a lot of time navigating in our code base, let’s try to do it more efficiently.
Open class
cmd+o (Mac)
ctrl+n(Linux)
Imagine that you must go to a class named “MainActivity”, just use this shortcut and start typing “MainA”.
Open File
cmd+shift+o (Mac)
ctrl+shift+n(Linux)
Works like the “Open Class” shortcut but on every files in your project. It is very useful to open your AndroidManifest.xml or anything that sits in the res/ or assets/ folder.
Open Symbol
cmd+alt+o (Mac)
alt+shift+n(Linux)
A very powerful but little less known variation of the previous tips: You can use this to go directly to a method or field by searching its name!
For example, if you know that you have a method named getFormattedDate() somewhere in your project, you can type it in the Open Symbol dialog to go directly to it.
Partial Matching
You can enter incomplete strings and it will work. For example. if you are searching for a class named “ItemDetailFragment”, you can actually type “IDF” and it will find it.
Line Number
Imagine that your colleague just told you that the juicy part is in ExcitingClass at line 23. You can open the file directly by appending a “:” to the class name in the Open Class dialog. e.g.:
ExcitingClass:22
You can also combine it with partial matching and type something like:
EC:22
Recently opened files
cmd+e     (Mac)
ctrl+e   (Linux)
This will show a popup listing the files you navigated to previously.
Recently edited files
cmd+shift+e(Mac)
ctrl+shift+e(Linux)
Same as the above but listing only files that have been edited.

Navigate Back/Forward

cmd+alt+left/right (Mac)
ctrl+alt+left/right(Linux)
To understand this shortcut, think about how the back and forward buttons work in a web browser. Now, instead of thinking in web pages, think about source code! So when you drill down in code or open a new file, the IDE will remember where you where before, allowing you to quickly go back.

Last Edit Location

cmd+shift+backspace (Mac)
ctrl+shift+backspace(Linux)
This is a variation on the “Navigate Back” shortcut that cycles between the locations where you typed something.
Picture yourself fixing a nasty bug. You think you have the solution so you start fixing it but then realize that you have to look at the android source code and a couple other classes in your project. You enter a function, which leads you to another class, which leads you to another thing and 20 steps later, you finally have the insight needed to complete your fix… but in which file and at what line where you again? Just use this shortcut and you are right back at the exact line where you stopped writing.

 

Ref: http://www.developerphil.com/android-studio-tips-of-the-day-roundup-5/

No comments:

Post a Comment