Visual studios is an amazing text editor. Once you become familiar with a lot of it’s short cut keys, you will start to notice things you can do in visual studios that you can’t do in any other text editor (VS code being a possible exception). In particular, I have opened up visual studio to type out things completely unrelated to code, specifically for the multi caret feature.
This is a feature that takes a minute to get comfortable using it. It’s not something you’ll want to do once and then hope to remember it months in the future. It’s something like ctr+c for copy that you’ll want to register as muscle memory. The relevant short cuts are as follows
Shift Alt . => Add multi caret selection
Shift Alt / => Skip multi caret selection
Shift Alt , => Undo a multi caret selection
Seeing those is one thing. But being able to use them and commit them to muscle memory is another.
public class LearningMultiCaretFunctionality
{
public int test;
private decimal abc;
public double moneyAmount;
}
So let’s start with the above. Three random fields. Copy these into visual studio and follow along to be able to get practice as seeing how and when you can use this multi caret feature
Step 1: Select the “;” in line one. We choose this because everything we want to select will have that in common.
Step 2: Press “Shift Alt .” It will add a multi caret to the “;” in line two.
Step 3: Use “Shift Alt /” to skip this one. You will now have two carets on the “;” of the two public variables;
Make sure to experiment with “Shift Alt ,” to undo the last selection here, and then “Shift Alt .” to get back to where we are , so you’ll be comfortable with the different keys.
Step 4: type: {get;set;}
make sure to get the space before the property. If you miss it, you can just key left and add it into both locations while your carets are good.
public class LearningMultiCaretFunctionality
{
public int test {get;set; }
private decimal abc;
public double moneyAmount {get;set;}
}
The result is that you just turned both of your public fields into a public properties. At first you might go, ‘so what, I could have done that by copy & pasting over the semi colon in these two places, and that was so many steps.’
First, once you get these down to muscle memory it’ll feel like as many steps as ‘copy & paste’.
Second…We intentionally took the long way by starting with the semi colon which was common in all 3 scenarios when we could have started with the ‘public’ and been faster/more efficient about it.
Third and most importantly….we’ve only scratched the surface of the possibilities here.
Okay. So let’s continue with this example. This is where we are going to use other standard keyboard buttons in the process.
Ctrl Arrow Keys => jump a full word left or right
Shift Arrow Keys => Select multiple characters
Ctr Shift Arrow Keys=> select a full word to the left or right
Ctrl U => turn selection into lower case
Ctr Shift U => turn selection into upper case
Ctr C => Copy
Ctr V => Paste
If you don’t have your two get & set still highlighted. Highlight the top one and use Ctr Alt . To get your second caret on the bottom one as well.
Now use Ctr + Left Arrow Key to jump left one word. We want to do this until the top caret is to the left of the t in test & the m in moneyamount. Notice how it’s irrelevant of the length of the word. We moved 4 spaces on the top caret & 11 spaces on the bottom caret. This is important. I have copied entire text from a pdf, and turned documentation into a useful class in a very short amount of time by being able to not care about the length of the character
Ok. Now that our carets are in place. Use Shift+Right 1 time. This should select the first character in both of our new properties.
Now that they are selected. We want to do Ctr +Shift + U to push it to upper case.
public class LearningMultiCaretFunctionality
{
public int Test {get;set;}
private decimal abc;
public double MoneyAmount {get;set;}
}
Now, it might not seem impressive when it’s only two. But you didn’t have to care about what the letter was when you turned it to a capital letter. Once this is muscle memory, you’ll be doing this for short amounts of code, and long amounts of code all the time.
Now let’s try putting this to another example.
We want to convert the two properties to decimals. First we are going to double click on the word decimal in the abc field. Then we will do Ctr+C to copy it into our clipboard.
From here we want to double click on the word ‘public’ in the test property line. This should select the whole word.
Shift + Alt + . and you will select the second public. Just for practice you can hit it a second time, which will select the top public. And then do Shift + Alt + , to undo that so we just have the two we want selected.
Ctr + Right to bring the top caret to the left of the i in “int” and the bottom caret to the left of d in “double”
Now we want these to be decimals because we are dealing with money. So let’s use Ctr + Shit + Right arrow to select both words “int” and “double” at the same time.
looking at your selection. You should notice that this technically grabs one more space than we wanted to grab, so we will want to Shift + Left arrow to back up that one space.
From here use Ctr + V to dump our clipboard into these two locations
public class LearningMultiCaretFunctionality
{
public decimal Test {get;set;}
private decimal abc;
public decimal MoneyAmount {get;set;}
}
And now you have used it various times in a single sitting. The trick is going to be remembering these techniques and using them daily. All the time until they become muscle memory.
You might not be working a fin tech job that requires a lot of repetitive code, but it’ll still come in great use.
I had a job at a pizza joint once, where I was a prep cook. As a prep cook the hardest part of the job was making the pizza dough. This process could take anywhere between 40-80 minutes on your own, and most of the time you were making it on your own.
Basically you had to measure out a piece of dough. Roll it properly so it wouldn’t have any air holes. Oil it. And place it on a sheet pan.
At some point, I had realized we were making about 60 per batch. Which if you think about it, means that the difference between taking 60 seconds for a single dough ball and 46 seconds for a single dough ball was really 5 minutes per batch. At 3-4 batches a day. It meant that those 5 seconds snow balled to 20 minutes.
As a prep cook, you didn’t work shifts. You worked until the work was done. Sometimes that meant 5 hour shifts. Sometimes it meant 14 hour shifts. 20 minutes earlier meant going home 20 minutes earlier. I started to optimized the process every single step. Cut it down from 60 seconds down to 40 seconds. Every dough ball. Every batch. Every day.
I got good. I got fast. And the end result was a lot more days of getting out at a decent hour. A lot less time having people grumpy cause the dough took too long or wasn’t good enough. In general a better experience. Not by making big changes…but by finding small things that could be optimized.
In a round about way, it’s the same thing for coding. At first the idea of it saving a few seconds might sound silly learning these short cut keys. But those seconds add up when you program for 8 hours a day. Just try using the mouse and forget all your shortcut keys for a single day. It’ll feel like everything takes forever.
I know this…because I work in vb6 sometimes, which lacking any modern functionality makes even the easiest things take a lifetime to code out.
Small things snow ball into big things. Practice turns to muscle memory, and the less time you spend on getting your idea into code, the more time you can spend on making the ideas in the first place.