intellij-idea Little-known features Language injection


Example

If you want to write strings containing other languages (JSON, regexes), it's hard to keep up with escaping symbols, and it would be nice to get some code assist.

  1. Put your cursor inside an empty string
  2. ALT + ENTER
  3. Pick "Inect language or reference"

Pick "Inject language or reference"

  1. Pick the desirable language (RegExp in my case) from the pop-up

enter image description here

  1. Again use ALT + ENTER and pick Edit regex fragment

enter image description here

  1. In the new tool window enter the regex - note how it's automatically mapped to a properly escaped Java string. Similarly for JSON the indents will be placed properly.