添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

IntelliJ IDEA 2023.1 Help

Migrate from Eclipse to IntelliJ IDEA

Switching from Eclipse to IntelliJ IDEA, especially if you've been using Eclipse for a long time, requires understanding some fundamental differences between the two IDEs, including their user interfaces , compilation methods , shortcuts , project configuration and other aspects.

Import an Eclipse project to IntelliJ IDEA

You can import either an Eclipse workspace or a single Eclipse project. To do this, click Open on the Welcome Screen or select File | Open in the main menu.

IntelliJ IDEA automatically detects Eclipse projects located on your computer and places them in the dedicated node right on the Welcome screen. This node will be available among the recent projects until you decide to remove it. When the Eclipse project is in the node, just click it to quickly open it in the IDE.

Opening an Eclipse project from the Welcome screen

If your project uses a build tool such as Maven or Gradle , we recommend selecting the associated build file pom.xml or build.gradle when importing the project. For more information on how to import a project, refer to Import a project from Eclipse .

If you'd like to import your existing run configurations from Eclipse , consider using this third-party plugin .

User Interface

No workspace

The first thing you'll notice when launching IntelliJ IDEA is that it has no workspace concept. This means that you can work with only one project at a time. While in Eclipse you normally have a set of projects that may depend on each other, in IntelliJ IDEA you have a single project that consists of a set of modules.

If you have several unrelated projects, you can open them in separate windows.

If you still want to have several unrelated projects opened in one window, as a workaround you can configure them as modules .

IntelliJ IDEA vs Eclipse terminology

The table below compares the terms in Eclipse and IntelliJ IDEA:

Eclipse

IntelliJ IDEA

Workspace

Project

Project

Module

Facet

Facet

Library

Library

JRE

SDK

Classpath variable

Path variable

No perspectives

The second big surprise when you switch to IntelliJ IDEA is that it has no perspectives .

It means that you don't need to switch between different workspace layouts manually to perform different tasks. The IDE follows your context and brings up the relevant tools automatically.

IntelliJ IDEA project overview

Tool windows

Just like in Eclipse , in IntelliJ IDEA you also have tool windows. To open a tool window, click its name in the tool window bar:

Tool windows bars

If the tool window bar is hidden, you can open any tool window by hovering over the corresponding icon in the bottom-left corner:

Tool windows bars menu

If you want to make the tool window bar visible for a moment, you can press Alt twice and hold it.

If you don't want to use the mouse, you can always switch to any toolbar by pressing the shortcut assigned to it. The most important shortcuts to remember are:

  • Project : Alt+1

  • Commit : Alt+0

  • Terminal : Alt+F12

Another thing about tool windows is that you can drag, pin, unpin, attach and detach them:

Moving tool windows

To help store/restore the tool windows layout, there are two useful commands:

  • Window | Store Current Layout as Default

  • Window | Restore Default Layout (also available via Shift+F12 )

Multiple windows

Windows management in IntelliJ IDEA is slightly different from Eclipse . You can't open several windows with one project, but you can detach any number of editor tabs into separate windows.

Always select opened files

By default, IntelliJ IDEA doesn't change the selection in the Project tool window when you switch between editor tabs. However, you can enable it in the tool window settings:

Enabling the 'Always select opened file' option

General workflows

No 'save' button

IntelliJ IDEA has no Save button. Since in IntelliJ IDEA you can undo refactorings and revert changes from Local History , it makes no sense to ask you to save your changes every time.

Still, it's worth knowing that physical saving to disk is triggered by certain events, including compilation, closing a file, switching focus out of the IDE, and so on. You can change this behavior via Settings/Preferences | Appearance & Behavior | System Settings :

Configuring the system settings

Save actions

If you are an experienced Eclipse user, you are familiar with save actions : the actions triggered automatically on save, such as reformatting code, organizing imports, and so on.

IntelliJ IDEA also features save actions that you can find and enable in Settings/Preferences | Tools | Actions on Save .

Settings: Actions on save

On top of that, IntelliJ IDEA offers you to run the corresponding actions automatically on commit:

Committing changes to VCS

Or manually:

  • Code | Reformat Code Ctrl+Alt+L

  • Code | Optimize Imports Ctrl+Alt+O

  • Code | Code Cleanup

Compilation

The way IntelliJ IDEA compiles projects is different from Eclipse in a number of ways.

Auto-compilation

By default, IntelliJ IDEA doesn't automatically compile projects on saving because normally we don't invoke the save action explicitly in IntelliJ IDEA.

