How do I create a new class in IntelliJ without using the mouse?

Viewed 135015

Is there a way to create a new class in a desired location without using the mouse in IntelliJ?

I understand there is no keyboard binding in the default keymap.

12 Answers

If you are already in the Project View, press Alt+Insert (New) | Class. Project View can be activated via Alt+1.

To create a new class in the same directory as the current one use Ctrl+Alt+Insert (New...).

You can also do it from the Navigation Bar, press Alt+Home, then choose package with arrow keys, then press Alt+Insert.

Another useful shortcut is View | Select In (Alt+F1), Project (1), then Alt+Insert to create a class near the existing one or use arrow keys to navigate through the packages.

And yet another way is to just type the class name in the existing code where you want to use it, IDEA will highlight it in red as it doesn't exist yet, then press Alt+Enter for the Intention Actions pop-up, choose Create Class.

On Mac OS 10.14.5, Idea Intellij 2019.1.3 - Press command + 1 to navigate to project files then press control + n

On Mac you can navigate to the location in Project view where you want to create your class and then use ⌘N followed by Enter.

  1. Alt-Home until you're in Packages view
  2. Down-arrow until package is highlighted
  3. Alt-insert
  4. Enter X 2
  5. Type name
  6. $PROFIT$

I also searched this answer. Equivalent of command+N on Mac OS for Windows is ctr + alt + insert which @manyways already answered. If you searching this in settings it is in Settings > IDE Settings > Keymap, Other > New ...

If the difficulty is in finding the option that makes .java or .class files (Like me), then simply,

click on the folder you want to create file on. select new, and type file's name along with extension.

For example, instead of, helloWorld type helloworld.java or any file extension you desire.

Related