Favorite Pycharm Hotkeys!

When I started working at a new company and working in Django, I was using PyCharm for the first time, and had a workflow established in a different IDE. Reestablishing muscle memory around different hotkeys is definitely a challenge, and I find that I often only get around to looking things up in a fit of frustration/inefficiency. So in an effort to possibly help you avoid some of that, or just to show you a fun new shortcut you didn’t even know you should look up, here are just a few of my favorites (by no means an exhaustive list)! (These assume you’re working on a mac).

First, a legend:

  • ⌘: command
  • ⌥: option
  • ⇧: shift
  • ⌃: control

This one is cool, and I tend to find that other people (my sample size is small — making up only my own team, but still) aren’t aware of it. I’m frequently looking for a given method, but can’t remember if it’s in utils.py or directly in views.py or…well. If you know what your method is called, you can use this hotkey to find it! It can also be used on constant definitions.

This one is just what it sounds like — it allows you to search for a file by name/path without having to find it in the project directory. It’s worth noting that you don’t need to type the complete file names or paths for PyCharm to find you what you’re looking for.

For example, if you have a file that can be found at app_name/migrations/0006_…, you will be able to navigate to it by typing app/mig/0006. I’m a fan of saving keystrokes (and let’s be real, decreasing the odds that I’ll accidentally spell “organization” as “organziation”. I do this multiple times a day, and we don’t need to talk about it).

This one also does exactly what it sounds like it does — you can go directly to a model or other class definition anywhere in your codebase

  • Note: All 3 of the above hotkeys, by default, only look for symbols/files/classes within your own codebase. If you want to include symbols/files/classes that are defined within your libraries, pressing the same keys twice in quick succession will enable this (so you don’t have to check the nifty checkbox)*

Because when your console tells you you’ve got an error on line 4763, you don’t want to have to scroll all the way there to see what’s causing it (okay, hopefully your files don’t actually have that many lines in them, this command is helpful either way).

I’ve found this one to be less necessary in PyCharm than in some editors I’ve used because of its fancy “refactor” capability that allows you to rename a variable and it will do codebase-wide lookups for you to make sure you didn’t miss any.

But I still find that I use this a few times a week! If you select something that you want to find other instances of (within the same file only), you can hit ⌃-g — each time you hit it will highlight the next one found. It will tell you when you’ve reached the end of the file, and you can start searching again from the top, or not.

This is another one of my favorites that I find folks aren’t particularly aware of. I can never remember where the class or function I need lives when I’m importing (or maybe I’m just lazy and don’t like typing). If you’re using a function or class for the first time in a file and need to import it, you can hit ⌃+space twice in quick succession, and it will auto-import it for you (and finish typing it, if you didn’t). If there are multiple things you could be referring to, it will present you with an option from which you can choose. This works for functions and classes your codebase defines, as well as those from within Django or libraries.

To have a word or statement selected and wanting to wrap it in parentheses or quotes or any other bracket is pretty standard behavior to me, but by default, PyCharm doesn’t work like this — instead of wrapping your selection as has been the default in other editors I’ve used, it instead replaces your selection with the brace that you typed. This one took me too long to figure out how to fix(okay, too long to get annoyed enough by it to look it up for myself), so maybe I can spare you that! Find the relevant preferences here:

Preferences→Editor→General→Smart Keys→Surround selection on typing quote or brace

The description of the functionality is actually a bit misleading — it works more broadly than the name implies. “Brace” seems to be a stand-in for anything from a parenthesis or square bracket or curly bracket. It’s also worth noting that you need to type the opening brace for this to work, not the closing one (i.e { will work, while } will not).

Happy not-typing! I’d love to hear if you’ve got any go-tos that aren’t included here!