If you want to mimic the Eclipse behavior, you can invoke the Build Project action Ctrl+F9 - it will save the changed files and compile them.

You can also enable the Build project save action in Settings/Preferences | Tools | Actions on Save .

Note that automatic compilation in IntelliJ IDEA differs from that in Eclipse . In Eclipse it's not fully automatic, as it is triggered by the save action invoked by the user explicitly, whereas in IntelliJ IDEA it is invoked implicitly when you type in the editor.

This is why, even if the Build project option is enabled, IntelliJ IDEA doesn't perform automatic compilation if at least one application is running: it will reload classes in the application implicitly. In this case you can call Build | Build Project Ctrl+F9 .

Problems tool window

The Problems tool window appears if the Build project option is enabled in save actions . It shows a list of problems that were detected on project compilation.

Problems tool window

Eclipse compiler

While Eclipse uses its own compiler, IntelliJ IDEA uses the javac compiler bundled with the project JDK. If you must use the Eclipse compiler, navigate to Settings | Preferences | Build, Execution, Deployment | Compiler | Java Compiler and select it as shown below:

Configuring the Eclipse compiler

The biggest difference between the Eclipse and javac compilers is that the Eclipse compiler is more tolerant to errors, and sometimes lets you run code that doesn't compile.

In situations when you need to run code with compilation errors in IntelliJ IDEA, replace the Build option in your run configuration with Build, no error check :

Running code with compilation errors

Shortcuts

IntelliJ IDEA shortcuts are completely different from those in Eclipse .

The table below shows how the top Eclipse actions (and their shortcuts) are mapped to IntelliJ IDEA (you may want to print it out to always have it handy).

Eclipse

IntelliJ IDEA

Action

Shortcut

Action

Shortcut

Code completion

Ctrl+Space

Basic completion

Ctrl+Space

-

-

Type-matching completion

Ctrl+Shift+Space

-

-

Statement completion

Ctrl+Shift+Enter

Quick access

Ctrl+3

Search everywhere

Double Shift

Maximize active view or editor

Ctrl+M

Hide all tool windows

Ctrl+Shift+F12

Open type

Ctrl+Shift+T

Navigate to class

Ctrl+N

Open resource

Ctrl+Shift+R

Navigate to file

Ctrl+Shift+N

-

-

Navigate to symbol

Ctrl+Alt+Shift+N

Next view

Ctrl+F7

-

-

-

-

Recent files

Ctrl+E

Quick outline

Ctrl+O

File structure

Ctrl+F12

Move lines

Alt+Up/Down

Move lines

Alt+Shift+Up / Alt+Shift+Down

Delete lines

Ctrl+D

Delete lines

Ctrl+Y

Quick fix

Ctrl+1

Show intention action

Alt+Enter

Quick switch editor

Ctrl+E

Switcher

Ctrl+Shift+Tab

-

-

Recent files

Ctrl+E

Quick hierarchy

Ctrl+T

Navigate to type hierarchy

Ctrl+H

-

-

Navigate to method hierarchy

Ctrl+Shift+H

-

-

Show UML popup

Ctrl+Alt+U

Last edit location

Ctrl+Q

Last edit location

Ctrl+Shift+Backspace

Next editor

Ctrl+F6

Select next tab

Alt+Right

Run

Ctrl+Shift+F11

Run

Shift+F10

Debug

Ctrl+F11

Debug

Shift+F9

Correct indentation

Ctrl+I

Auto-indent lines

Ctrl+Alt+I

Format

Ctrl+Shift+F

Reformat code

Ctrl+Alt+L

Surround with

Ctrl+Alt+Z

Surround with

Ctrl+Alt+T

-

-

Surround with live template

Ctrl+Alt+J

Open declaration

F3

Navigate to declaration

Ctrl+B

-

-

Quick definition

Ctrl+Shift+I

Open type hierarchy

F4

Navigate to type hierarchy

Ctrl+H

-

-

Show UML popup

Ctrl+Alt+U

References in workspace

Ctrl+Shift+G

Find usages

Alt+F7

-

-

Show usages

Ctrl+Alt+F7

-

-

Find usages settings

Ctrl+Alt+Shift+F7

Open search dialog

Ctrl+H

Find in Files

Ctrl+Shift+F

Occurrences in file

Alt+Ctrl+U

Highlight usages in file

Ctrl+Shift+F7

Copy lines

Ctrl+Alt+Down

Duplicate lines

Ctrl+D

Extract local variable

Ctrl+Alt+L

Extract variable

Ctrl+Alt+V

Assign to field

Ctrl+2 / Ctrl+F

