Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

try, catch, finally autocomplete pattern in IntelliJ

Using IntelliJ when i type try followed by Ctrl-Space (autocomplete), i get nothing added

Instead, i'd like to see

  try {
    // do something great
  } catch {
    case e: Exception => // handle me
  }

Language is Scala, if this matters.

How can i define autocomplete pattern as shown above?

like image 544
James Raitsev Avatar asked Dec 13 '12 03:12

James Raitsev


People also ask

How do I autocomplete in IntelliJ?

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.

Why is IntelliJ autocomplete not working?

I have tried the following according to this thread (Intellij IDEA CE 12 Android XML Code Completion not working): Go to File->Power Save Mode and disable it - it is off. Go to Preferences->Editor->Code Completion and check Autopopup code completion - this has been checked. Go to File->Invalidate Caches and restart.

How do I get a list of methods in IntelliJ?

By default, IntelliJ IDEA shows all classes, methods, and other elements of the current file. To toggle the elements you want to show, click the corresponding buttons on the Structure tool window toolbar.


2 Answers

Use the surround templates:

surround

You can find more details in help:

  • Surrounding Blocks of Code with Language Constructs
like image 72
CrazyCoder Avatar answered Sep 21 '22 11:09

CrazyCoder


Yes, you can go to File > Settings... and under Live Templates add your own with, Abbreviation: try

Template text:

try {
        // do something great
    } catch {
        case e: Exception => $END$ // handle me
    }

Applicable in Java: expression. The $VAL$ places the cursor there after you tab off of the "try".

like image 43
kuporific Avatar answered Sep 21 '22 11:09

kuporific