Skip to content
Patrick Scheibe edited this page Jan 29, 2017 · 1 revision

IDEA's features for autocompletion can be divided into two steps: (1) Invoking the autocompletion so that you get a list of possible items to insert and (2) actually inserting them. While the first one is obvious, it might not be clear why there should be several ways to insert a chosen completion. I'll explain this in a moment.

1. Invoking autocompletion

By invoking I mean how do you get the window that shows several possible functions, symbols or expressions that can be inserted at the current cursor position. IDEA's behavior I describe here can be adjusted so that it works differently for you. If you like to adjust how code completion works in IDEA, you can go to File -> Settings -> Editor -> General -> Code Completion. I usually use these settings:

Code completion settings

With Autopopup code completion enabled, IDEA will automatically pop up a completion window while you are typing, suggesting functions that match what you have currently typed. You can always close this window by pressing Esc. However, there is a lot more to it (be aware of the different shortcuts on Mac OSX):

  • Ctrl+Space will pop up the basic code completion window wherever you like.
  • Ctrl+Shift+Space will show a smart completion window which only works in specific places, like inside a function to show only options, or inside Message[...] to show possible messages.
  • Ctrl+Alt+Space will show a code completion window that contains every possible symbol you have used in your code.
  • Ctrl+Alt+T will show possible expressions that can surround the current selection of code. That is helpful if you like to surround an expression with Module, braces, Do loops, and other things.
  • The above surround completion will show a list of live templates, which are often used code constructs. This list can be accessed with Ctrl+Alt+J.

2. Inserting a completion

The completion window has basically two states: 1. No entry is focused and 2. an entry is focused. When you did not enable Insert selected variant by typing dot, ... in the settings above, IDEA will not focus any entry for the auto popup code completion window. The list will look like this

unselected completion

As soon as you use your arrow keys to move down the list, or you invoke the completion explicitly with one of the shortcuts above, one entry will be highlighted. Here is the same image as above after I pressed down arrow

focused entry

There is not much difference between these two, except with a focused entry, you can use [, (, ;, Space, or several other keys and the completion is inserted. If no entry is focused, then this won't work.

Most of the times you will insert a completion entry in 3 different ways:

  • pressing Enter simply inserts the selected entry
  • pressing Tab will insert the entry, deleting the text that is right to the cursor. This is handy if you have mistyped something. Let's say you have typed AbsoluteFileName but what you wanted was AbsoluteTiming. Just go with the cursor right after the Absolute and start typing T and press Tab. You see that the rest of FileName is replaced.
  • pressing Ctrl+Shift+Enter is called SmartEnter and it will insert the entry as well, but in addition, it will insert [] for you if it is a built-in function. Try typing Ab and press it. The behavior if only [] is inserted or for instance the complete call pattern can be adjusted in Settings->Languages-> Mathematica.

Here is an example that shows how SmartEnter works:

Here is an example that shows that you can always call the completion pop up with Ctrl+Space, even in the middle of a word. As explained above, use Tab to replace the rest of the word with the current selection:

And remember, as soon as you start navigating inside the completion window and you have focused an entry, you can always look up its documentation with Ctrl+Q (Ctrl+j on OS X).