Discover Intellij IDEA for Scala
To start working with Scala in IntelliJ IDEA you need to download and enable the Scala plugin (by default it is not bundled with IntelliJ IDEA). Since you've already installed and launched IntelliJ IDEA, you can select on the welcome screen or you can Ctrl+Alt+S access settings and in the search field type Plugins to open the Plugins page. Select Browse Repositories and in the search field type "Scala". On the right-hand side click "Install", you can also read the short description of what the plugin includes. Moreover, after the installation IntelliJ IDEA keeps track of the plugin updates and will suggest you to update the plugin when the a new version is available. You can access the Scala plugin page, and check Scala nightly, EAP and release builds.
The IntelliJ IDEA Editor is special in a number of ways, most notable being is that you can invoke almost any IDE feature without leaving it, which allows you to organize a layout where you have more screen space because auxiliary controls like toolbars and windows are hidden.
Accessing a tool window via its shortcut moves the input focus to it, so you can use all keyboard commands in its context. When you need to go back to the editor, pressEscape.
Below is a list of shortcuts that invoke the tool windows you will most often need:
When you want to focus on the code, try the Distraction Free Mode. It removes all toolbars, tool windows, and editor tabs. To switch to this mode, on the main menu select View | Enter Distraction Free Mode.
An alternative to the Distraction Free Mode may be hiding all tool windows by pressing Ctrl+Shift+F12. You can restore the layout to its default by pressing this shortcut once again.
Most components in IntelliJ IDEA (both tool windows and pop-ups) provide speed search. This feature allows you to filter a list, or navigate to a particular item by using a search query.
Since in IntelliJ IDEA you can undo refactorings and revert changes from Local History, it makes no sense to ask you to save your changes every time.
The most useful Editor shortcuts are:
|Move the current line of code||Ctrl+Shift+Up Ctrl+Shift+Down|
|Duplicate a line of code||Ctrl+D|
|Remove a line of code||Ctrl+Y|
|Comment or uncomment a line of code||Ctrl+Slash|
|Comment a block of code||Ctrl+Shift+Slash|
|Find in the currently opened file||Ctrl+F|
|Find and replace in the current file||Ctrl+R|
|Navigate between opened tabs||Alt+Right Alt+Left|
|Navigate back/forward||Ctrl+Alt+Left Ctrl+Alt+Right|
|Expand or collapse a code block in the editor||Ctrl+NumPad Plus Ctrl+NumPad -|
|Highlight usages of a symbol||Ctrl+F7|
To expand a selection based on grammar, pressCtrl+W. To shrink it, press Ctrl+Shift+W.
IntelliJ IDEA can select more than one piece of code at a time. You can select/deselect any piece of code via Alt+J, or by clicking a code selection and pressing Shift+Alt+J.
For more details, refer to Editor.
When you access Basic Completion by pressingCtrl+Space, you get basic suggestions for variables, types, methods, expressions, and so on. When you call Basic Completion twice, it shows you more results, including private members and non-imported static members.
The Smart Completion feature is aware of the expected type and data flow, and offers the options relevant to the context. To call Smart Completion, press Ctrl+Shift+Space. When you call Smart Completion twice, it shows you more results, including chains.
To let IntelliJ IDEA complete a statement for you, pressN/A. Statement Completion will automatically add the missing parentheses, brackets, braces and the necessary formatting.
If you want to see the suggested parameters for any method or constructor, press Ctrl+P. IntelliJ IDEA shows the parameter info for each overloaded method or constructor, and highlights the best match for the parameters already typed.
The Postfix Completion feature lets you transform an already typed expression to another one, based on the postfix you type after a dot.
For more details, refer to Auto-Completing Code.
Most of the time you work with a finite set of files, and need to switch between them quickly. A real time-saver here is an action called Recent Files invoked by pressing Ctrl+E. By default, the focus is on the last accessed file. Note that you can also open any tool window through this action:
Navigate to Class is available by pressing Ctrl+N and supports sophisticated expressions, including camel humps, paths, line navigate to, middle name matching, and many more. If you call it twice, it shows you the results out of the project classes.
When you are not switching between files, you are most probably navigating within a file. The simplest way to do it is to pressCtrl+F12. The pop-up shows you the structure of a file, and allows you to quickly navigate to any of them:
Navigation shortcuts include:
|Search everywhere||Double Shift|
|Navigate to class||Ctrl+N|
|Navigate to file||Ctrl+Shift+N|
|Navigate to symbol||Ctrl+Shift+Alt+N|
|Navigate to declaration||Ctrl+B|
|Navigate to type hierarchy||Ctrl+H|
|Show UML pop-up||Ctrl+Alt+U|
For more details, refer to Navigating Through the Source Code.
IntelliJ IDEA offers a comprehensive set of automated code refactorings that lead to significant productivity gains when used correctly. Firstly, don't bother selecting anything before you apply a refactoring. IntelliJ IDEA is smart enough to figure out what statement you're going to refactor, and only asks for confirmation if several choices are possible.
|Extract a constant||Ctrl+Alt+C|
|Extract a method||Ctrl+Alt+M|
|Extract a parameter||Ctrl+Alt+P|
For more details, refer to Refactoring Source Code.
Find Usages helps you quickly find all pieces of code referencing the symbol at the caret (cursor), no matter if the symbol is a class, method, field, parameter, or another statement. Just press Alt+F7 and get a list of references grouped by usage type, module, and file.
For more details, refer to Finding Usages.
Most inspections not only tell you where a problem is, but also provide quick fixes to deal with it right away. Press Alt+Enter to choose a quick fix.
Inspections that are too complex to be run on-the-fly are available when you perform code analysis for the entire project. You can do this in one of the following two ways: by selecting from the main menu, or by selecting to run an inspection by its name.
Note that while inspections provide quick-fixes for code that has potential problems, intentions help you apply automatic changes to code that is correct. To get a list of intentions applicable to the code at the caret, pressAlt+Enter.
For more details, refer to Code Inspection.
Code style and formatting
IntelliJ IDEA automatically applies a code style you've configured in the Code Style settings as you edit, and in most cases you don't need to call the Reformat Code action explicitly.
Useful formatting shortcuts:
Note that by default, IntelliJ IDEA uses regular spaces for indents instead of tabs. If you have files with lots of indents, you may want to optimize their size by enabling the Use tab character option in the Java code style settings.
For more details, refer to Reformatting Source Code.
Version control basics
To check out a project from a Version Control System (VCS), click Checkout from Version Control on the Welcome Screen , or in the main menu.
To quickly perform a VCS operation on the current file, directory, or an entire project, use the VCS operations pop-up by pressing Alt+Back Quote
Once you've configured the VCS settings, you'll see the Version Control tool window. You can switch to it anytime by pressingAlt+9.
The Local Changes tab of the Version Control tool window shows your local changes: both staged and unstaged.
Useful VCS shortcuts:
|Version Control tool window||Alt+9|
|VCS operations pop-up||Alt+Back Quote|
For more details, refer to Version Control with IntelliJ IDEA.
Note that for multiple repositories, IntelliJ IDEA performs all VCS operations on all branches simultaneously, so you don't need to switch between them manually.
Shelves, stashes and patches help you when you need to store some of the local changes without committing them to the repository. You can then switch to the repository versions of the files, and then come back to your changes later.
For more details, refer to Managing Branches.
Running and debugging
Once you've created a Run/Debug configuration by selecting from the main menu, you are able to run and debug your code.
When in the debug mode, you can evaluate any expression by using the Evaluate expression tool, which is accessed by pressing Alt+F8. This tool provides code completion in the same way as in the editor, so it's easy to enter any expression.
|Smart step into||Shift+F7|
If you want to "rewind" while debugging, you can do it via the Drop Frame action. This is particularly helpful if you mistakenly stepped too far. This will no revert the global state of your application, but will at least let you revert to a previous stack frame.
Reloading changes and hot swapping
Sometimes, you need to insert minor changes into your code without shutting down the process. Since the Java VM has a HotSwap feature, IntelliJ IDEA handles these cases automatically when you call Make.
To deploy your application to a server:
- Configure your artifacts by selecting (done automatically for Maven and Gradle projects).
- Configure an application server by clicking the page of the Settings/Preferences dialog.
- Configure a run configuration by selecting , then specify the artifacts to deploy and the server to deploy them to.
For more details, refer to Working with Application Servers.
Working with build tools (Maven/Gradle)
Once you've imported/created your Maven/Gradle project, you are free to edit its
build.gradle files directly in the editor. Any changes to the underlying build configuration will eventually need to be synced with the project model in IntelliJ IDEA.
If you want the IDE to synchronize your changes immediately, do the following:
pom.xmlenable the Import Maven projects automatically option in (Windows and Linux) or (macOS).
build.gradle, enable the Use auto-import option in of the Settings/Preferences dialog.
For manual synchronization, use the corresponding action on the Maven/Gradle tool window toolbar: .
Note that any goal or task can be attached to be run before a run configuration.
For more details, refer to Build Tools.