Something that has always interested me is the impact that small actions have on our daily lives and I think knowing keyboard shortcuts is one of those actions. Why? It saves you time. Yes, only a tiny fraction of time but all those tiny fractions add up in the end. Keyboard shortcuts can also give off the impression that you are confident in what you are doing, which is a huge plus.
Before I started programming I had no idea how to use any keyboard shortcuts. It was through programming, and my insistent fiancé, that I began to learn how to navigate around my computer while rarely touching my mouse/trackpad. He used to get so frustrated with me when I'd ask him a question while coding and I'd use the trackpad of my laptop to navigate through open windows or to select a word. Why would he get mad? Well, I was sort of wasting his time. Using keyboard shortcuts creates a quicker way to navigate your laptop/computer than constantly pulling back and using your trackpad/mouse.
Since gaining this skill I feel as if I have gained the tiniest semblance of confidence in my demeanor at work and during interviews. This skill has helped me combat the good 'ole fight with imposter syndrome, because it has given me a sense of "I know what I'm doing."
Anyways, that's enough about me. Let's dive on in.
One thing I'll note before jumping into each shortcut is that these are Mac specific. If you are running on a different system just hop on your favorite search engine and look up what your equivalent is!
This is a need-to-know, especially for me who incorrectly types very often! If you ever need to undo any of the changes you've made to your code editor simply type
command + Z.
Wait! What if you accidentally got trigger happy and undid something you didn't mean to! Don't fret,
command + shift + Z is here to save the day!
This is one of my favorite keyboard shortcuts because I am sometimes indecisive with my variable names and need to change them. Instead of going through and changing each instance where I called the variable, I select one instance of it and use
command + D to select each time that variable appears one at a time.
The reason I like using this one over the one I'm covering next is because sometimes the phrase being matched appears within the name of another variable and I may be happy with that variable! No need to change it!
If you feel confident and comfortable to select all instances that match the phrase you've selected at one time, then give
command + shift + L a try.
If you've accidentally selected an instance of the phrase that you didn't mean to select, then use
command + U to undo it. Note that if you do it after using
command + shift + L it will unselect everything, not just one at a time.
If you are ever in the middle of a line (or even the end) and want to jump to the beginning of the line use
command + left arrow or
control + A instead of holding down the left arrow until you reach the start.
To get to the end of the line you can either use
command + right arrow or
control + E.
Similar to jumping to the beginning of the line, in order to select the code from your cursor's current position to the beginning of the line you should use
command + shift + left arrow or
control + shift + A.
You may have already guessed that there is also a shortcut to select code from your cursor's current position to the end of the line! In order to do this use
command + shift + right arrow or
control + shift + E.
Any time you want to select all the text in one file use
command + A.
So now you may be wondering if there is a shortcut to select the word your cursor is currently near. Well there is! If your cursor is left of the word you want to select use
option + shift + right arrow. Now if your cursor is to the right of the word you would use
option + shift + left arrow.
You can continue to select more than word if you keep clicking the arrow in the desired direction.
If you want to move around within a line without jumping straight to the beginning or end of the line there is a shortcut that allows you to move one word at a time. This is
option + left arrow or
option + right arrow, which one you choose is dependent upon which direction you'd like to move in.
When you have dead code that you no longer need and it requires you to remove everything from your cursor's current position to the beginning of the line you can use
option + delete.
In order to delete the code from your current position to the end of the line use
control + K.
If you want to quit an application, which will close all open windows of said application, use
command + Q.
When you are ready to close the current window you are in (like I will be when I'm finished writing this blog post 😉) you can use
command + W.
If you don't want to close the window but want it off the screen, then you should minimize it by using
command + M.
We can go even further by minimizing all windows that belong to a particular application by using the shortcut
command + option + M.
In order to open a new window of an application use the shortcut
command + N
If you ever want to open a new tab while you are in your browser use
command + T.
When you accidentally close a tab you didn't mean to close, you can use
command + shift + T to get it back!
Switching between tabs while in the browser has to be one of my favorite keyboard shortcuts because when I write blogs I often reference many articles. To go towards the left use
command + shift + ] and to go to the right use
command + shift + [.
This is one of my favorite finds during my research for this blog! While in the browser you can use
command + L to select the address bar so you can start typing in your next web destination!
Another general useful shortcut is
command + space to invoke spotlight to search your machine.
If you are ever working across multiple applications and need to switch frequently use
command + tab. You keep pressing
tab until you reach the application you want as your current window.
Another awesome find of my research!!
In any application use
command + , to open up the applications preferences.
I have no idea how I managed to forget to include this one as well as the next two since I use them probably the most on a daily basis. Thanks to That Blair Guy for reminding me of them in the discussion.
Anyways, to copy any selected code in a browser, text editor, etc. use
command + C.
Whenever you want to paste code use
command + P
To cut selected code use
command + X
Anna Simoroshka reminded me of this other amazing shortcut to search for something in a file. To do this use
command + F.
She also taught me that
command + shift + F will search all files within a project in a text editor. This is a new tool I'll be using frequently.
Another new one that Anna taught me is
command + P within a text editor to search for a file by name.
This was a fun blog post for me to research and write. I learned so many new shortcuts I never knew of and I even thought of a few I use very often while writing it.
If you are new and are thinking "Holy cow! How do I remember all these?" don't worry. I also felt overwhelmed when I first started. Like anything, with more repetition and practice it'll become secondhand nature to use them.
Thanks for reading and happy coding!
Note: The cover image for this post is brought to you from the Ballycotton Cliff Walk in Ballycotton, Ireland.