IntelliJ IDEAが便利になる40のショートカット

ここ数カ月、家でも仕事でもIntelliJ IDEAを使っているのですが、せっかくのIDEなのにショートカットをほとんど使っていなくて宝の持ち腐れ状態になっているので、ちょっと調べて便利そうな物を一欄にまとめてみました。
Macでは微妙に違うものもあるので注意。

ショートカット 動作
Ctrl + Space Basic Code Completion
Alt + Enter Show intention actions and quick-fixes
Ctrl + Alt + L Reformat code
Ctrl + Alt + O Optimize imports
Ctrl + P Parameter info
Ctrl + Q Quick Documentation lookup
Ctrl + F1 Show descriptions of error or warning at caret
Alt + Insert Generate code
Ctrl + O Override methods
Ctrl + I Implement methods
Ctrl + Alt + T Surround with
Ctrl + / Comment/uncomment with line comment
Ctrl + Shitt + / Comment/uncomment with block comment
Ctrl + W Select successively increasing code blocks
Ctrl + Shift + W Decrease current selection to previous state
Ctrl + D Duplicate current line or selected block
Ctrl + Y Delete line at caret
Shift + Enter Start new line
Ctrl + F4 Close active editor tab
Shift + F10 Run
Shift + F9 Debug
Ctrl + N Go to class
Ctrl + G Go to line
Ctrl + B Go to declaration
Ctrl + Alt + B Go to implementation(s)
Ctrl + H Type hierarchy
Ctrl + Shift + H Method hierarchy
Ctrl + Alt + H Call hierarchy
F11 Toggle Bookmark
Shift + F11 Show Bookmarks
F2 / Shift + F2 Next/previous highlighted error
Shift + F6 Rename
Ctrl + F6 Change Signature
Ctrl + Alt + N Inline
Ctrl + Alt + M Extract Method
Ctrl + Alt + V Introduce Variable
Ctrl + Alt + F Introduce Field
Ctrl + Alt + C Introduce Constant
Ctrl + Alt + P Introduce Parameter
Ctrl + J Insert Live Template

以下解説。

Ctrl + Space [Basic Code Completion]

いわゆる入力補完。一番お世話になるやつですね。

Alt + Enter [Show intention actions and quick-fixes]

キャレットのある位置で行うのに適したアクションの一覧を表示します。
という説明だとなんのことやらわかりにくいですが、エラー・警告表示の箇所では取り敢えずこのショートカットを使えば何とかなる。そんな頼りになる奴です。二番目にお世話になるやつです。
クラス名の上で入力するとサブクラスやテストクラスも作れます。

Ctrl + Alt + L [Reformat code]

コードを自動整形します。まさか手動でなんかやりませんよね?
整形ルールは設定のCode Styleで編集できます。

Ctrl + Alt + O [Optimize imports]

不要なimportを削除したりしてくれます。まさか手動で(略
こちらも設定のCode Styleでルールなどを編集できます。

Ctrl + P [Parameter info]

メソッドのパラメータ一覧を表示します。
パラメータを忘れた時にはこれ。

Ctrl + Q [Quick Documentation lookup]

javadocを表示します。
このクラス/メソッドなんだっけ?そんな時に。

Ctrl + F1 [Show descriptions of error or warning at caret]

キャレット位置のエラー/警告の説明を表示します。

Alt + Insert [Generate code]

コードを生成します。
setter/getterにメソッドのオーバーライド、委譲などが生成できます。

Ctrl + O [Override methods]

オーバーライドしたメソッドを生成します。

Ctrl + I [Implement methods]

interfaceのメソッドの実装を生成します。
もちろんinterfaceをimplementしていないクラスでは無意味です。

Ctrl + Alt + T [Surround with]

選択箇所をif文、while文、synchronized文などで囲みます。

Ctrl + / [Comment/uncomment with line comment]

選択行をコメント行化またはその逆を行います。

Ctrl + Shitt + / [Comment/uncomment with block comment]

選択箇所をコメントブロック化またはその逆を行います。

Ctrl + W [Select successively increasing code blocks]

連続したコードブロックを選択状態にします。
連続で入力すると、入力するごとに選択範囲が広がります。

Ctrl + Shift + W [Decrease current selection to previous state]

入力するごとに選択範囲が小さくなります。上のショートカットと組み合わせて使います。

Ctrl + D [Duplicate current line or selected block]

キャレットの行または選択箇所を複製します。

Ctrl + Y [Delete line at caret]

キャレットのある行を削除します。

Shift + Enter [Start new line]

新しい行を入力します。
どの位置にキャレットがあっても新しい行を入力できて便利です。

Ctrl + F4 [Close active editor tab]

アクティブなタブを閉じます。

Shift + F10 [Run]

実行します。

Shift + F9 [Debug]

デバッグモードで実行します。 

Ctrl + N [Go to class]

入力欄が表示されるので、クラス名を入力するとそのクラスのコードに移動します。

Ctrl + G [Go to line]

行番号を入力するとその行に移動します。

Ctrl + B [Go to declaration]

クラスやメソッド、変数などの宣言箇所に移動します。

Ctrl + Alt + B [Go to implementation(s)]

インターフェイスやそのメソッドを実装しているクラスの一覧を表示します。

Ctrl + H [Type hierarchy]

クラスの継承階層を表示します。

Ctrl + Shift + H [Method hierarchy]

継承しているクラスなどでのメソッドのオーバーライドの状況を表示します。

Ctrl + Alt + H [Call hierarchy]

メソッドを呼び出しているメソッドの一覧を表示します。

F11 [Toggle Bookmark]

キャレットのある行をブックマークに追加または削除します。

Shift + F11 [Show Bookmarks]

ブックマークの一覧を表示します。

F2 / Shift + F2 [Next/previous highlighted error]

コード中の次の/前のエラー箇所に移動します。

Shift + F6 [Rename]

クラス名やメソッド名、変数名などを変更します。

Ctrl + Alt + N [Inline]

選択しているメソッドをインライン展開します。
使うことがあるのか微妙ですが一応。

Ctrl + Alt + M [Extract Method]

選択箇所をメソッドにします。

Ctrl + Alt + V [Introduce Variable]

変数宣言を入力します。

new ArrayList<String>();

だけ入力してからこのショートカットキーを入力すると

ArrayList<String> strings = new ArrayList<String>();

こんな感じに補完されます。

Ctrl + Alt + F [Introduce Field]

こちらはフィールドとして宣言を入力します。

Ctrl + Alt + C [Introduce Constant]

こちらはstatic finalなフィールドとして宣言を入力します。

Ctrl + Alt + P [Introduce Parameter]

こちらはメソッドやコンストラクタのパラメータとして宣言を入力します。

Ctrl + J [Insert Live Template]

テンプレートを入力します。
soutで

System.out.println();

など、いくつか標準でもテンプレートが設定されています。