Chapter 3 - Selection
Move + Select
ctrl+shift+arrows
Open Chapter3.java, then move your cursor to the beginning of the line containing "jumps over", hold
down
ctrl, shift and press the right arrow key → to select that sentence.
Now cut and paste it behind the first line.
Expand Selection
ctrl+w
Press
ctrl + n and open Fugly.java.
Move your cursor to line 23, column 28 by pressing
ctrl + g and typing 23:28.
From that position press
ctrl + w, press this key combination again a few times, and see what happens.
Now try using
ctrl + shift + w to incrementally reduce the size of your selection. Play around with both the
Expand selection and Reduce selection key combinations until you feel comfortable with them.
What happens if you keep on pressing that combination?
Using Selection to help Navigation (e.g. Fluent API)
Because
ctrl + w expands a selection, and because the arrow keys decide where our cursor is going to be:
← at the beginning or
→ at the end of the selection.
We can use a little trick to format our Fluent API.
Format the one-liner so that it looks like the method below. You can do this by pressing
ctrl + w until you have a selection
containing a “method call”, e.g. fugly(), then press → to put your cursor at the end, and press
⏎
(enter).
Rinse and repeat.
Wrapping (IntelliJ feature)
IntelliJ has a neat feature that wraps your selection with braces, curly braces, single or double quotes, …
You can enable this feature under Settings by pressing
⌘ + >,, then go to Editor > General >
Smart Keys, and enable Surround selection on typing quote or brace.
An alternative is by pressing
ctrl + shift + a, and then type Smart Keys Braces.
Fix the wrapStuff method by selecting "efffff" with
ctrl + w, and then type a ".
Then apply the same pattern to yewwww but instead of a ", type a (.Then apply the same pattern to the entire method body but type a {.
This feature really shines in combination with multi-cursor (which we’ll discuss in detail later on).