Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best way to use shortcuts and autocomplete to create a new object in Intellij IDEA?

Object + shortcutObject object = new Object();

Whether there is such shortcut?

like image 353
CarryFlag Avatar asked Aug 09 '12 20:08

CarryFlag


People also ask

How do I autocomplete in IntelliJ?

Invoke type-matching completion By default, IntelliJ IDEA displays the code completion popup automatically as you type. If automatic completion is disabled, press Ctrl+Shift+Space or choose Code | Code Completion | Type-Matching from the main menu. If necessary, press Ctrl+Shift+Space once again.

How do I use IntelliJ shortcuts?

To add or change the shortcut for any action, press Alt+Enter when it is selected in the list. Key Promoter X is a plugin that shows a popup notification with the corresponding keyboard shortcut whenever a command is executed using the mouse.

Where is the shortcut method in IntelliJ?

Ctrl+Alt+Shift+N : finds a symbol. In IntelliJ IDEA, a symbol is any code element such as method, field, class, constant, and so on. Ctrl+Shift+A : finds an action by name. You can find any action even if it doesn't have a mapped shortcut or appear in the menu.


1 Answers

As of 2017, improving on @aleksander's answer, I believe the best way to create a new object as efficiently as possible in Intellij IDEA, is this (click to enlarge):

enter image description here

  1. Go to Settings > Live Template.
  2. Then click the + to the right of the window, to add a new Live Template.
  3. Choose the abbreviation you want (Like n or newo). Description could be new Object .
  4. Add the template text: $Clazz$ $obj$ = new $Clazz$($END$);
  5. Click que Edit Variables button, and the fill in the Clazz and obj Expression and Default Value as shown in the picture above.
  6. Don't forget to click Define next to No applicable contexts, to define Java > Statement as the context.

Now test it: Go to the editor, type n and then the TAB key.

like image 159
MarcG Avatar answered Oct 05 '22 08:10

MarcG