Skip to content

Edit code inside IntelliJ Idea

Patrick Scheibe edited this page Jan 29, 2017 · 4 revisions

Documentation lookup

With Ctrl+Q (Ctrl+j on OS X) you can get documentation of all built-in Mathematica functions. Shown are the html/MathML styled usage, Attributes, and Options. Additionally, you can click the link to navigate to the online reference page of Wolfram. For the Mathematica function Compile this looks for instance as follows

If a symbol has no online reference page, you automatically search the online Wolfram site for the symbol name and context. The documentation even works on operators (other than the most basic ones like +). Try for instance calling the documentation when you are at /@ or =!=.

Inserting braces and highlighting brace matcher

Inserting any kind of brace automatically adds a matching closing brace, which keeps your brace balance correct from the start. Many people love to close their braces manually, but this is not a problem. If you are in front of a closing brace and close this brace again, no additional brace is inserted. Instead, the cursor jumps over the closing brace:

On the other hand, when your braces are not balanced, and a closing brace would be required, then an additional brace is indeed inserted. Consider this example: f[g[x]. Go behind the "x" and press a closing ] twice and see what happens:

Matching braces are highlighted when you move around in code. Additionally, when you try to highlight a closing brace where the opening one is outside the editor window, the line containing the opening brace is shown on top of the editor window.

Commenting code

With Ctrl+/ you can comment or uncomment lines or selected blocks. Additionally, Ctrl+Shift+/ lets you comment a selected text region:

Note that if you just want to start a new comment, even in the middle of a line of code, you have to use Ctrl+Shift+/.

Selecting code

In addition to the usual selection of text with Shift and the arrow keys, you can expand the current selection by pressing Ctrl+W. This function selects step after step surrounding expression by walking up the Mathematica structure. Shrinking the selection works the same way with Ctrl+Shift+W:

Smart Enter aka Complete Expression

Smart Enter aka Complete Expression will try to finish the expression you are currently working on and do something useful. It has the shortcut Ctrl+Shift + Enter (Cmd+Shift + Enter on Mac OS X). There are several situations where this is very useful:

  • The most basic usage is if you want to insert a function and the correct name already pops up. Let's say you type Modu, then the name Module should already pop up in the suggestion box. Now, it is very likely that you want to have Module[] with the cursor inside the braces. Pressing the shortcut for Smart Enter will exactly do this.
  • Another usage is if you are inside a list. Let's say your cursor is directly after the 5 in the code Module[{a=1,b=3,c=5}]. Pressing Smart Enter the first time will reformat the contents of the list fixing the spaces around the = operator. If you press it again, it will jump out of the list.
  • Staying with the above example and the cursor after the closing list }. Typing in a comma and pressing Smart Enter again will (this time) really insert a line feed but additionally, it will move the closing ] to another line, and it will fix your cursor indentation.
  • Now it gets a bit more involved. Still staying with our initial example but let's say you already typed something like this
Module[{a = 1, b = 3, c = 5},
  a = 3;
  b = a
]

With the cursor behind the last a. Now, and this is important because the plugin cannot do magic, the structure of your code suggests that you are writing a Module with a CompoundExpression (several expressions end by a semicolon). Pressing now Smart Enter will fix the indentation of the current line, insert a semicolon at the end and jump to the next line. It is important to understand that this only works if you have at least one line which was terminated by a semicolon.