Using IntelliJ's diff tool with a keyboard  Version Control

Using IntelliJ's diff tool with a keyboard

This article gives a short introduction to IntelliJ's diff and merge tool. It explains how to locate yet unknown keyboard shortcuts and tells you how to use the Diff & Merge tool with your keyboard.

Introduction

I’m glad that I know how to use most of IntelliJ with the keyboard.
Using the mouse is slow and also puts a lot of strain on my wrist.

But I noticed that I’m using the mouse for some tasks. That’s usually because I don’t know
how to use the keyboard for it.

I was wondering for a long time how to use the merge dialog without the mouse.
I was always thinking “This has to be possible! Somehow…” but was too lazy (or stubborn) to
find out how to get of the mouse here.

Our Use Case

Could you use these dialogs without your mouse?

List of Conflicts

IntelliJ window showing a list of conflicts

Do you know how to use this without your mouse?

For this dialog, I usually do one of these tasks:

  • Resize the columns and/or the window to see all of the paths and the names of the branches
  • Accept Yours
  • Accept Theirs
  • Merge...

I have never used Group files by directory yet—I can’t remember that this already was in older versions.
And you couldn’t use it with your keyboard, anyway. There’s no mnemonic defined for it and thus no
shortcut to enable it using the keyboard.

Merging conflicts in IntelliJ

IntelliJ window showing a 3-way diff

Could you merge the change on the left without your mouse?

I already knew about these shortcuts:

  • F7 to navigate to the next conflict
  • Shift + F7 to navigate to the previous conflict

But I always use the mouse for these tasks:

  • put focus on the left, middle, or right pane by clicking into it
  • accept the item on the left or the right, i.e. click on the little arrows pointing towards the center
  • reject an item on the left or the right, i.e. click on the little x symbol
  • change the selection in the Ignore whitespace box
  • change the type of highlighting, e.g. to use Highlight words

Finding the shortcuts

It’s not very intuitive to find out about the keyboard shortcuts. The tooltips for the actions above
are not showing the shortcuts.

Head over to the settings at File > Settings… > Keymap. Now enter diff in the filter input on the right.

IntelliJ settings dialog showing keymap

Finding default shortcuts for the Diff and Merge tool

Have you already spotted the entry for Accept Left Side and Accept Right Side?
I was very happy to see that it’s possible to use the keyboard for these actions.

Oh, and there’s Select Opposite Diff Pane. Isn’t that helpful?

And, if you look closely at the list, you’ll see unassigned shortcuts for Append Left/Right Side and Ignore Left/Right Side.

I tested this a bit. Working in the middle column, navigating with F7 , accepting left or right with
Alt + Shift + Left or Alt + Shift + Right and finally accepting the modifications with Alt + Enter
seems good enough to me.

Summary

Hopefully, you’ve learned something new. At least I did. It’s good to use the mouse less and be able to work
a bit faster with the diff and merge tool.

I added an overview with the most common shortcuts I’m (now) using with Diff & Merge.

Shortcuts for IntelliJ’s list of conflicts

I’ll make more use of these helpful shortcuts:

TaskmacOSLinux / Windows
Resize the window to get wider columnsCtrl + ShiftCtrl + Shift
Accept YoursAlt + YAlt + Y
Accept TheirsAlt + TAlt + T
MergeAlt + MAlt + M

Shortcuts for IntelliJ’s merge window

TaskmacOSLinux / Windows
Put focus into middle columnCtrl + TabCtrl + Tab
Accept change on the leftCtrl + Shift + LeftAlt + Shift + Left
Next changeF7F7
Previous changeShift + F7Shift + F7
ApplyOption + EnterAlt + Enter

External References

JetBrains help
Elements of the Diff & Merge viewer
Keyboard shortcuts of the Diff & Merge viewer