Use AI in editor
Ask AI Assistant to generate code or start a chat
Generate code using prompts right in the editor or start a chat with AI Assistant.
Generate code in editor using prompts
Select a piece of code that you want to modify or place the caret anywhere in the editor and press Ctrl+\.
Alternatively, right-click anywhere in the editor to open the context menu, select AI Actions and then Ask AI Assistant.
In the input field, write your prompt and press Enter.
Wait for the generation to complete. The generated code will be shown in the same editor tab where you have invoked the input field.
All suggested changes are marked with different colors.
If you want to improve the generated code, in the same input field, write a follow-up message with the 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 or press Ctrl+F5.
Click Accept to insert the generated fragment.
If you want to revert some of the suggested changes, in the gutter, click
Revert.
To discard all the suggested changes, click Discard in the input popup.
You can use the input field the same way as the AI Assistant chat to ask programming-related questions, invoke the /explain
and /refactor
commands, or reference a particular file or function in your query with #
to provide more context.
For more information about the AI Assistant chat features, refer to Chat with AI.
Get help with name suggestions
When you rename (Shift+F6) a symbol, AI Assistant suggests name options for it based on its contents.
![AI-generated rename suggestions AI-generated rename suggestions](https://resources.jetbrains.com/help/img/idea/2024.2/cl_aiassist_renamesuggestions.png)
This feature is enabled by default. To switch it on and off, check the AI Assistant settings.
Press Ctrl+Alt+S to open settings and then select
.Use the Provide AI-generated name suggestions checkbox.
Invoke AI-powered code completion
Cloud completion powered by AI Assistant can autocomplete single lines, blocks of code, and even entire functions in real time based on the project context. The generated code is similar to how you would write code, matching your style and naming conventions.
Work with cloud completion in the editor
The suggestions are shown in the editor as you type.
You can also trigger the code completion by pressing Alt+Shift+\.
To apply the suggestion:
Press Tab to accept the entire suggestion. You can configure a different shortcut for this action.
Press Ctrl+Right to accept a suggestion word by word.
Press End to accept a suggestion line by line.
To reject the suggestion, press Escape. Alternatively, just continue to write your own code or change the caret position either with the arrow keys or by a mouse click.
Configure cloud completion
The cloud completion option is enabled by default. You can configure the way it works in the settings.
Press Ctrl+Alt+S to open settings and select Editor | General | Inline Completion.
Available options to configure:
Under the Enable cloud completion suggestions checkbox, select the languages that you want to use cloud completion with.
Clear the Enable multi-line suggestions checkbox to leave only single-line suggestions.
To disable this option completely, clear the Enable cloud completion suggestions checkbox on the same settings page or in .
Change the cloud completion shortcut
You can change the default cloud completion shortcut that you use to accept suggestions.
Hover over the suggestion.
In the popup that appears, click
and select the key that you want to use for accepting suggestions, for example, Right.
To assign your own shortcut, select Custom.
You can also change any code completion shortcuts in the
anytime.