Scala offers an ability to enter
Redirect | ||
---|---|---|
|
Intellij IDEA lets you add different intentions for strings and perform different actions with strings in Scala. Intellij IDEA also supports the Scala multi-line strings feature. This feature lets you format literals
Scala offers a method called stripMargin that removes the left-hand part of a multiline string up to a specified delimiter (default: "|"). Here is an example:
Entering Multi-line strings
Enter triple quots to envoke StripMargin method. You can enter multi-line strings.
It also preseves white spaceand helps your code to look more orderly.
1. How to Insert Gap with Concatenation into a String
IntellijIDEA lets you insert a gap with concatenation intention. To do that, in your editor enter a string and press
Wiki Markup |
---|
{span:class=shortcut}Alt{span} |
Wiki Markup |
---|
{span:class=shortcut}Enter{span} |
Select Insert gap with concatenation ("+ +") and press
Wiki Markup |
---|
{span:class=shortcut}Enter{span} |
Now you can insert a value into your string. You can evaluate the result in the Scala Console window.
2. How to Convert a String Concatenation into Interpolated String
For the Scala version 2.10 and later you have the ability to convert a string concatenation into the interpolated string.
To do that, select a value with concatenation in your string and press
Wiki Markup |
---|
{span:class=shortcut}Alt{span} |
Wiki Markup |
---|
{span:class=shortcut}Enter{span} |

Select Convert to interpolated string, press
Wiki Markup |
---|
{span:class=shortcut}Enter{span} |
You can also choose an option Convert to formatted string and get your basic Java formatted string.
3. How to Convert a String into a Multi-line String and Vice Versa
You can convert your string into a multi-line string. Simply enter your string, press
Wiki Markup |
---|
{span:class=shortcut}Alt{span} |
Wiki Markup |
---|
{span:class=shortcut}Enter{span} |
Converting to multi-line strings removes escaped sequences such as '\\' or '\n'.
You also can convert the multi-line string into the regular string.
Press
Wiki Markup |
---|
{span:class=shortcut}Alt{span} |
Wiki Markup |
---|
{span:class=shortcut}Enter{span} |
Wiki Markup |
---|
{span:class=shortcut}Enter{span} |
View the result.
To start entering a multi-line string, simply type triple quotes in your editor.
If you press
Wiki Markup |
---|
{span:class=shortcut}Enter{span} |
The white spaces are also preserved. Please see the following example:
You can choose different intention options for Scala
4. How to Insert a Replace Intention
The .replace("\r"," ") intention lets you keep the caret in the correct place on the next line in the multi-line strings . Place your cursor on the string and press [regardless of what operating system you have at the moment.
Enter a multi-line string, press
Wiki Markup |
---|
{span:class=shortcut}Alt |
{span} |
Wiki Markup |
---|
{span:class=shortcut}Enter{span} |
5. How to Insert an Inject Language/Reference Intention
You can inject language or a reference into your multi-line string literals.
Enter a multi-line string, press
Wiki Markup |
---|
{span:class=shortcut}Alt{span} |
Wiki Markup |
---|
{span:class=shortcut}Enter{span} |
The list of available languages opens. Choose the appropriate one and press
Wiki Markup |
---|
{span:class=shortcut}Enter{span} |

For example, the if you select Convert to "String" option, you will see the following result:

The multi-line string is converted to the one-line string.
To cancel the language injection, simply choose the Un-Inject Language/Reference intention.
6. How to Edit Multi-line Strings Settings
You can set a different format for multi-line strings' options such as Margin char indent or Margin Char. You can also disable a multi-line strings support.
To open the Multi-line strings settings, in the main menu select
Wiki Markup |
---|
{span:class=shortcut}File{span} |
Wiki Markup |
---|
{span:class=shortcut}Setting{span} |
Wiki Markup |
---|
{span:class=shortcut}Project Settings{span} |
Wiki Markup |
---|
{span:class=shortcut}Code Style{span} |
Wiki Markup |
---|
{span:class=shortcut}Scala{span} |
