Interface Settings
Appearance & Behavior
Theme Configuration
Adjusting Font and Size for Windows and Menus
You can install your preferred font and select it here.
Enable Memory Indicator Display
IDEA does not show memory usage by default. To enable it, go to Help - Find Actions, search for Show memory indicator, and set it to On:
Result:
Disable Automatic Updates
Keymap
Customize Keyboard Shortcuts
-
Search for the shortcut you want to change, such as code formatting:
-
Double-click it and click Add keyboard Shortcut to customize:
-
Change it to your preferred shortcut and click OK:
Editor
Adjust Font Size with Mouse Wheel (Optional)
Editor -- General
Check this option to use Ctrl + Mouse Wheel to adjust code font size.
Enable Auto Import Functionality
Editor -- General -- Auto Import
Add unambiguous imports on the fly: Automatically import ambiguous structures Optimize imports on the fly: Automatically optimize imported packages
Shortcut: Remove unused imports
Ctrl + Alt + O
Enable Line Numbers and Method Separators
Editor -- General -- Appearance
Check Show line numbers: Display line numbers. This is usually enabled Check Show method separators: Display method dividers. These lines help distinguish methods
Disable Case-Sensitive Suggestions
Editor -- General -- Code Completion
Uncheck Match case Match case is checked by default, which enables case-sensitive suggestions First letter only: First letter All letters: All letters
Disable Single-Line Tabs Display
Editor -- General -- Editor Tabs
When many files are open, IntelliJ IDEA displays all tabs in a single row by default, which hides tabs beyond the visible area, making file navigation inconvenient. Uncheck show tabs in one row:
In Editor Tabs, find tab limit, which is the number of tabs displayed (default 10). After exceeding this number, the earliest opened tabs will be closed. Adjust according to your needs.
Set Default Font, Size, and Line Spacing
Editor -- Font
Modify Font, Size, and Line Spacing for Current Theme (Optional)
Editor -- Color Schema -- Color Schema Font
If the current theme should not use the default font, size, or line spacing, you can set it separately:
Modify Console Output Font and Size for Current Theme (Optional)
Editor -- Color Schema -- Console Font
Change Comment Text Color in Code
Editor -- Color Schema -- Language Defaults
Doc Comment – Text: Change the text color of documentation comments Block comment: Change the text color of multi-line comments Line comment: Change the text color of inline comments
Set Threshold for Import Display as *
Editor -- Code Style -- Java -- Imports
Set Leading Indent for Comments
Editor - Code Style - Java - Code Generation
Uncheck Line comment at first column and check Add a space at line comment start, then click Apply to apply the settings:
Generate Common Code Quickly (Comment Blocks, Main Methods, Variable Declarations, etc.)
Generate Comment Block
Use sbc + Enter to quickly generate a comment block, as shown below:
Generate Main Method
Use main + Enter or psvm + Enter to quickly generate a main method.
Generate System.out.println()
Use sout + Enter to quickly generate the System.out.println() console output method.
Generate TODO Comment
Use todo + Enter to quickly generate a TODO comment.
Generate public static final
Use psf + Enter to quickly generate public static final
Ganerate public static final String
Use psfs + Enter to quickly generate public static final String
Generate public static final int
Use psfi + Enter to quickly generate public static final int
Generate private static final
Use prsf + Enter to quickly generate private static final
Generate Static Method for Singleton
Use geti + Enter to quickly generate a static method for getting the singleton instance, commonly used in implementing the singleton pattern
Generate Private Static Final String
Use key + Enter to quickly generate a private static final string with the prefix KEY_
Generate Private Static Final Integer Varible
Use const + Enter to quickly generate a private static final integer variable
Struggling to remember shortcuts? Use Ctrl + j to quickly bring up the code template menu
Live Templates Code Templates
You may wonder where these quick code snippets are defined. In fact, IDEA has a Live Templates feature that allows you to define various templates. Click File - Settings - Editor - Live Templates - Java to see the built-in code templates in IDEA:
In addition to these built-in templates, you can click the plus sign to add your own code templates, which is very useful.
Custom Live Template
Customize try-catch template code
The try-catch template provided by IDEA is not complete by default. Let's create a custom try-catch template that includes logging the exception. The common exception code is as follows:
-
Click + -> Template Group... to create a new template group, name it MyTemplates, and click OK:
-
After creating, select MyTemplates, click + -> Live Template to create a new code template:
try {
$action$
} catch (Exception e) {
log.error("", e);
$END$
}
Finally, click Apply to apply the settings, which will take effect immediately.
Customize @Autowired Template Code
In Web development, we often need to inject Service through @Autowired in the Controller layer, like the following code:
@Autowired
private UserService userService;
Where
@Autowired
private
is general code that can be extracted into a template. Follow the same steps to define a new Live Template with the shortcut apr.
Configure Class and Method Comment Templates
IDEA's default comment templates do not provide enough detailed information. For classes and methods, we can reconfigure them.
Set Class Comment Template
Editor - File and Code Templates, find the Class template in Files. The header of the template shows an included file named Header.java:
Header.java can be found in Includes. Enter the comment template in the right input box with the following format:
/**
*@Author: harvey
*@Date: ${DATE} ${TIME}
*@Version: v1.0.0
*@Description: TODO
**/
After setting, click Apply to apply and then click OK to close the dialog.
Here, the @Author is hard-coded with my name. It can also be defined as ${USER} to dynamically get the system's current username.
Set Method Comment Template
Refer to another article:
Set Project File and Console Encoding
Editor -- File Encodings
Note: Transparent native-to-ascii conversion is mainly used to convert ascii. It is generally checked, otherwise the comments in Properties files will not display in Chinese. Console encoding will also be set to UTF-8
Set Encoding for Current Source File
You can also modify the encoding of a specific file by clicking the encoding setting area at the bottom right corner.
If the code contains Chinese, a prompt will appear as follows.
① Reload means to reload using the new encoding. The new encoding will not be saved to the file. When you reopen the file, it will still be in the old encoding. ② Convert means to convert using the new encoding. The new encoding will be saved to the file. When you reopen the file, it will be in the new encoding. ③ Converting files with Chinese may result in garbled characters after conversion. Make sure to back up before converting, otherwise there may be issues with garbled characters that cannot be restored.
Version Control
Configure Git in IDEA
Click File - Version Control - Git, and configure the path to Git executable in Path to Git executable. The path is git.exe in the Git installation directory. Once Git is installed successfully, you can see that IDEA automatically identifies the correct path in the configuration box. Normally, no manual configuration is needed. Just click Test button. If the Git version number is printed correctly, the configuration is successful.
Build, Execution, Deployment
Set Auto Compilation
Building involves using our written Java code, framework configuration files, internationalization, other resource files, JSP pages, and images as raw materials to produce a deployable project.
IntelliJ IDEA is not set to auto-compile by default. Eclipse is set to auto-compile by default. Many users switch from Eclipse to IntelliJ, which often leads to forgetting to recompile modified Java class files when operating on class files, thus working on outdated files.
IDEA Maven Configuration
Build, Execution, Deployment -- Build Tools -- Maven
Configure the following three points:
- Maven home path: Set the Maven installation directory;
- User settings file: Select the Maven configuration file;
- Local repository: Set the Maven local repository path, used to store project dependencies;
Plugin
How to Install Plugins in IDEA
Official site: https://plugins.jetbrains.com/
IntelliJ IDEA suports a wide range of plugins. Mastering the use of relevant plugins can effectively improve our development efficiency and user experience. So, how do we install plugins in IDEA? There are two ways:
- Online installation;
- Offline installation;
Online Installation
Click Marketplace plugin market, enter the keyword of the plugin you want to install. Here, One Dark theme is used as an example:
Wait for the plugin to install:
After the plugin is installed successfully, you can view the installed plugins in the Installed list:
Restart IDEA to make the plugin take effect
Note: After installing a plugin, you must restart IDEA for the plugin to take effect.