Use AI in editor
This functionality relies on the AI Assistant plugin that requires an additional license.
For more information about licensing and enabling AI Assistant, refer to JetBrains AI Service licensing and Enable AI Assistant plugin.
Generate code and use prompts right in the editor.
Select a piece of code that you want to modify or place the caret anywhere in the editor and press Ctrl0\.
Alternatively, right-click to open the context menu, select AI Actions and then Generate code.
note
If you select a piece of code and invoke the code generation action, AI Assistant will only suggest changes for the selected piece of code.
If you place the caret anywhere in the editor before invoking the code generation action, AI Assistant will insert the generated code in the editor at the caret.
In the input field, write your prompt and press Enter.
The generated code opens in a separate AI Diff tab. Wait for the generation to complete. In the upper-right corner, select the way you want to review the suggested changes:
The Unified view shows the results in one editor.
The Two-Side view shows the results in two editors. The left side displays the original code. The right side displays the code with the suggested changes.
All changes are marked with different colors. Read more on how IntelliJ IDEA displays the changes in Compare files, folders, and text sources.
If you want to improve the generated code, click Specify, add new requirements, and press Enter.
AI Assistant will regenerate the code while taking into account the new specifications.
If you want to regenerate the answer, click
Regenerate.
Click Accept all to insert the generated fragment to the rest of the code.
To accept only part of the suggested changes, click
Accept in the Two-Side view or
Accept in the Unified view on the line with the desired changes.
Otherwise, close the AI Diff tab to discard all changes.
When you rename (ShiftF6) a symbol, AI Assistant suggests name options for it based on its contents.
This feature is enabled by default. To switch it on and off, check the AI Assistant settings.
Press CtrlAlt0S to open settings and then select Tools | AI Assistant.
Use the Provide AI-generated name suggestions checkbox.
AI Assistant can autocomplete single lines, entire functions, and even blocks of code in real time based on the project's context. The generated code is similar to how you would write code, matching your style and naming conventions.
While working on your code, press Enter to start a new line and wait for a few seconds to get a suggestion.
The suggested code will be shown in gray font.
To apply the suggested code, press Tab.
To reject the suggestion, press Esc. Alternatively, just continue to write your own code.
To disable the inline code completion, go to Settings | Tools | AI Assistant and clear the Enable automatic inline code completion as you type checkbox.
Thanks for your feedback!