In the previous part of this series, we looked at some shortcuts for refactoring our code and for doing some miscellaneous things. In this part, we are going to learn shortcuts for navigation in our code/files. Let’s get started
- Navigate to Class(Ctrl+N): Pressing Ctrl+N anywhere in Android Studio allows you to search and navigate to any type, interface, enumeration, etc. in your project. Just start typing the name of type or enumeration etc. after pressing the keyboard shortcut and Android Studio will present you with a list of matching cases.
- You can also supply a line number with the search term if you want, to move to a specific line in that file.
- Android Studio also supports camel case searching which can save a little more of your time.
- Navigate to File(Ctrl+Shift+N): Pressing Ctrl+Shift+N anywhere in Android Studio allows you to search and navigate to any file in your project; for ex. navigating to xml files in your Android Project.
- Navigate to a line(Ctrl+G): If you want to move to a particular line in your file, then press Ctrl+G in the file and enter the line number that you wish to move to in the dialog and Android Studio will take you directly to that line. You can additionally supply a column number if you want to place caret at a pinpoint location.
- Navigate to Recent files(Ctrl+E): Press Ctrl+E to view your recently visited files and navigate to them.
- Navigate to Recently edited files(Ctrl+Shift+E): Sometimes you are working on multiple files at one time and constantly need to switch between them, in such a case you can view your recently edited files by pressing Ctrl+Shift+E and quickly navigate to them, saving you a lot time.
- Search Everywhere(Shift+Shift): As the name suggests this shortcut searches everywhere in Android Studio. It will find all the occurrences of the thing that you are looking for and all the things that are related to it in the whole project which is why it is slower and consume more resources than the other specific search options.
- Move between methods(Alt+up/down arrow keys): If you wish to move to a previous/next method in your code from anywhere, then pressing Alt+up/down arrow keys respectively can do that for you.
Additional tip: Holding down Ctrl key and pressing up/down keys will scroll the current file without moving the cursor from it’s position.
- Last edited location(Ctrl+Shift+Backspace): Suppose while writing/refactoring code, another high priority task comes in your way which requires you to work in another part of the code. Wouldn’t it be nice if we can just move to the location of previous work after finishing the high priority task. Turns out, pressing Ctrl+Shift+Backspace will automatically move the caret to the previously edited location. Pretty cool! right?
- Move between Tabs(Alt+left/right arrow keys): If you have tabs activated in Android Studio then you can use Alt+left/right arrow keys to move between them. This shortcut works for any window that have tabs in Android Studio. You can also set shortcuts for closing a tab and reopening a closed tab to have a little more control over tabs.
- Navigate to implementation(Ctrl+Alt+B): You can find all implementations of a method in you class, interface or abstract class by placing the caret at the method name and pressing Ctrl+Alt+B. Android Studio will show you a list of all implementation and you can select the one that you want to go to.
- Navigate to declaration(Ctrl+B): Place the cursor at the name of the variable or method etc. and press Ctrl+B to move to it’s declaration.
- Navigate to super class/method(Ctrl+U): Place your cursor at the method name or class name and press Ctrl+U to move to the super class or super method.
- Move to next/previous highlighted error(F2/Shift+F2): This is a super helpful shortcut which will automatically move the caret to the next/previous error in the file. Pressing F2 will move to the next highlighted error and pressing Shift+F2 will move to the previous highlighted error. No need to manually find those annoying errors in your big files.
- File Structure(Ctrl+F12): This will show a list of all the methods implemented in your class. This is very helpful if you want to move to a particular method. Just start typing the name of the method on the dialog and Android Studio will automatically filter the list matching your search term. If the specified method is not found in the current class then Android Studio will search for the method in the super class.
- Move to Beginning/End of file: This is kind of a known shortcut which is present in almost all editors. Just like Home takes you to the beginning of the line and End takes you to the end of the line, pressing Ctrl+Home will take you to the beginning of the file and pressing Ctrl+End will take you to the end of the file.
Navigate between windows
- Project Window(Alt+1): If you want to browse files in your project then you can move to project window by pressing Alt+1.
- If you want to navigate to a file/directory, just start typing the name of file/directory in project window and Android Studio will highlight the name of the matching file/directory if that file/directory is visible in the project window.
- If you want to create a new file, then select the directory in the project window under which you want to create new file and press Alt+Insert to show a list of different file types that you can create.
- Android Monitor(Alt+6): You can go to Android Monitor by pressing Alt+6. This window is automatically shown when you run your app but if it doesn’t then you can use this shortcut to show it.
Additional tip: Press Shift+F10 to run your app.
- Version Control Window(Alt+9): If you have your project under Version Control System like Git, then you can press Alt+9 to move to the Version Control Window.
Additional tip: You can use Alt+left/right arrow keys to move between tabs in this window.
- Debug Window(Alt+5): Press Alt+5 to show the debug window while debugging your app. This window can only be shown if you are currently debugging your app.
Additional tip: Press Shift+F9 to debug you app.
- Project Structure Window(Alt+7): You can view the structure of your file by going to this window. Press Alt+7 to show this window. You can also search for things in your file in this window by start typing it’s name and Android Studio will highlight the cases that match your search term.
- Hide/Restore all Windows(Ctrl+Shift+F12): If you feel like there are lots of open windows in Android Studio, leaving a very little space for you to edit your code, then pressing Ctrl+Shift+F12 will hide all of those windows leaving only the editor on the screen. When you are done editing your code or you wish to view those windows, pressing the same shortcut again will restore all those windows on the screen.
- You can move to the editor anytime from any window by pressing the Escape key.
- You can increase/decrease size of any window by using Ctrl+Shift+left/right arrow keys or Ctrl+Shift+up/down arrow keys depending on the direction that window can be resized.
- To close a window, use the same key combination that you used to open that window.
That’s it for this part! I hope you enjoyed reading this and learned something new today. If you liked it then please share and recommend it.