Get familiar with the editor environment

ActionDescription
⌃`⌃`⌃`⌃`⌃`Press this shorcut to quickly switch schemes, keymaps, or view modes.

In the Switch menu, select your option and press . Use the same shortcut to undo your changes.

You can also find and adjust the color scheme settings in File | Settings/Preferences | Editor | Color Scheme and the keymap settings in File | Settings/Preference | Keymap.
⇧⌘F12⇧⌘F12⇧⌘F12⌃⇧F12⌃⇧F12Press this shortcut to maximize editor pane.
⎋, ⎋Press this shortcut to return to an active editor from other windows.
⌥F12⌥F12⌥F12⌥F12⌥F12Press this shortcut to return to an editor from the command-line terminal. However, note that in this case IntelliJ IDEA closes the terminal window.

To keep the terminal window open when you want to switch back to an active editor, press ⌃⇥⌃⇥⌃⇥⌃⇥⌃X, B.
⇧⌘F12⇧⌘F12⇧⌘F12⌃⇧F12⌃⇧F12Press this shortcut to hide all windows. In this case only the editor you currently work in is open.
⇧F12⇧F12⇧F12⇧F12⇧F12Press this shortcut to return to a default layout. In this case IntelliJ IDEA hides the Project tool window. However, you can select Window | Store Current Layout as Default from the main menu to save the current layout you are working in as default and use the same shortcut to restore it.
F12F12F12Press this shortcut to jump to last active window you have used.

Navigate inside the editor

Line numbers

Action / Access

To find any action in the editor, press ⇧⌘A⇧⌘A⌘3⌃⇧A⌃⇧A.

Description
Show line numbersTo permanently show line numbers in the editor, select File | Settings/Preferences | Appearance and from the options on the right, select this option. You can also assign a shortcut to the Show line numbers action.
⌘L⌘G⌘L⌃G⌥GPress this shortcut to navigate to a specific line or a column in the editor. In the dialog that opens, specify the line or column number and click OK.

Cursor position and edit location

Action / AccessDescription
⌃⇧Q⌃⇧Q⌃⇧Q⌥Q⌥QPress this shortcut to find current cursor location in the editor. It might be helpful if you have a large project and do not want to scroll through the file.
⌘[⌥⌘←⌘[⌃⌥←⌃⌥←Press this shortcut to find a previous cursor position.
⇧⌘⌫⇧⌘⌫⌃Q⌃⇧F2⌃⇧⌫.Press this shortcut to navigate to the last edited location.
⇧⌘E⇧⌘E⇧⌘E⌃⇧E⌃⇧EPress this shortcut to show the list of recently edited files.

Lens mode

To make the lens mode in the editor available on a mouse hover, right-click the code analysis marker located on the right side of the editor and from the context menu select the Show code lens on the scrollbar hover option.

Alternatively, you can perform the following steps:

  1. Press ⌘,⌘,⌘,⌥F7⌃⌥S to open the Settings/Preferences dialog.
  2. From the options on the left, select Editor | General | Appearance.
  3. From the options on the right, select the Show code lens on the scrollbar hover.

Breadcrumbs

Breadcrumbs let you navigate through the source code, by showing the names of classes, variables, functions, methods and tags in the file with which you are currently working in the editor. By default, breadcrumbs are enabled and displayed at the bottom of the editor.

  • To change the location of breadcrumbs, right-click a breadcrumb, from the context menu select Breadcrumbs and the location preference.
  • To edit breadcrumbs settings, press ⌘,⌘,⌘,⌥F7⌃⌥S and on the page that opens, select Editor | General | Breadcrumbs. On the Breadcrumbs page, adjust the settings and click OK.

    Clear the Show HTML breadcrumbs option to hide the appearance of breadcrumbs in the editor.

Manage editor tabs

IntelliJ IDEA lets you manage the open tabs in the editor. You can close, hide, and detach them. Every time you open a file for editing, the tab with its name is added next to the active editor tab.

You can select Window | Editor Tabs to see what additional actions you can perform with the editor tabs.

You are able to do the following:

  • To close all of the opened tabs, select Window | Editor Tabs | Close All on the main menu.
  • To close all inactive tabs leaving only the active one, press and click the ../../Shared/close1.png icon on the active tab.
  • To close only the active tab, press ⌘W⌘F4⌘W⌃F4⌃F4.
  • To detach a tab, drag the tab you need outside of the main window (drag the tab back to attach it) or press ⇧F4⇧F4⇧F4⇧F4⇧F4.
  • IntelliJ IDEA limits number of tabs that you can open in the editor simultaneously (the default tab limit is 10).

    To prevent closing editor tabs automatically after the number of editor tabs reaches its limit:
    1. Press ⌘,⌘,⌘,⌥F7⌃⌥S.
    2. From the options on the left, select Editor | General |Editor Tabs.
    3. From the options on the right, in the Tab closing policy section, adjust the settings according to your preferences and click OK.
  • To switch between tabs, press ⌃⇥⌃⇥⌃⇥⌃⇥⌃⇥.
  • To place editor tabs in a different part of the editor or remove the tabs, from the main menu, select Window | Editor Tabs | Editor Placement and the appropriate option.
  • To sort editor tabs, select Window | Editor Tabs | Sort Tabs by File Name from the main menu.
  • To hide editor tabs if there is no more space:
    1. Press ⌘,⌘,⌘,⌥F7⌃⌥S.
    2. From the options on the left, select Editor | General | Editor Tabs.
    3. From the options on the right, select the Hide tabs if there is no space option. Extra tabs will be placed in the drop-down list located in the upper right part of the editor.
  • To split the editor window, right-click the desired editor tab, and from the context menu select how you want to split the editor window (vertically or horizontally). In this case IntelliJ IDEA makes a copy of the file and places it according to your selection. If you want to move the file without copying it first, select the Move Right or Move Down option.

Edit code

Select, move, copy code

ActionDescription
⌥↑⌘W⌃⇧↑⌃W⌃⌥W

The selection extends or shrinks according to capitalization, if the Use "CamelHumps" words checkbox is selected on the Smart Keys page (File | Settings | Editor | General | Smart Keys).

If you want to make selection according to capitalization, using double-click, make sure that the Honor CamelHumps words... checkbox is selected on the General page (File | Settings | Editor | General).

Press this shortcut to extend the selection of your code. For plain text and comments, the selection starts within the whole word then moves to the next word, sentence, etc. For lines of code, the selection starts with argument, extends to a group of arguments then all arguments inside method call.
⌥↓⇧⌘W⌃⇧↓⌃⇧W⌃⇧W Press this shortcut to shrink the code selection.
⌃G⌃G⌃G⌥J⌥JPress this shortcut to make the selection of your code, press the same key again to find the matching occurrence in the file. Alternatively, to make a multiselection of your code, press ⇧ ⌥ and double-click the left mouse button.
⌃⌘G⌃⌘G⌃⌘G⌃⌥⇧J⌃⌥⇧J Press this shortcut to find all the occurrences in the file.
⌥⇧⌘C⌥⇧⌘C⌥⇧⌘C⌃⌥⇧C⌃⌥⇧C / ⌘V⌘V⌘V⌃V⌥P Press these shortcuts to copy / paste a reference of a line or symbol placing a caret on the line or symbol in question.
⇧⌘V⇧⌘V⇧⌘V⌃⇧V⌥Y

By default, when you paste anything in the editor, IntelliJ IDEA performs 'smart' paste, for example, pasting multiple lines in comments will automatically add comment markers (//) to the lines you are pasting. If you need to paste just plain text, press ⌥⇧⌘V⌥⇧⌘V⌥⇧⌘V⌃⌥⇧V⌃⌥⇧V.

Press this shortcut to paste from history. In the dialog that opens, select your entry and click Paste.

You can configure the depth of the clipboard stack in the Limits section located in File | Settings/Preferences | Editor | General. When the specified number is exceeded, the oldest entry is removed from the list.
⌘Z⌘Z⌘Z⌃Z⌃⇧- / ⇧⌘Z⇧⌘Z⇧⌘Z⌃Y⌃⇧Z Press these shortcuts to undo or redo your changes.
Highlight bracesPlace the caret immediately after the block closing brace/bracket or before the block opening brace/bracket.

Select, move, copy lines and code blocks

Action / AccessDescription
⇧ ⌥ and click the left mouse button at the location of the caret. Choose this action to use multiple cursor.

Alternatively, press ^ (for Windows or UNIX) / (for macOS) twice, and then without releasing it, press up or down arrow keys.

The new carets are added to the specified locations, according to the setting specified in the Virtual Space section located in File | Settings/Preferences | Editor | General.

If you want to delete all existing carets, press ⎋, ⎋ or press ⇧ ⌥ and click the left mouse button on the caret you want to delete.
and drag your mouse vertically. Choose this action to have a continuous vertical line.

If the Allow placement of caret after end of line option in File | Settings/Preferences | Editor | General is selected, you will not be able to create a continuous vertical line.

To extend a cursor up or down:
  1. Press ⇧⌘A⇧⌘A⌘3⌃⇧A⌃⇧A to open the find action window.
  2. In the search field, start typing "clone".
  3. From the list of suggestions, select either Clone Caret Below or Clone Caret Above.

    The primary caret is propagated downwards or upwards respectively.
⌘C⌘C⌘C⌃C⌥C/ ⌘X⌘X⌘X⌃X⇧⌦/⌘V⌘V⌘V⌃V⌥P Press these shortcuts to copy, cut, and paste a text with multiple cursor.

IntelliJ IDEA splits the output text into lines.
Press this shortcut to add a line. IntelliJ IDEA moves the cursor to the next line.

To add a line before the current one, press .
⌘D⌘D⌃D⌘DPress this shortcut to duplicate a line.
⌘⌫⌘Y⌘D⌃⇧LPress this shortcut to remove a line.
⌥⇧↑⌥⇧↑⌥⇧↑⌥⇧↑ / ⌥⇧↓⌥⇧↓⌥⇧↓⌥⇧↓Press these shortcuts to move a line up or down.
⌥⇧⌘←⌥⇧⌘←⌥⇧⌘←⌃⌥⇧←⌃⌥⇧← / ⌥⇧⌘→⌥⇧⌘→⌥⇧⌘→⌃⌥⇧→⌃⌥⇧→Press these shortcuts to move a code element to the left or to the right. Place the caret at the desired code element, or select the elements to be moved and press the appropriate shortcut.

For example, for Java you can use these actions for method invocation or method declaration arguments, enum constants, array initializer expressions. For XML or HTML, use these actions for tag attributes.
⌃⇧J⌃⇧J⌃⇧J⌃⇧J⌃⇧JPress this shortcut to join lines. Place the cursor on the line to which you want to join the other lines and press the shortcut. Keep pressing the shortcut until all the needed elements are joined. You can successfully join string literals, a field or variable declaration, and statement. Note that IntelliJ IDEA checks the syntax and eliminates unwanted spaces and redundant characters.
To split string literals into two parts, press this shortcut in the string. IntelliJ IDEA splits the sting and provides the correct syntax. You can also use the Break string on '\n' intention to split the string literals.
⇧⌘U⇧⌘U⇧⌘X⌃⇧U⌃⇧UTo toggle between upper and lower case, press this shortcut.

Note that when you apply the toggle case action to the CamelCase name format, IntelliJ IDEA converts the name to lower case.
⌥⌘/⌃⇧/⌃⇧/⌃⇧/⌃⇧/To comment or uncomment blocks of code, select your code block and press this shortcut.

For a line of code, press ⌘/⌘/⌘/⌃/⌥;.

To configure settings for commenting behavior in Java, use options in the Comment Code section, on the Code Generation tab located in File | Settings/Preferences | Editor | Code Style | Java.

Enable Drag'n'Drop functionality in editorTo move or copy code fragments using drag-and-drop actions in the editor, make sure the this option is selected. This option is located in File | Settings/Preferences | Editor | General and selected by default. If you want to move the item, select the desired fragment of your code and drag the fragment to the target location.

If you want to copy your code selection, keep the ^ key pressed, drag the selection to the target location.

Move, remove statemets

Action / AccessDescription
⇧⌘↑⇧⌘↑⌥↑⌃⇧↑⌃⇧↑ / ⇧⌘↓⇧⌘↓⌥↓⌃⇧↓⌃⇧↓ To move statement, select the one you want and press one of these shortcuts. Note that if moving of statement is not allowed in the current context, the commands will be disabled. Also, note that IntelliJ IDEA moves the selected statement performing a syntax check.
⇧⌘⌦⇧⌘⌦⌃⇧⌦⌃⇧⌦To unwrap or remove statement, place the caret on the expression you want to extract or unwrap and press this shortcut.

IntelliJ IDEA shows a pop-up window with all the actions that are available in the current context. Statements to be extracted are displayed on the blue background, statements to be removed are displayed on the grey background.

You can select the desired action and press .

Reformat and rearrange code

IntelliJ IDEA lets you reformat your code according to the requirements you've specified in the Code Style settings located in File | Settings/Preferences | Editor | Code Style and rearrange code based on the arrangement rules specified on the Arrangement tab.

  • To reformat code in the current file, in the editor, select part of the code you want to reformat(⌥⌘L⌥⌘L⇧⌘F⌥F8) or rearrange (Code | Rearrange Code).

    If you don't select part of the code, IntelliJ IDEA will reformat the whole file.

  • To invoke the Reformat File dialog for details, press ⌥⇧⌘L⌥⇧⌘L⌥⇧⌘L⌃⌥⇧L⌃⌥⇧L.
  • To reformat a module or directory, right-click the module or the directory in question and from the context menu, select Reformat Code.

    (⌥⌘L⌥⌘L⇧⌘F⌥F8 also works.)
  • If you need to exclude part of code from reformatting, select the Enable formatter markers in comments option located in File | Settings/Preferences | Editor | Code Style. Then in the editor, at the beginning of a region that you want to exclude, create a line comment (⌘/⌘/⌘/⌃/⌥;) and type //@formatter:off, at the end of the region, again create a line comment and type //@formatter:on.
  • You can use ⌃⌥I⌥⌘I⌘I⌃⌥I⌃⌥I to quickly reformat line indents based on the specified settings on the Tabs and Indents tab located in File | Settings/Preferences | Editor | Code Style, on the language page.

    In some cases, the option Detect and use existing file indents for editing located in the Indent Detection section in File | Settings/Preferences | Editor | Code Style can override your settings. In this case IntelliJ IDEA will display the appropriate notification message.

Use quick pop-ups

Action / AccessDescription
⌥Space⇧⌘I⌥Space⌃⇧I⌃⇧IPress this shortcut to view quick definition of a symbol (tag, class, method/function, field, etc.). IntelliJ IDEA displays the information in a pop-up. If you need, click the ../../Shared/pin.png icon to open the pop-up in the Documentation tool window.
F1⌃J⌥Button2 Click⌃Q⌃QPress this shortcut to view quick inline documentation of a symbol, press .

IntelliJ IDEA displays a pop-up with the appropriate information. You can press F1⌃J⌥Button2 Click⌃Q⌃Q twice or click the ../../Shared/pin.png icon to open the pop-up in the Documentation tool window.

If you need to change the font size of the text displayed in the pop-up window, click the ../../Shared/cogwheel_blue_no_arrow.png icon and in the window that opens, change the font size according to your preferences.

You can also view an external documentation while in the quick documentation pop-up. Click ../../Shared/arrowUp.png or press ⇧F1⇧F1⇧F2⇧F1⇧F1.

External documentation becomes available when you properly configure it in the module structure. For example, in the module paths, you can add a path to a JavaDoc file, or a link to documentation; or specify a documentation URL for a library.

⌃⇧Q⌃⇧Q⌃⇧Q⌥Q⌥QPress this shortcut to view context (the action shows the current method or class declaration when it is not visible).
⌘F1⌘F1⌘F1⌃F1⌃F1Press this shortcut to view an error description. This action shows an error or warning description at the caret.
F1⌃J⌥Button2 Click⌃Q⌃QPress this shortcut to view quick documentation on a code element. For example, you can press ⌘O⌘N⇧⌘T⌃,⌥⇧G to look for a class and look up the documentation on any class displayed in the list. Press the same shortcut to switch focus to the pop-up.
⌥⌘F7⌥⌘F7⌥⌘F7⌃⌥F7⌃⌥F7Press this shortcut on the element in question to see all usages for code element.

If you want to enable/disable import pop-up messages, do the following:

  1. Press ⌘,⌘,⌘,⌥F7⌃⌥S.
  2. Select Editor | General from the options on the left.
  3. From the options on the right, in the Formatting section, depending on the action, select or clear the Show notification after optimize imports action and click OK.

Spellchecking

For spellchecking you can use Typo inspection that highlights the code based on the pre-defined dictionaries.

You can also configure the spellchecker's custom dictionary (a file with the dic extension) in the Custom Dictionaries Folder section located on the Dictionaries tab, in File | Settings/Preferences | Editor | Spelling.

  • To check the spelling of the highlighted word, press ⌥⏎⌥⏎⌘1⌥⏎⌥⏎ to show the available intention actions and choose the appropriate one.
  • To configure pre-defined and custom dictionaries, press ⌘,⌘,⌘,⌥F7⌃⌥S, select Editor | Spelling and specify the appropriate options.
  • To configure Typo inspection settings:
    1. Press ⌘,⌘,⌘,⌥F7⌃⌥S and select Editor | Inspections .
    2. In the list of inspection types, expand the Spelling node, click Typo and configure spellchecking options.

Configure file encodings

  • You can change file encoding in the editor by pressing ⌥⏎⌥⏎⌘1⌥⏎⌥⏎ on the encoding tag and selecting the encoding you need.
  • You can choose file encoding on the status bar located at the bottom of the screen.

    In this case, IntelliJ IDEA opens a dialog where you can decide what you want to do with your file. You can click either Reload or Convert.

    (In case of Reload, you load the file in the editor from a disk and the encoding changes are applied to editor only. In case of Convert, the file on a disk is overwritten with the encoding of your choice.)
  • To configure settings for file encodings, press ⌘,⌘,⌘,⌥F7⌃⌥S, select Editor | File Encodings.

Editor settings

IntelliJ IDEA lets you use settings for configuring different editor options to customize the editor.

  • To access settings, press ⌘,⌘,⌘,⌥F7⌃⌥S.
  • To navigate inside the Settings dialog, use search field for your queries.
  • To format your code, select Editor | Code Style.

    Use the Code Style page to configure general settings or click the Code Style node and select the language for which you want to configure code style options such as tabs and indents, spaces, wrapping and braces, etc. You can also configure hard and soft margins on the Code Style page.
  • To change fonts:
    1. For color schemes, select Editor | Color Scheme | Color Scheme Font.

      For for the console, select Editor | Color Scheme | Console Font.
    2. Configure your settings and click OK.
  • To change font size in the editor:
    1. Select Editor | General.
    2. On the General page, select the Change font size (Zoom) with Ctrl+Mouse Wheel option and click OK.
    3. In the editor, press ^, hold it and using the wheel on your mouse, adjust the font.
  • To configure font ligatures, select the Enable font ligatures checkbox located in Editor | Font and specify the appropriate options.
  • To configure color schemes, select Editor | Color Scheme. If you open the Color Scheme node, you are able to configure color scheme settings for different languages and frameworks. You can also use the General option from the list to configure color schemes settings for general items such as code, editor, errors and warnings, popups and hints, search results, etc.
  • To configure code completion options, select Editor | General | Code Completion. You can configure case sensitive completion, configure how to sort your code, configure auto-display options, etc.
  • To configure caret placement options:
    1. Select Editor | General.
    2. On the General page, select the Allow placement of caret after end of line option. For example, you can use this option to turn off the unlimited whitespace in the editor.

      If the Allow placement of caret after end of line option is selected, the creating of the continuous vertical line will not work.

      You can also select the Allow placement of caret inside tabs option which might be helpful when you scroll your file and want the cursor to remain in the same position.
  • To configure editor appearance options, for example, showing line numbers, or showing hard wrap guide, select Editor | General | Appearance.
  • To manage long lines of code, use soft wraps that you can configure in the Soft Wraps section in Editor | General.
  • To configure different smart keys, select Editor | General | Smart keys.
  • To configure settings for editor tabs, select Editor | General | Editor Tabs.