“Focus On What Matters”
When working in our IDE, at times it’s easy to become overwhelmed with all the code on the screen. To better focus on what’s most important, it can be useful to hide non-essential blocks of code from our editor window.
The Code Folding shortcuts in Android Studio help us do just that.
The allow us to fold Code Blocks & Region Blocks so we can have more fine grained control over what code we are looking at in any given moment.
Shortcuts
The expand & collapse shortcuts allow us to quickly show or hide code blocks or code regions.
We can expand all or collapse all by adding shift to the shortcuts above.
Code Blocks
We can take an expanded block of code like this anonymous inner class
and collapse it within the IDE, using the collapse shortcut, so it visually looks like this.
We lose the immediate view of the code, but if that code is not relevant to us in this moment, then it can actually help reduce the visual noise in our IDE.
To collapse a specific block of code, place your cursor within the block and execute the shortcut.
If you run the shortcut multiple times, the IDE may continue to collapse blocks of code in increasing scope until everything in the current file is collapse. The same logic applies when expanding code as well.
Region Blocks
We can define custom region blocks using comments. These regions can be helpful for documenting & group related sections of code; such as the implementation of an interface.
Using the collapse command, we can collapse the entire region so only the region label is visible within our editor.
For more on code folding, check out my video on YouTube
I love to talk Android, tech, or geekery, so if you have feedback or want to chat you can follow me on Twitter, here on dev.to, or check out my blog
Top comments (2)
//region ${ Your Comment }
....
....
//endregion
This way of "Code folding" is best way to fold as:
You can use this in Visual Studio for C# as well.
And, Thanks Nate : for gathering all these Tips/hacks at one place.
Thanks Nate