Pycharm notes

From raju

Current configuration

my favorite configuration

if version == 2019.3.3:

    • File -> Settings -> Appearance & Behavior -> Appearance -> Theme -> IntelliJ

else:

    • File -> Settings -> Appearance & Behavior -> Appearance -> UI Options -> Theme -> IntelliJ
  • File -> Settings -> Appearance & Behavior -> System Settings -> Project Opening -> select "Open project in new window"
  • scrollbar -> right click -> Customize Highlighting Level -> drag it to Syntax
  • File -> Settings -> Editor -> General -> Editor Tabs -> Tab Closing Policy -> Tab limit - 20 -> OK

useful shortcuts

go to the location of current file in the project tool window

Alt+F1 -> 1

Ref:- https://intellij-support.jetbrains.com/hc/en-us/community/posts/206737795-Show-current-file-in-Project-view-

view just the functions

Ctrl+F12

Ref:- https://www.jetbrains.com/help/pycharm/viewing-structure-of-a-source-file.html

tags | show code outline

To go back after control clicking

  • Ctrl+Alt+Left arrow, Ctrl+Alt+Right arrow - to go back and forward
  • Ctrl+Tab - Switch to the last (most recent) tab -- similar to how Alt+Tab works

Ref:- https://stackoverflow.com/questions/25103626/in-pycharm-how-to-go-back-to-last-location

tags | coming back after navigating to a function

Jump to next/previous function

Navigating between editor tabs

  • Open a file already opened in another tab - Ctrl+Tab
  • Go to the right or to the left tab - Alt+Right or Alt+Left
  • Go back and forth through the history of visited tabs - Ctrl+Alt+Left, Ctrl+Alt+Right

view function definition

folding

  • Ctrl+NumPad Plus - Expand the current fold
  • Ctrl+NumPad - - Close the current fold
  • Ctrl+Shift+Plus - open closed folds

Ref: https://www.jetbrains.com/help/pycharm/code-folding.html

tags | expand import stanza by keyboard

editing

switch between open projects

  • Window | Next Project Window Ctrl+Alt+]
  • Window | Previous Project Window Ctrl+Alt+[
  • Window | <ProjectNameOrLocation>

project tool window

formatting

  • format the whole file - ctrl+alt+L
  • format a selection - ctrl+alt+l

Ref:- https://www.jetbrains.com/help/pycharm/reformat-and-rearrange-code.html

tags | realign selected code

change indentation

multiple selections

To select multiple blocks of text

    select first block normally
    press ALT key for all the subsequent blocks.
    

dummy

release history

    released, version
    2020-04-07, 2020.1
    2019-10-31, 2019.2.4
    2019-09-25, 2019.2.3
    2019-07-30, 2019.1.4
    2019-05-29, 2019.1.3
    2019-05-07, 2019.1.2
    2019-02-26, 2018.3.5
    2019-01-29, 2018.3.4
    2018-09-19, 2018.2.4
    2018-04-09, 2018.1.1
    2017-09-05, 2017.2.3
    2017-08-23, 2017.2.2
    2017-07-11, 2017.1.5
    

Ref:-

run git bash in the terminal

  • File -> Settings -> Tools -> Terminal -> Shell path = "C:\Program Files\Git\bin\bash.exe" --login

The quotes are important

Ref:- https://stackoverflow.com/questions/20573213/embed-git-bash-in-pycharm-as-external-tool-and-work-with-it-in-pycharm-window-w

add new python interpreter

tags | python interpreter not available in the run configuration

Click the Project Interpreter widget in the lower right hand corner of pycharm window.
See https://www.jetbrains.com/help/pycharm/guided-tour-around-the-user-interface.html for a pic. It is part of the status bar which is at the bottom.
-> Add Interpreter

change python console interpreter

File -> Settings -> Build, Execution, Deployment -> Console -> Python Console -> select the Python interpreter from the dropdown.

Ref:- https://www.jetbrains.com/help/pycharm/console-python-console.html

go to a line

Use Ctrl+g

sort after

  • search for whole words - \bfoo\b


Ref:- https://www.jetbrains.com/help/pycharm/regular-expression-syntax-reference.html


links to the documentation

tags | git log branchA..branchB

useful links

troubleshooting

Change PYTHONPATH

Run -> Edit configurations -> Environment variables -> click the three dots icon

Add something like

    PYTHONPATH
    c:\path\to\dir1;d:\path\to\dir2
    

Send output from a run to a file

    Edit Configurations -> Logs tab -> check "Save console output to file" -> provide the full path of the output file.
    

This will redirect both standard output and standard error. On subsequent runs, it overwrites the previous file.

Ref:- https://stackoverflow.com/questions/21568810/how-do-i-redirect-input-and-output-with-pycharm-like-i-would-on-the-command-line

missing features

  • Pycharm does not correctly hightlight a multiline todo item inside the comments. It assumes that a todo item is always just a single line.

Ref:- https://stackoverflow.com/questions/48645942/how-do-i-format-a-multi-line-todo-comment-in-pycharm

  • If you have a split screen, it is not possible to click on a function call and have its definition open in the other split screen.

Ref:- https://stackoverflow.com/questions/37074172/pycharm-jetbrains-ide-go-to-declaration-on-other-split-screen

tags | open function definition in a different split

functions are not clickable

tags | cannot find function, not able to find imported functions, python path files in another directory, sources root, control click, functions are not clickable

Add appropriate directory as a content root

    File -> Settings -> Project: foo -> Project Structure -> Add Content Root
    

See also:

convert single quotes docstrings to double quoted docstrings

Code -> Inspect Code -> Whole project -> Python ... -> Convert docstring to the triple double-quoted string form

Ref:- https://stackoverflow.com/questions/39648917/how-do-i-make-all-the-docstring-using-triple-double-quotes-instead-of-triple-sin

key words

  • navigation bar

wrap lines

    View -> Active Editor -> Soft-Wrap
    

Ref:- https://stackoverflow.com/questions/38585204/pycharm-to-toggle-soft-wrap-in-code-editor

useful videos

Tips

block selection

  • You can easily make column selection by dragging your mouse pointer while keeping the Alt key pressed.

How can I

show all unresolved references

    Code -> Inspect Code