Navigate to Nested File
Sometimes you have a couple of files that have the exact same name but are in different directory. E.g. many AndroidManifest.xml in different modules.
So when you try to navigate to a file, you get a bunch of results and have to think which one you need.
By prefixing a portion of the path and adding a slash to your search query, you can get the right one on the first try.
Mac: Cmd+O, then type it!
Windows/Linux: Ctrl+N, then type it!
|Navigate to Nested File|
Open File Externally
With this shortcut, you can open your file navigator to the current file or any of its parent folder simply by clicking on its tab.
Shortcut (on a file tab):
|Open File Externally|
When you do a find in files, invoking the autocomplete shortcut will suggest words that are in the current file.
Mac: Cmd+F , type something and autocomplete
Windows/Linux: Ctrl+F, type something and autocomplete
This will cycle through all changes in the current file. The changes are based on the previous version of the file currently under source control.
A nice thing about this shortcut is that it will also open a bubble showing the previous value and allowing you to:
Revert to the old value
Show a side by side diff
Copy the old value to the clipboard
If you want to open this popup using the mouse, you can also click the blue bar in the gutter.
Next Highlighted Error
When there are a couple of errors and warnings in a file, you can quickly cycle through them using this shortcut. Very useful when you have a couple errors in a file or if you are resolving merge conflicts by hand (the “<<<<<<<” thing in the middle of a java file is an error right!)
By default it won’t make a difference between a warning and an error. If you want to prioritize errors, you can set it in Preferences → Editor → Error Highlighting → ‘Next Error’ action goes to high priority problems only. Once all errors are cleared, it will cycle through warnings.
|Next Highlighted Error|
Sometimes you auto complete a boolean and then you go back to the beginning to add a “!” in front of it to negate it.
Turns out that that you can skip that part by pressing the “!” key instead of the enter key to auto-complete it.
Shortcut (during code completion on a boolean)
Smart Type Completion
Code completion is already pretty smart right? Well it turns out that there is a shortcut for something even smarter. If you invoke it, it will try to complete only with parameters that have business being there. So when you complete for a method parameter, it will only show objects that fit the signature.
– If you invoke the shortcut a second time, it will search the project for chained method calls. Meaning that it could be a method on an object in the current scope or even calling a static method on a factory object. Pretty useful to autocomplete a Context.
|Smart Type Completion|
Following in my streak of extract refactoring, here is the one to extract a code block in a new method.
This thing is extremely useful. Whenever you encounter a method that is starting to become a bit complex, you can use this to safely extract a portion in another method. I say safely because the IDE won’t make a silly copy-paste mistake like we might do.
– Once you are in the extracting dialog, you can change the visibility of the method and the parameter names.
Compare With Branch (Git)
Assuming that your project is under Git, you can compare the current file or folder with another branch.
Pretty useful to get an idea of how much you have diverged from your main branch.
Menu : VCS -> Git -> Compare With Branch
Find Actions: Compare With Branch
|Compare With Branch (Git)|
Enable column selections, also known as block selection.
Basically, if you select down, it will go down and not bother wrapping to the end of the line.
This will also put a cursor after each line of the block selection from where you can type.
Mac : Cmd+Shift+8
I want to credit this article