PyCharm — Tips & Tricks
by Lucian Corduneanu • over 4 years ago • 5 min read
We are human, we are different, we are curious. Although not everyone agrees software developers are regular humans, we can all agree that devs are obsessed with being efficient not only in their professional life but also beyond.
I am using JetBrains products since 2010, and they served me well in my career. In this post, I want to share my favorite shortcuts that I use to boost my productivity. Will briefly point them out one by one ordered by my personal preferences.
Go back where you last edited
- Action:
Last edit location
There are some discussions about how much time a developer actually spends writing vs reading code. I can personally tell from my experience, that I spend around 30% of the time writing code while the rest goes on navigating around, reading code, reading manuals, figuring out where things should end up in order to keep consistency and make life easier for other devs and future me.
We all know how to navigate through a bunch of files and scroll files to read the codebase. Now imagine there is a big project with 2000+ files. You start to write your first service class method, then pause, look around and read unit tests, observe patterns from other places, reply to a Slack message, and after about 2 minutes, you are kind of lost. What exactly am I doing here? Where did I start?
Wouldn’t it be cool to have a quick shortcut to go back to where you last edited?
This is by far my favorite shortcut, that helps me get back on track fast because I’m used to changing contexts/projects many times a day.
Note that, you can search for all available actions
. I'd just point out the name of the action
for you to search.
Navigation
- Actions:
Navigate Back
andNavigate Forward
We are all browsing the web. Imagine life without back buttons :) Hard to imagine, right? I find back/forward shortcuts especially useful when I navigate through different layers like models, view, serializers then back to models, then to services.
At some point, I reach that “aha moment” and want to go back to validate it, precisely in the reverse order of screens I saw before having that moment.
Also, there are other useful navigation shortcuts. I especially use Go to Class
and Go to File
. However, if you want to search everything just hit Shift + Shift
(double Shift key). It will search through classes, method names, files, actions, etc.
Rename class, file, and variable names
- Action:
Rename...
PyCharm is indexing the world. Wait whaaat? Yeah, I was speaking about your Python projects. Isn't that your world? Good. Since I kind of "suffer" a bit of OCD, I constantly ask myself if a class or method name is really expressing their true intensions. I am very careful to write clean code. And guess what - I abuse the renaming feature, that not only helps me to rename something in the current file but renames it everywhere. Even within strings, comments, import statements, and many other places.
I suggest you to be especially careful when renaming a rather generic name, PyCharm magic can go wrong. E.g. renaming things in your migration files also (that you almost never want to). Hit that Preview
to see exactly what is going to be renamed.
Refactor - Move things around
- Action:
Refactor Move
Did you ever want to move a bunch of classes with or without inheritors to different locations? It is so annoying to do it manually and figure out which imports you need to cut and paste. I'd use this action instead.
Extract methods and variables
- Actions:
Extract Variable
andExtract Method
Keep your methods as short as possible, but of course, while experimenting with things and hacking your way to make something work, you are careless about how big and ugly your method is. Now that you have a proof of concept, let’s be professionals and take a few moments to clean it up. Use meaningful variable names and extract logic blocks within different methods.
Recent files
- Action:
Recent Files
Again comparing it to a web browser feature, the navigation history is particularly useful when you remember that you saw a website, but don’t remember its name. I usually use this when I know that I recently opened a file that I need at the moment, but can’t manage to remember the full name.
Others worth mentioning
- Action:
Extend selection
- Actions:
Clone Caret Above
andClone Caret Below
- Action:
Replace...
Conclusion
There are endless possibilities. Check out the PyCharm Settings. Go nuts and even edit your favorite shortcuts to stay on top of your skills, impress your fellow devs with your ability to move fast, without ever using your slow mouse to get the job done.
What are your favorites?
What other powerful IDEs are you using? Let's start a debate on this.
Thanks for reading.
Dev Thoughts
How to migrate a PodBean podcast website to a custom website with Nginx permanent redirects
by Lucian Corduneanu • 6 months ago• 13 min read
The Product Owner’s View: Building a Streamlined Transport Management System
by Alexandra Voinea • 6 months ago• 5 min read
Improve Your Dev Journey: Essential Skills Beyond Just Coding
by Dragos Ispas • 6 months ago• 5 min read