200

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.

giannis christofakis
  • 8,201
  • 4
  • 54
  • 65
JavaRocky
  • 19,203
  • 31
  • 89
  • 110
  • 6
    Please specify the operating system! Keyboard layouts are different for Windows/Linux and Mac. – shaunthomas999 Nov 09 '18 at 11:25
  • 4
    Mac: `Command + 1` then `ctrl + return` – Janac Meena Oct 01 '19 at 13:39
  • @Janac Meena that worked for me. PSA return key is the same as enter key on Mac. So basically Command+1 to navigate through the directory and then Ctrl+Enter to simulate "right clicking" and then creating a class/resource/etc. – M.Ed Jun 23 '22 at 12:23

12 Answers12

293

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.

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
  • 1
    Thanks CrazyCoder. You are indeed Crazy. BTW, are you crazy enough to use IntelliJ debugger without the mouse? It can not be done i tell you! I'm talking about full navigation around the debugging windows. – JavaRocky Feb 12 '10 at 03:52
  • 2
    Probably you can't do everything with keyboard in debugger, but most things are possible. Alt+5 activates the panel, Tab switches between Frames/Variables/Watches, Up/Down in Frames changes frame, F2 in Variables edits variables, Insert in Watches adds Watch, other common keys also work (like delete/arrows, etc). Some actions have no default shortcuts and need to be assigned in Settings | Keymap. – CrazyCoder Feb 12 '10 at 04:02
  • I agree that not everything is possible with keyboard only with the debugger. CrazyCoder, i challenge you to unplug your keyboard and work with IntelliJ!!! – JavaRocky Feb 12 '10 at 04:31
  • Is there any way you know of to do it from code with a single keystroke? I've been trying to figure this out from time to time for years it seems. – Sophistifunk Feb 04 '14 at 02:23
  • @Blundell there are many keymaps provided, so I can't specify hotkeys for all of them, you just open your keymap settings or use `Help` | `Find Action` to figure out what is the shorcut for **New** action in your keymap. – CrazyCoder Jan 28 '16 at 15:04
  • What if the insert key does not work? The only insert key I have is on the number pad with 0, and Alt+Insert is not working. – Peter Burbery Nov 08 '21 at 16:16
  • @PeterBurbery you can change the shortcut in the Keymap settings: https://i.imgur.com/1vjGlA2.png. – CrazyCoder Nov 08 '21 at 16:18
109

You can also use: ctrl+alt+insert

Nicofisi
  • 1,083
  • 1
  • 15
  • 27
manyways
  • 4,386
  • 2
  • 23
  • 19
24

With Esc and Command + 1 you can navigate between project view and editor area - back and forward, in this way you can select the folder/location you need

With Control +Option + N you can trigger New file menu and select whatever you need, class, interface, file, etc. This works in editor as well in project view and it relates to the current selected location

// please consider that this is working with standard key mapping

Rodislav Moldovan
  • 1,175
  • 1
  • 13
  • 20
19

For Mac Os, command + 1 , then press control + return

Vishal Nagpure
  • 266
  • 4
  • 12
9

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

Adelin
  • 18,144
  • 26
  • 115
  • 175
7

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.

Ivaylo Toskov
  • 3,911
  • 3
  • 32
  • 48
5

I do this a lot, and I don't have an insert key on my laptop, so I made my own keybinding for it. You can do this by opening Settings > IDE Settings > Keymap and navigating to Main menu > File > New... (I would recommend typing "new" into the search box - that will narrow it down considerably).

Then you can add a new keyboard shortcut for it by double clicking on that item and selecting Add Keyboard Shortcut.

Michael Dorst
  • 8,210
  • 11
  • 44
  • 71
2
  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$
Jason DeMorrow
  • 489
  • 5
  • 9
1

If you use Mac, you are in luck. One can change the keymap for Intellij as Mac OS X, then you can use option+C.

Nicofisi
  • 1,083
  • 1
  • 15
  • 27
Alan Dong
  • 3,981
  • 38
  • 35
0

In my (linux mint) system I can not get working combination alt+insert so I do the next steps:

alt+1 (navigate to "tree") --> "context button - analog right mouse click" (between right alt and ctrl) -- then with arrows (up or down) desired choice (create new class or package or ...)

Hope it helps some "mint" owners )).

Svetlin Zarev
  • 14,713
  • 4
  • 53
  • 82
Andrew
  • 36,676
  • 11
  • 141
  • 113
0

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 ...

Bohdan Myslyvchuk
  • 1,657
  • 3
  • 24
  • 39
-2

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.