Skip to content

Latest commit

 

History

History
133 lines (115 loc) · 4.63 KB

ij-osx-basic-code-completion.md

File metadata and controls

133 lines (115 loc) · 4.63 KB

Top => IntelliJ on OS X

JetBrains IntelliJ IDEA on Mac OS X

Kata for practicing keyboard shortcuts for basic code completion features

Kata: Basic code completion

Key sequences to practice

  • ⌃␣ (Ctrl + Space) - basic code completion
  • ⌘⇧⏎ (Command + Shift + Return) - complete statement
  • ⌥⌘⇧] (Option + Command + Shift + ]) - select from caret to end of code block
  • ⌫ (Delete) - delete selected text

Keystrokes without explanations

  • Open the Java source file, CodeCompletionPractice.java.
  • Begin editing at the top of method1().
  • Repeat the following keyboard inputs until the sequence becomes fluid.
        double randomNumber = M
⏎
.
ran
⏎
⌘⇧⏎
⏎
        double result = ra
⏎
⌘⇧⏎
⏎
        S
⏎
.
⏎
.
⏎
        System.out.println("Result: " + re
⏎
⌘⇧⏎

And then to revert:

  1. Place the caret at the beginning of the first line of code in method1().
  2. Press
⌥⌘⇧]
⌫

Walkthrough of steps with explanations

  1. Open the Java source file, CodeCompletionPractice.java.
  2. Begin editing at the top of method1().
  3. Type the following code:
        double randomNumber = M
  1. The editor presents a list of possible completions. The first one is "Math (java.lang)". Press ↩ (Return or Enter) to select that item. The code now reads:
        double randomNumber = Math

and the caret is positioned immediatly after the token, "Math".

  1. Type . (Period or Dot). The editor presents a list of possible completions.
  2. Type "ran," so that the source line looks like this:
        double randomNumber = Math.ran
  1. The editor reduces the number of possible completions as you type. Only one option remains after you've typed "ran". Press ↩ (Return or Enter) to select it. The source line now looks like this:
        double randomNumber = Math.random()
  1. Press ⌘⇧↩ (Command + Shift + Return) to complete the statement. The editor appends a semicolon, leaving the source line like this:
        double randomNumber = Math.random();

Note: You might wonder why you should press three keys instead of just typing in the semicolon yourself. The statement completion feature can fill in much more than just a semicolon in different situations. It's a good habit to use it routinely.

  1. On the next line in the source file, type the following:
        double result = ra
  1. The editor presents a list of possible completions and reduces the list as you type. At this point, only one suggestion remains. Press ↩ return to select it. The code in method1() now looks like this:
    public void method1() {
        double randomNumber = Math.random();
        double result = randomNumber
    }
  1. Press ⌘⇧↩ (Command + Shift + Return) to complete the statement. The editor appends a semicolon, leaving the source line like this:
        double result = randomNumber;
  1. On the next line, type
        S
  1. The editor presents a list of possible completions, of which the first one is "System (java.lang)". Press ↩ (Return or Enter) to select it. The source line now looks like this:
        System

and the caret is positioned immediately after the token, "System".

  1. Enter . (Period or Dot) and the editor presents a list of possible completions, of which the first one is "out". Press ↩ (Return or Enter) to select it. The source line now looks like this:
        System.out

and the caret is positioned immediately after the token, "out".

  1. Type . (Period or Dot) and the editor presents a list of possible completions, of which the first one is "println (int x)". Don't worry about the argument type. Press ↩ (Return or Enter) to select the item.
  2. Start to fill in the argument to the println() method:
        System.out.println("Result: " + re
  1. The editor presents a list of possible completions and reduces the list as you type. At this point, only one option remains: "result". Press ↩ (Return or Enter) to select it. The source line now looks like this:
        System.out.println("Result: " + result
  1. Press ⌘⇧↩ (Command + Shift + Return) to complete the statement. Method method1() now looks like this:
    public void method1() {
        double randomNumber = Math.random();
        double result = randomNumber;
        System.out.println("Result: " + result);
    }
  1. Position the caret at the beginning of the first line of code in method method1(). Press ⌥⌘⇧] to select the text from the caret position to the end of the code block. Press ⌫ (Delete) to delete the selected text.