Saturday, 17 January 2015

tldr: If you don't have the time to read the entire post, just read Productivity Guide, because I assume that you want better productivity as your primary goal.

PyCharm is a very powerful IDE, and has a multitude of features that keep growing at a large pace. PyCharm is essentially, a plugin built on top of the IntelliJ platform, Jetbrains' main IDE. Because PyCharm borrows from a whole host of features available from IntelliJ, its easy to get lost.

This post shows you some of the best features that PyCharm has to offer, and how to use those features properly. I assume that you've installed plugins and know your way around the IDE. The table of contents should give you an idea of what is covered in this post.

Productivity Guide You might not know this, but PyCharm tracks what features you use, and tells you how productive you are being in your productivity guide: The productivity guide gives you detailed descriptions of what features can help you code faster. You can see below that although I don't use all the features, I do use some quite a lot:

Starting Out PyCharm touts its project creation wizard a lot, and for Windows users is a godsend because you can easily create a project and associate a virtualenv with it. However for *nix users, the best option is to start PyCharm from the command line, and you can do this by creating a command line launcher: There is one thing that you need to know about starting from the command line is that PyCharm uses the interpreter that the python command is linked to. So for example, if your python command in the shell links to /usr/bin/python , then that interpreter will become the interpreter for your new project. However, if you want to have the interpreter as a virtualenv, you have to create the virtualenv, activate it and then use the command line launcher to initialize your project. If we do the following: $ mkdir SimpleProjectDir $ cd SimpleProjectDir $ charm . It would create a PyCharm project in SimpleProjectDir and use the default interpreter in the shell like so: We can see that it is the same python that was linked to in our shell: $ which python /usr/local/bin/python However, if we were to create a virtualenv beforehand and then create a project using the command line launcher, we would get the virtualenv as the interpreter instead: $ mkdir SimpleProjectDir $ cd SimpleProjectDir $ virtualenv .venv New python executable in .venv/bin/python2.7 Also creating executable in .venv/bin/python Installing setuptools, pip...done. $ source .venv/bin/activate ( .venv ) $ charm . In simple terms, whatever python points to in the shell at the time of using the command line launcher, PyCharm will adopt that interpreter as the project interpreter.

Keyboard Shortcuts Keymap PyCharm allows you to see all your keyboard shortcuts using the Keymap. Keymap has two key features which aid in development. One being the ability to find keyboard shortcuts based on what they're called: But it also allows you to find shortcuts based on the keys themselves, so that you can talk other people about them: So, whenever I talk about an action like "Find Action" or "Search Anywhere", just search it up on your keymap to see the corresponding keyboard shortcut. Find Action The best way to learn Keyboard shortcuts is to use Find Action. Every time you use an action using find action, the keyboard shortcut is also denoted on the right: Whatever you find yourself using over and over again through Find Action, just commit it to memory and you'll be saving yourself some time. Useful Shortcuts Use the Keymap to find what shortcuts these commands refer to: Find Action

Search Everywhere

Find

Structure

Add Selection for Next Occurrence

Switcher

Check In Project

Syntax Aware Selection

New The first two features are must use shortcuts, and will aid you in learning more shortcuts as you see fit. The others are shortcuts I use regularly, and find helpful.

Navigation This section covers how to get from place to place. I've divided it into two sections. One being Macro and the other being Micro. Macro is about moving between files, panels and tools. Micro is about moving from place to place within a file. Macro Back and Forward This is one of my most favorite features. Back and Forward allows you to go back to the place where your cursor was previously. This is immensely powerful, and allows you to jump between places within files and places between files. Let me demonstrate: Search Everywhere We need to find stuff all the time like functions, files, classes and methods. The best way to search for classes, files, and directories is to use Search Everywhere (press SHIFT in quick succession): Switcher The other way is to use the Switcher, which gives you quick access to your most recently used panels and files: Micro Structure In order to find things within files, its best to use Find, and for a more structural view, use Structure. The Structure panel gives you a skeletal view of your file, with variables, classes, functions and methods. It allows you to quickly navigate between important structures within your file: AceJump AceJump is a plugin that allows you to quickly jump from place to place. Its a clone of Emacs' AceJump mode. There are two superb videos by the creator of AceJump, John Lindquist on how to use the plugins. Installing a plugin is simple: