A Huge List of Useful Keyboard Shortcuts

Create more hours in your day

Donny Landis
Better Programming

--

Photo by Kevin Ku on Unsplash

tl;dr: There are more keyboards shortcut articles on the internet than you can shake a stick at. This is basically a meta cheat sheet that I made for myself and my friends that lays out the core shortcuts that make the life of a new programmer much nicer. It also has one not-so-core game changer at the end.

The Why

When people use the phrase time investment these days, they often mean time suck, as in, “I’d always wanted to rewatch the ‘Lord of the Rings’ movies but it’s such a time investment. Now that we’re quarantined though…”

Here and now, let’s reclaim the original meaning of the phrase: that is, time spent doing something that will pay off in the future. You can apply it as big and abstract (going to college) or as small (organizing your sock drawer) as you want.¹ Specifically, we’re here to talk about a time investment that pays off with the thing that money can’t buy: more time.

Let’s pretend for a second that every action you take on your computer in the course of a day were represented as a line of code in a file. There would be some big, headline activities that take up many lines, like writing code, surfing the web, writing emails, and listening to music. You would also see a ton of micro-activities, such as switching between applications or opening a browser window. In our imaginary file, there would be so much repetition of those micro-activities that we would be monsters if we didn’t at least try to DRY them out.

What are the magic tools that allow us to do this, you ask? Answer: keyboard shortcuts. I know that this is a deeply un-sexy term, but you know what is sexy? Having more time to do stuff that’s not repetitive. Since, after all, this is an article on shortcuts, we’ll abbreviate it as SC going forward.

If there’s one thing I want you to take away from this article, it’s this. Every second spent learning an SC will yield hours of time in the future. This is a stone-cold fact; if you don’t believe it, check this footnote.²

Ultimately, the choice is yours on how diehard you want to get with SCs. You don’t have to be one of those people who find the idea of using a trackpad repulsive and curse Steve Jobs for popularizing the GUI. Even picking up a few SCs will make your life better. After all, we’re lazy programmers — not doing more work than we have to is our M.O.!

The How

This cheat sheet is written to be modular, meaning you can skip around to pick and choose, or if you want, read the whole thing in one go. It’s a choose-your-own adventure. If the list feels overwhelming, here are two suggestions on how to start:

  • Bookmark this page (command + shift + d) and go about your everyday computer activities. But make a mental note whenever you use your mouse. When one of those mouse tasks is showing up repeatedly, pull this article up, find the SC for it, and start using it. Rinse, wash, repeat.
  • The topics in the article go from the general (things you’ll use everywhere) to the particular (things you’ll use a lot if you’re using Rails, but only apply to Rails).

The biggest thing is muscle memory. If you’re starting from a place where you don’t use a lot of SCs, trying to stuff all these abstract commands into your brain is not going to be fun or effective. Take a few at a time and focus on using them consistently. In some ways, just thinking in SC terms is the most powerful thing because you’ll look for them whenever you reach for the mouse or a task feels cumbersome.

Two quick notes

  • These shortcuts reflect the systems I use, so if you use different ones, eat around the bits you don’t like.
  • Virtually all of the MacOS SCs work in both Chrome and VS Code. For the sake of brevity, I won’t reprint them in those sections.
Photo by Rubén Menárguez on Unsplash

MacOS

Operating system SCs are the foundation for everything and easily the lowest-hanging fruit on the tree. This list contains the must-haves because not only do these shortcuts improve how you generally use your computer, they’re so common that most applications use the same shortcuts. Many for the price of one!

Basics

  • Cut a selected item: command + x
  • Copy a selected item: command + c
  • Paste a selected item: command + v
  • Paste and match style: option + shift + command + v
  • Undo the last action: command + z
  • Find items in a document or window: command + f
  • Save a file: command + s
  • Quit an application: command + q

Navigation

  • Open a new window: command + n
  • Close current window: command + w
  • Minimize current window: command + m
  • Open a new tab: command + t
  • Switch between applications: command + tab (keep hitting tab till the application you want appears)
  • Switch between applications in the opposite direction: command + shift + tab (keep hitting tab till you get to the application you want)

