Kata for practicing keyboard shortcuts for commenting/uncommenting lines of code
Key sequences to practice
- ⌘/ (Command + Slash) - comment/uncomment line(s) - toggle
- ⌘⌥/ (Command + Option + Slash) - comment/uncomment with block comment
Keystrokes without explanations
- Open the Java source file, LongConditional.java.
- Repeat the following keyboard inputs until the sequence becomes fluid.
(position caret after opening curly brace of the class declaration)
⏎
⌘⌥/
line1
⏎
line2
⏎
line3
And then to revert:
- Press ⌘Z repeatedly to undo changes.
Walkthrough of steps with explanations
- Open the Java source file, LongConditional.java.
- Place the caret just after the opening curly brace ({) for the class declaration.
- Press ⏎ (Return or Enter) to insert a blank line just above the declaration of method1().
- Press ⌘⌥/ (Command + Option + Slash) to insert a block comment at the caret location. The caret will then be positions in between the opening and closing markers of the block comment.
- Type some text and press ⏎ (Return or Enter) to start a new line. The editor inserts an asterisk, alining the new comment line with the first comment line. Repeat this if desired to end up with several lines of comments within the block comment.
** Key sequences to practice**
- ⌘/ (Command + Slash) - Comment/uncomment the line where the caret resides
Keystrokes without explanations
⌘/
⌘/
⌘/
⌘/
⌘/
⌘/
⌘/
⌘/
Walkthrough of steps with explanations
- Open the Java source file, LongConditional.java.
- Place the caret on any source line; it doesn't have to be at the beginning of the line.
- Press ⌘/ (Command + Slash) multiple times. Notice how the line is commented and the caret moves down one line with each press.
To reverse:
- Place the caret on the first line you just commented.
- Press ⌘/ (Command + Slash) repeatedly until the commented lines have all been uncommented.
Key sequences to practice
- ⇧↓ (Shift + Down Arrow) - select multiple lines, one by one
- ⌘/ (Command + Slash) - Comment/uncomment the selected lines
Keystrokes without explanation
⇧↓ ↓ ↓ ↓
⌘/
⇧↓ ↓ ↓ ↓
⌘/
Walkthrough of steps with explanations
- Open the Java source file, LongConditional.java
- Place the caret at the beginning of any source line.
- Press ⇧↓ (Shift + Down Arrow) to select several consecutive lines.
- Press ⌘/ (Command + Slash) to comment the selected lines.
To reverse:
- Select the same lines again.
- Press ⌘/ (Command + Slash) to toggle the comments off.