As George Costanza might say, this is a post about nothing.
…or what looks like nothing, anyway. I’m talking about “whitespace” (spaces, tabs, line feeds, etc.).
I probably spend more time than I should obsessing over the appearance of my code, including whether statements are more readable with or without line breaks.
For example, I might decide that instead of this:
…I want to format the statement like this:
(The term “whitespace” is a bit weird with a dark color scheme. You can think of it as “dark matter” for the rest of this post if you prefer.)
In the past, to make the change described above, I would start by positioning the cursor after the opening parenthesis on the first line and pressing the delete key, which would move the second line of code up with the first:
Then, I would either select the whitespace between the parenthesis and opening quote mark and hit the delete key, or just position the cursor after the parenthesis and hold down the delete key until, Pac-Man style, I gobbled up all of the unwanted whitespace characters (and usually gobbled up more than I wanted to and had to hit Ctrl-Z a few times to restored accidentally deleted text).
I knew there was probably a keyboard short to do what I wanted, but I was too lazy to look it up. I finally did. the shortcut is:
CTRL + K, CTRL + \
Collapses white space in the selection, or deletes white space adjacent to the cursor if there is no selection.
In the example above, I would just position the cursor after the parenthesis and press the Ctrl-K,\ “chord” to zap everything between the parenthesis and the opening quote mark.
But wait, there’s an even faster way. If instead of pressing the delete key to bring the second line up to join the first, I had pressed CTRL+DELETE, that would have immediately zapped everything between the parenthesis and the quote mark (including the line feed characters):
CTRL + DELETE
Deletes the word to the right of the insertion point.
If you ever have a need to make whitespace visible (for example, to see if indenting is done with tabs or spaces), you can use the Edit -> Advanced -> View White Space menu (keyboard shortcut: CTRL + R, CTRL + W):