Reputation: 9415
Is it possible to enable some option to fold or collapse groups of import statements in java code using vscode?
Are there any extensions that do this job?
Upvotes: 27
Views: 8744
Reputation: 1328602
As an alternative, consider VSCode 1.59 (Juil. 2021), which includes:
Automatically Fold Imports
Use the setting
editor.foldingImportsByDefault
to have import statements automatically folded.The fold state is stored once a file has been opened once.
The feature works with TypeScript, JavaScript, Java, C# and C++ and with all language that have a folding range provider that annotates
import
statements withFoldingRangeKind.Imports
.
Upvotes: 45
Reputation: 1776
I use the VS Code extension "Language Support for Java" from Red Hat (redhat.java
) which comes bundled in the "Java Extension Pack" from Microsoft (vscjava.vscode-java-pack
). With this extension there are many ways to fold various parts of my code, including the import statements.
Next to the import statements I have a little carrot symbol that toggles the folding of the import statements.
VS Code also ships with a large selection of customizable commands for folding and unfolding code. You can explore the list your self at
`Manage` (the gear icon in the bottom left) -> `Keyboard Shortcuts` -> Search for "fold".
(CTRL
+ K
+ CTRL
+ S
also brings up this same menu).
Upvotes: 1