It is a common-place note that PyCharm is a keyboard-centric IDE. What does it mean? Actually, any action you perform in PyCharm - for example, opening a file for editing, navigation between editor tabs or between PyCharm's tool windows - can be done either via the menu commands, or the mouse pointer, or keyboard shortcuts. Doing something without menu or a mouse not only speeds up development, but is also just cool... However, if you've worked with some set of key combinations, you fingers have memorized them, and it's rather hard to change this habit.
So.. you have a long experience of working in Eclipse, or NetBeans, or you are a Vim addict? Then this tutorial is for you. It aims to walk you through selecting a keymap of your choice, and its further tuning.
The basics of keymaps, their location and their usage are out of scope of this tutorial. Find the detailed information on the page Configuring keyboard shortcuts. Refer also to the Keymap settings description.
This is most easy: on the main toolbar, click , and then, under the IDE settings, click the page Keymap.
On this page, select the keymap of your choice from the Keymaps drop-down list:
Then apply changes - and here you are. For example, if you've selected Eclipse keymap, you can enjoy deleting a line with Ctrl+D.
What will you do if your favorite keyboard shortcut is still missing from the keymap you've selected? In this case. you have to change your keymap.
Let's consider the following example: you've selected an Emacs keymap, but there is no pre-defined keyboard shortcut for deleting a line:
You want to associate this action with the keyboard shortcut Ctrl+D. This is how it's done:
- Click to open the Settings dialog, and then, under the IDE settings, click the page Keymap.
- From the Keymaps drop-down list, choose Emacs.
- Then in the content pane of actions, expand the node Editor Actions, and locate the action Delete Line.
- Right-click this action, and choose Add Keyboard Shortcut on the context menu:
- In the First Stroke field of the Enter Keyboard Shortcut dialog box, type the shortcut you want to use:
Important! Use exactly the same keys you want to use. For example, if you want to define a keyboard shortcut Ctrl+D, press two keys: Ctrl and D.
If you've mistyped a key, use YOUR MOUSE POINTER ONLY to delete the wrong entry! Any key you press (for example, the everlasting Backspace or Escape) will be interpreted as a keystroke!
- Next, pay attention to the conflict reported in the dialog box: the keyboard shortcut Ctrl+D is already in use! PyCharm has this shortcut associated with a certain action, which, luckily, is not used so often. Click OK.
PyCharm displays the warning, where you choose to remove the old assignment:
- Now look at the Keymaps field:
You see that instead of the Emacs keymap you've selected, appears another keymap with the name Emacs copy. The reason for such a behavior is that PyCharm cannot modify the pre-defined keymaps, but only their copies. You can, actually, create a copy first, and then modify it to your taste, but why bother, if PyCharm does it automatically? So just click OK to apply changes and close the Settings dialog.
Let's test how it works. Open a file for editing, place the caret at the line to be deleted, and then press Ctrl+D - great! The line is really deleted