Cursor and selecting

I think of these as the real gateway drugs to SC land. They technically originate in Mac applications like notes and document editors, but they exist in many applications, such as VS Code, and they make life a lot easier.

The basic idea is that your cursor doesn’t have to move one space up/down/right/left at a time — plus you can select things at the same time!

  • Jump to the top/bottom of a document: command + up/down arrow
  • Jump to the beginning/end of the line: command + left/right arrow
  • Jump to beginning of previous/next word: option + left/right arrow
  • To select a block of text, combine any of the previous SCs with the shift button. Want to select all the content in the file? Get your cursor to the last line of the document and hit shift + command + up arrow. Boom! Once you get really comfortable with these, selecting stuff with a trackpad will feel like a chore.

This is by no means an exhaustive list. There are a lot more, so if you want to check out the full list, go to Mac keyboard shortcuts on Apple’s site.

Image by Photo Mix on Pixabay

Chrome

Chrome is the most popular web browser around, so this guide is for its SCs. That said, most other web browsers have the exact same ones, so even if you don’t use Chrome, this is probably useful.

Tab/window navigation

  • Switch browser windows: option + `
  • Switch browser windows(reverse direction): shift + option + `
  • Jump to the tab next door left: command + option + left arrow
  • Jump to the tab next door right: command + option + right arrow
  • Reopen the most recently closed tab: command + shift + t
  • Open a window in incognito mode: command + option + n

Miscellaneous features

  • Bookmark current page: command + d
  • Open developer tools: command + option + i
  • Jump to address bar: command + l (as in Lima)
  • Reload current page: command + r
  • Scroll down webpage: spacebar
  • Scroll up webpage: shift + spacebar
  • Open link in a new tab: command + mouse click
  • Open browser history in a new tab: command + y
  • Open downloads history in a new tab: command + shift + j

Once again, there’s a ton more out there. These are just the ones I use regularly. Google support has the full list of Chrome keyboard shortcuts.

VS Code

The structure of this one will be a little different, simply because VS Code has a lot of powerful features. I’ll spotlight some that I find most useful, plus I’ll flag a couple of the more advanced tools. You can find the full list of VS Code keyboard shortcuts here. It bears mentioning quickly that the MacOS Cursor and Select SCs are crazy valuable for VS Code since they allow you to navigate the cursor quickly and to select efficiently.

Display

  • Basic tab navigation is the same as Chrome:
    jump next door right/left: command + option + l/r arrow
    close a tab: command + w
  • Split the editor window: command + \
  • Comment out a block of code: with your selection highlighted or the cursor in the line you want to comment out, command + /
  • Toggle word wrapping when your code is overflowing the window: set your cursor in the window that you want to wrap, option + z

Editing

  • One feature in particular to highlight is something they call IntelliSense. They have an entire page on it, but long story short, it’s an autocomplete function that knows the objects in your application. It pops up automatically when you start typing, but if you want to trigger it to use things like code snippets, you can hit control + spacebar. It’s fun to play with once you know it’s there.
  • Move a block of text: with your selection highlighted or the cursor in the line you want to move, option + up/down arrow
  • Copy a block of text: with your selection highlighted or the cursor in the line you want to copy, shift + option + up/down arrow
  • (This one is probably my favorite because of the amount of time it saves.) Select all occurrences of the current selection. Once selected, it’s basically a find-and-replace — any edit you make to the current selection will happen in all the selections in the current file: with your cursor inside the thing you want to mass select, shift +option + L
  • Related to the above is multi-cursor editing, useful (for example) if you want to delete the last # characters from # different lines of seed data. Insert another cursor in the same location in the line above or below: option + command + up/down arrows

Advanced features

  • Code snippets are templates that make it easier to enter repeating code patterns. Need an example? I once spent an entire morning debugging something that turned out to be an initialize typo. Now I use a snippet whenever I need an initialize method so that I never have to experience that again. You can write your own; there are also lots available in their marketplace.
  • Extensions are a little bit like gems for Ruby. They’re code packages that create tools that do things like format or help you debug your code. I personally use Simple Ruby ERB and HTML snippets, but honestly, there are so many extensions out there that they could probably be their own article. If you’re curious about them, you can check out the documentation overview or browse the Visual Studio marketplace.
Photo by yours truly

Terminal

This is the big one that inspired me to write this article in the first place.

I’ve been an enthusiastic SC user for a long time, so when I started using Rails, I got a little queasy about some of the commands:

rails g controller <controller_name>

rails db:migrate

I mean, that’s pretty much a full paragraph compared to what I’m used to, not to mention there’s so much room for typos. Ugh.

One SC tip to rule them all

Then I found something. I kid you not, it was like getting the cheat codes for programming. That something, in their words, is “A delightful community-driven framework for managing your zsh configuration.” It’s called Oh My Zsh.

Quick note: I don’t have any affiliation with this product, and there may be others out there like it. I just happen to think this one rocks.

What is it? It’s a framework that sits on top of your zsh that automates a lot of really convenient features for you. I’ll quickly cover a few of my favorites.

File tabbing

You just ran ls to see what files are in the directory, and now you’re sitting there with a cd, but it turns out the first 13 characters of the directory you want are identical to another one (for example, not like I’ve ever been that dumb when naming something). No worries! Now you can just hit Tab to scroll through them. (Similarly, there’s a multi-level cd feature “cd ...” = 1 level, “cd ...” = 2 levels, “cd ...” = 3 levels!)

Themes

You may be thinking, We’re talking about brass tacks, shaving serious time off my programming, why is he bringing up an aesthetic feature? Well, turns out themes are more than just a pretty face. For instance, if you’re doing a lot of collaborative work with Git, a theme can replace the prompt line with the name of the branch you’re working on.

Plugins

The first two features are nice, but the plugins pushed Oh My Zsh from “nice to have” to “can’t imagine my life without it” for me. My jaw actually hit the floor. A plugin is a custom set of SCs that alias common commands. Put differently, if you set the Rails plugin, for instance:

rake db:migrate

becomes…

rdm

This is the tiniest tip of the iceberg. Think of all the ugliest, longest commands you possibly can, in whatever language, and you can bet there’s probably a plugin for that. Just thinking about the Git and Rails aliases makes me giddy. Please do yourself a favor and look into it. Here are the wiki and the very extensive list of plugins.

That’s all I’ve got for now: go forth and become an SC ninja! As with any work like this, decisions had to be made on what to include and what not to include. If you love something that I didn’t cover, share your love with the world and drop it in the comments.

Footnotes

Here are some cool footnotes:

¹ Modern internet clickbait culture refers to this concept as a life hack. Like many such things, it’s a very old idea that’s been gussied up with a seductive term to get pageviews. You can be sure that if cave people had been on the internet, there would be millions of articles titled “The One Life Hack That Will Change Everything: Cooking With Fire!”

² Let’s do some quick math on this. I have a line of code that I need to copy from the top of the file and insert into the code that I’m writing at the end of the file. Using shortcuts it takes me ~seven seconds. Using my trackpad (and right-click, which is faster than a pull-down menu), that same action takes me 14 seconds. That’s a seven-second difference. Let’s say I’m coding 45 weeks a year, five days a week, eight hours a day, and I have to perform (very conservatively) a similar action three times an hour. If I use my trackpad all year, I’ve spent an extra 37,800 seconds just copy-pasting things. That’s ten and a half hours!³

³Yes, this is a footnote to a footnote. This study from 2005 confirms those numbers. It also found that only 13%–19% of the people in their study used SCs regularly for cut/copy/paste functions. First, I pray that number has skyrocketed in the last 15 years. Second, here is a thought experiment that makes me physically uncomfortable: take the total number of U.S. workers who primarily work on a computer, multiply that by the fraction who do not use SCs, multiply that by the amount of time they would save if they did. I would wager that the number is larger than the paid vacation disparity between the U.S. and Europe (20-ish days). I’m only half kidding when I say I think we should have a national PSA campaign with WWII era posters like this one that says: “Have you REALLY tried to save time by using keyboard shortcuts?”

--

--

Spends lots of time neglecting his many hobbies because he’s coding. Never stop learning!