PyCharm Flashcards
Effective PyCharm 9 topics
- Projects
- Editor
- Git
- Refactoring
- Databases
- Debugging
- Profiling
- Testing
- Packaging
Projects: 4 kinds of roots
- Source roots: for resolving imports
- Resource roots: images, style sheets
- Excluded: ignored by PyCharm
- Template folder: templates
Projects: Add installed package to requirements.txt
Right click on the import > Add imported packages to requirements.txt
Projects: search everywhere
Double Shift:
1. Search classes
2. IDE actions
3. files
4. Git
Projects: search show_leaderboard()
Double shift > s_l
Editor: create a function in module by simply calling the function
alt+enter
mymodule.new_func() # Create function new_func() in module mymodule.py
Editor: install a package by simply calling the package’s function
resp = requests.get(url) # alt+enter # 'Install and import package 'requests'
Editor > Live Templates
main
turns into ‘if __name__ == ‘__main__’
Search settings for ‘Live Templates’ to edit templates
Hot key for arguments tooltip
Ctrl + P
Turn regular string into f-string
print('{e') # autocompletion pop-up with available variables
To enhance autocomplete…
provide type hints
~~~
def my_func(arg) -> Optional[User]
~~~
How to discover new features?
Open action palette and search for stuff:
~~~
Ctrl + Shift + A
~~~
Find usages
F7
Pre-commit settings
You can optimize imports and reformat the code in the commit window
Select only certain changes for a commit
In the git palette on the left click ‘diff’ icon and press checkmarks next to the changes you want to include
Create label in local history
Right click - Local history - Put label…
‘Refactor this’ hotkey
Ctrl + Alt + Shift + T
^ T (Mac)
5 Main Refactor tools
1. Extract/introduce Variable/Constant/Parameter Object/Method/Field/Superclass 2. Inline is the opposite of extract/introduce 3. Pull class members up/down 4. Move (a class) to another file (or drag and drop them) 5. Move to a package
Visualize only specific tables
Select tables and click visualization
Debug: conditional breakpoint
Add Condition checkmark
or click More on the breakpoint pop-up
Profiling the app
Click Profile icon (3rd from the Run)
Enable custom config .ideavimrc
Click on the IdeaVim icon > Enable .ideavimrc
My Custom IdeaVim enable/disable hotkey
Alt+v
Settings > Keymap > search ‘vim’ > Tools - Alt+v
My Custom VCS Next/Previous Change
Alt + PgUp
Alt + PgDn
My Custom Git Blame hotkey
CTRL+SHIFT+ALT+A
Show autocomplete
CTRL+Space
Add annotations
ALT+Enter
Choose annotation
Change selection CASE
Select
Shift x2
type ‘case’
PyCharm Actions
CTRL+SHIFT+A
(show line numbers)
Select a word or a keyword (if)
CTRL+W
Select the whole string or the whole keyword statement (if)
CTRL+W+W
Select the whole string with quote marks
CTR+W+W+W
Select the whole call within brackets
CTR+W+W+W+W
Shrink the selection
CTRL+SHIFT+W
Move line down
Action Palette: CTRL+SHIFT+A
Move Line Down (mld)
Surround code with boilerplate (try/except etc)
CTRL+ALT+T (Ubuntu terminal)
CTRL+SHIFT+A > ‘surround’
Return to the previous wrap state (unwrap)
CTRL+SHIFT+DELETE
Multiple Selection
ALT+J at the caret
ALT+J again to the next occurence
(put cursor at ‘th’ <th>Text</th>)
Deselect previous occurrence (remove second cursor)
ALT+SHIFT+J
Select all occurrences in a file
CTRL+ALT+SHIFT+J
Recent (edited) locations pop-up
CTRL+SHIFT+E
Navigate between errors or warnings
F2
Shift+F2
Browse through methods
Alt ↓
Alt ↑
Go to a line in code
or
a column in a database
CTRL+G
CTRL+G :column_name
Plugin for hotkey learning
Key Promoter X: shows hotkeys for actions.
Suggests creating hotkeys for actions without default hotkeys
Custom hotkey for opening database window
ALT+D
Custom hotkey for Refactoring menu
Default: CTRL+SHIFT+ALT+T
Custom: ALT+T
Open Services window
ALT+8
Replace and not insert autocompletion
CTRL+SPACE
Select autocompletion
Tab
Postfix ‘if is not none’ completion
movies_dict.get(‘year’)
Type .if
Select .ifnn for ‘if is not None’
Type-matching completion
CTRL+SHIFT+SPACE
F-string completion
{my
Select popped up Autosuggestion
Quickly select item from Refactoring Menu
Invoke Refactoring Menu: ALT+T
Type ip for ‘Introduce Parameter’
Refactor - Rename - Exclude item from renaming
SHIFT+F6
Refactoring Preview window at the bottm
Select item to remove
Delete
Refactor: Extract Variable
CTRL+ALT+V
Refactor: Extract Method
CTRL+ALT+M
Settings: disable code drag-n-drop
search for “Move code fragments with drag-and-drop”
Recover parts of code from Local History
Local history - click on a chevrone
Reformat selection/whole file
CTRL+ALT+L selection or whole file
Reformat settings
CTRL+ALT+SHIFT+L
Method’s signature
Caret in ():
CTRL+P
Quick documentation
CTRL+Q
Pop-up definition at caret
CTRL+SHIFT+I
Go to the next highlighted error
F2
Expand warning description
CTRL+F1
Highlight all usages within a file
CTRL+SHIFT+F7
Search only for classes
CTRL+N
Search only files
CTRL+SHIFT+N
Look for a method or global variable
CTRL+ALT+SHIFT+N
Search for a whole word in Files window (CTRL+SHIFT+F)
CTRL+W
Replace in Files window
CTRL+SHIFT+R
Jump to declaration of method/its usages
CTRL+B
Detailed view of usages
ALT+SHIFT+7
Pin the search in Find tab
Right Click > Pin
Find tab
ALT+3
See file structure
CTRL+F12
Recent files window
CTRL+E
Delete files from recent history
DEL
Discover your code in recently visited files
CTRL+SHIFT+E
Set a break point on a line
CTRL+F8
Run a debugger
SHIFT+F9
Quick Evaluate a variable in debugger
CTRL+ALT+8
View type hierarchy
CTRL+H
View call hierarchy
CTRL+ALT+H
Using RegEx find ext…Select in ‘Find in files’ window
CTRL+SHIFT+F #enable regex search via ALT+X ext.*Select
Last Edit Location
Ctrl+Shift+Backspace
Toggle inline hints for codeium
ALT+H
Disable codeium
ALT+C
Codeium chat
ALT+B