Extract field

Ctrl+Alt+F

Show refactor quick menu

Ctrl+Alt+T

Refactor this

Ctrl+Alt+Shift+T

Rename

Ctrl+Alt+R

Rename

Shift+F6

Go to line

Ctrl+L

Navigate to line

Ctrl+G

Structured selection

Alt+Shift+Up / Alt+Shift+Down

Select word at caret

Ctrl+W / Ctrl+Shift+W

Find next

Ctrl+J

Find next

F3

Show in

Ctrl+Alt+W

Select in

Alt+F1

Back

Ctrl+[

Back

Ctrl+Alt+Left

Forward

Ctrl+]

Forward

Ctrl+Alt+Right

Eclipse keymap

For Eclipse users who prefer not to learn new shortcuts, IntelliJ IDEA provides the Eclipse keymap which closely mimics its shortcuts:

Eclipse keymap

Find action

When you don't know the shortcut for some action, try using the Find action feature available via Ctrl+Shift+A . Start typing to find an action by its name, see its shortcut, or call it:

The Find Action dialog

Coding assistance

Both Eclipse and IntelliJ IDEA provide coding assistance features, such as code completion, code generation, quick-fixes, live templates, and so on.

Quick-fixes

To apply a quick-fix in IntelliJ IDEA, press Alt+Enter :

Applying quick-fixes

All quick-fixes are based on inspections configured in Settings/Preferences | Editor | Inspections :

the Inspections dialog

If you want to apply a quick-fix to several places at once (that is to a whole folder, module or even a project), you can do it by running the corresponding inspection via Code | Analyze Code | Run Inspection By Name... or by running the whole batch of inspections via Code | Running Code Cleanup with profile ''{0}''… :

Analysing code in IntelliJ IDEA

Apart from outright problems, IntelliJ IDEA also recognizes code constructs that can be improved or optimized via the so-called intentions (also available with Alt+Enter ):

Applying intention actions

Eclipse

IntelliJ IDEA

Action

Shortcut

Action

Shortcut

Quick fix

Ctrl+1

Show intention action

Alt+Enter

Generating code

The key action for generating code is Code | Generate , available via Alt+Insert :

Generating code

This action is context-sensitive and is available not only within the editor, but also in the Project tool window and the Navigation bar :

Creating a new object in the Project tool window

Code completion

IntelliJ IDEA provides different types of code completion, which include:

  • Basic completion

  • Second basic completion

  • Type-matching completion

  • Second type-matching completion

  • Statement completion

To learn more about the differences between these completion types, refer to the Code Completion blog post.

By default, IntelliJ IDEA doesn't show the Documentation popup for the selected item, but you can enable it in Settings/Preferences | Editor | Code Completion | Show the documentation popup in :

Code completion

If you don't want to enable this option, you can manually invoke this popup by pressing Ctrl+Q when you need it:

Showing the quick documentation popup

When the caret is within the brackets of a method or a constructor, you can get the info about the parameters by calling Parameter Info with Ctrl+P :

Showing parameter info

Eclipse

IntelliJ IDEA

Action

Shortcut

Action

Shortcut

Code completion

Ctrl+Space

Basic completion

Ctrl+Space

-

-

Type-matching completion

Ctrl+Shift+Space

-

-

Statement completion

Ctrl+Shift+Enter

Templates

You may be used to typing main in the editor and then calling code completion to have it transformed into a main method definition. However, IntelliJ IDEA templates are a little different:

Template

Eclipse

IntelliJ IDEA

Define a main method

main

psvm

Iterate over an array

for

itar

Iterate over a collection

for

itco

Iterate over a list

for

itli

Iterate over an iterable using foreach syntax

foreach

iter

Print to System.out

sysout

sout

Print to System.err

syserr

serr

Define a static field

static_final

psf

The list of available templates can be found in Settings | Editor | Live Templates . There you can also add your own templates or modify any existing ones.

Postfix templates

In addition to 'regular' templates, IntelliJ IDEA offers the so-called postfix templates. They are useful when you want to apply a template to an expression you've already typed. For instance, type a variable name, add .ifn and press Tab . IntelliJ IDEA will turn your expression into a if (...==null){...} statement.

To see a complete list of available postfix templates, go to Settings | Editor | General | Postfix Completion .

Surround with live template

The surround with templates is another addition that works similarly to live templates but can be applied to the selected code with Ctrl+Alt+J .

To define your own surround with template, go to Settings | Editor | Live Templates and use $SELECTION$ within the template text:

$LOCK$.readLock().lock();