IntelliJ IDEA 2024.1 Help

Use AI in editor

Generate code in editor

Generate code and use prompts right in the editor.

  1. Place the caret anywhere in the editor and press Ctrl+\.

    Alternatively, right-click to open the context menu, select AI Actions and then Generate code.

  2. In the input field, write your prompt and press Enter.

    Input field in the editor
  3. The generated code opens in a separate AI Diff tab. Wait for the generation to complete. In the upper-right corner, select Unified or Two-Side view to review the suggested changes.

    Generated code in diff tab
  4. If you want to improve the generated code, click Specify, add new requirements, and press Enter.

    New requirements to update the generated code

    AI Assistant will regenerate the code while taking into account the new specifications.

    If you want to regenerate the answer, click Regenerate.

  5. Click Accept to insert the generated fragment to the rest of the code. Otherwise, close the diff viewer to skip code generation.

Enable name suggestions

When you rename (Shift+F6) 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.

  1. Press Ctrl+Alt+S to open the IDE settings and then select Tools | AI Assistant.

  2. Select the Provide AI-generated name suggestions checkbox.

    Enable name suggestion option in AI Assistant settings

Invoke inline code completion

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.

  1. 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.

    AI-generated code suggestion
  2. To apply the suggested code, press Tab.

    To reject the suggestion, press Escape. Alternatively, just continue to write your own code.

Last modified: 24 April 2024