How to close a file in Intellij using a keyboard shortcut?

Intellij Idea

Intellij Idea Problem Overview


I know this is a simplistic question; but I've been using IntelliJ for months now, and can't find this simple feature.

Any idea? Thank you.

Intellij Idea Solutions


Solution 1 - Intellij Idea

Idiot me. CMD-F4 or, as mentioned before, CTRL-F4.

Thank you all. I'll just bury myself now :)

Solution 2 - Intellij Idea

hmm you can't because there is no default key binding for that, at least on OSX, however you can go here and define one:

enter image description here

Solution 3 - Intellij Idea

The standard tip if you don't know how to do something in Idea is "Find Action..." (ctrl+shift+A in Windows) then type what you want to do, in this case close.

You will get a lot of different "close" actions and simply "Close" (ctrl+F4 in Windows) will be one of them.

Solution 4 - Intellij Idea

You can also set a custom key combination in the settings menu

Click on File > Settings and select Keymap from the menu on the left, then scroll down to the Other section and set your preferred key combination for Close Active Editor:

enter image description here

When you double-click on Close Active Editor, a menu pops up allowing you to set a key combination, a mouse gesture, or even an abbreviation for the action. If the shortcut is already set somewhere else (as in my case with Ctrl-W) you'll get a notification and won't be able to set the shortcut until you remove the other one.

Solution 5 - Intellij Idea

As with Matt Ball, I don't use IntelliJ but may also be CTRL+F4...

Solution 6 - Intellij Idea

For MAC user, Cmd-W will close the active tab (file).

Solution 7 - Intellij Idea

On Mac, you might like to use CMD + W, as this is the conventional shortcut for closing things e.g. Tabs in Chrome.

But by default this is usually associated with highlighting the current cursor block, so instead I use CTRL + W, rather than re-assigning.

e.g. (bottom right)

enter image description here

Also works for other IntelliJ IDEs, like WebStorm, etc.

Solution 8 - Intellij Idea

IDEA->File->Setting->Search for "Close Active Editor". Click on 'Add Keyboard Shortcut' -> Change it to "Ctrl+W". (Overwrite).

BOOM! you are universal now!

Solution 9 - Intellij Idea

I'm on version 2020.4 and this has changed to Ctrl+4

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTomer LichtashView Question on Stackoverflow
Solution 1 - Intellij IdeaTomer LichtashView Answer on Stackoverflow
Solution 2 - Intellij IdeahvgotcodesView Answer on Stackoverflow
Solution 3 - Intellij IdeaosundbladView Answer on Stackoverflow
Solution 4 - Intellij IdeaJonathan E. LandrumView Answer on Stackoverflow
Solution 5 - Intellij IdeaR4D4View Answer on Stackoverflow
Solution 6 - Intellij Ideahoang21View Answer on Stackoverflow
Solution 7 - Intellij IdeaDarren ShewryView Answer on Stackoverflow
Solution 8 - Intellij IdeaSyed Irfan AliView Answer on Stackoverflow
Solution 9 - Intellij IdeaMustapha-BelkacimView Answer on Stackoverflow