What's the best way to use shortcuts and autoc

2019-01-14 13:06发布

问题:

Object + shortcutObject object = new Object();

Whether there is such shortcut?

回答1:

new Obj, Tab to complete to new Object(), Ctrl+Alt+V (Refactor | Introduce Variable):

Object o = new Object();

Change name if needed and press Enter to confirm.

For the more convenient solution utilizing the live templates feature please check the answer below from @MarcG.



回答2:

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):

  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.



回答3:

You can define your own Live Template. Press Crtl+Alt+Shift+S (go to Settings), then go to tab Live Templates and write down something similar to below and you will have new shortcut (newo+tab).