Notes From Learning Pycharm
Notes From Learning Pycharm
PyCharm Shortcuts/Actions
Show Context Actions – Press Alt Enter (where PyCharm can guess your intention or propose
a fix for a warning or an error.
Find Action – Press Ctrl Shift A (lets you search through all available actions without having to
know their individual shortcuts)
Search Everywhere – Press Shift twice (you can look for your project code entities and other
IDE objects at the same time) [prob use this instead of Find Action]
Highlighting code – Ctrl W (press Ctrl W again and again to expand the highlight of the code
De-Highlighting code – Press Ctrl Shift W to shrink highlighted selection
Comment out any line with Ctrl Slash (Ctrl /). Uncomment with the same shortcut. Select
several lines with mouse and press Ctrl Slash to comment out multiple lines
Selecting current and previous line – Press Shift (up d-pad)[the up arrow] twice
Move Code Fragments – Press Alt Shift (up d-pad)/(down d-pad). This rearranges the lines
by doing a cut and paste that is usually two actions but turns it into one action!!!
To move the whole method, Press Ctrl Shift (up d-pad)/(down d-pad)
Surround and unwrap – To surround selected code fragment press Ctrl Alt T
To unwrap Press Ctrl Shift Delete
Multiple Selections – Press Alt J to select the symbol, Press Alt J again to select the next
occurrence of this symbol, Press Alt Shift J to deselect the last occurrence, **Press Ctrl Alt
Shift J to select all occurrences in the file, Type td to replace all occurrences of the th with td.**
**Tab Completion – suppose you want to replace [current] with [total]. Invoke completion by
pressing Ctrl Space, select [total] item, IF you press Enter, you will insert [total] before
[current]. Instead, press Tab to replace [current] with [total].**
Postfix Completion – helps you reduce backward caret jumps as you write code. It lets you
transform an already typed expression into another one based on the postfix you add, the type of
expression, and is context. For example, type .if after the parenthesis to see the list of
suggestions.
Type-Matching Completion – Pycharm has no direct info on the [x] type. Sometimes, it can
suggest completion by the context! Press Ctrl Shift Space to invoke Smart Completion. then
chose action as needed
F-string Completion – Pycharm Supports automatic f-string conversion. Start typing {my
complete the statement with [my_car]. Just press Enter to apply
the first item. the simple Python string was replaced by f-string after the completion.
Refactoring: Refactoring is the technique of changing an application (either the code or the
architecture) so that it behaves the same way on the outside, but internally has improved. These
improvements can be stability, performance, or reduction in complexity
Refactoring Menu – PyCharm supports a variety of refactorings. Many of them have their on
shortcuts. To access some rarely used refactoring, press Ctrl Alt Shift T and preview a partial
list of them. Suppose you are looking foa refactoring action to replace this expression with a
parameter. So we need to chose Introduce Parameter…. Now Simply type pa (introduce
parameter) or ip (introduce parameter) to reduce the proposed list. Press Enter to start the
Introduce Parameter… refactoring. Note that you can learn refactoring shortcuts from the
refactoring menu. To complete refactoring, you need to choose some name or leave the default
one and press Enter.
Rename – Press Shift F6 and rename the [teams] field(e.g., to [teams)number). In simple cases,
[teams] will just perform the rename refactoring without confirmation. However, in this sample,
PyCharm detects two calls of the [teams] method for objects with unknown types. Expand the
[Dynamic] item. It seems that [company_members] should be excluded from the rename
refactoring. Select it and press Delete. Complete the rename refactoring with the Do Refactor
Button.
Extract Method – Press Ctrl Alt M to extract the selected code block into a method.
Quick-fix refactoring -
In-place refactoring -
Restore Removed Code – restoring code using Local History. Example, you need to restore
code that you deleted in the beginning. The Undo action cannot help you because there were a
lot of changes and you might loose them. With Local History you can restore the deleted code.
Right the editor to invoke the context menu. Choose Local History – Show History. The left
pane of the Local History dialog displays a list of saved revisions of the current file. The project
state is automatically saved to Local History when you edit code, run tests, and perform other
actions.
Code Format – to reformat the selected code fragment with Ctrl Alt L.
reformat the whole file when no line are selected use Ctrl Alt L
use Ctrl Alt Shift L to reformat settings (here you can configure reformat
options
Editor Coding Assistance – Press F2 to go to the next highlighted error in the file. Let’s fix this
error. Press Alt Enter and select Import ‘math’ or Import this name -> math. Let’s go to the
next warning. Press F2. Also, you can see the warning or error description of the item at the
caret. Press Ctrl F1 to see a short description and press Ctrl F1 again to expand it. The popup
shows a refactoring action suggestion to fix this warning. Press Alt Shift Enter to remove the
unexpected argument. Another useful tool is the usages highlighting. Press Ctrl Shift F7 to
highlight all usages of the symbol at the care within the file.
Find and Replace in Files - Press Ctrl Shift F to open the Find in Files… window. type what
you want to replace. you can see context of what you want to replace. press enter on the row with
the context you want to replace to move to that file. Suppose you want to replace all occurrences
of that string. Press Ctrl Shift R to open Replace in Files… window. You can define the scope
of search and replace. Click the Directory button to narrow the replacement only to current
directory. Press Replace All to start refactoring. Finally, press Replace to confirm refactoring.
Declaration and usages – Press Ctrl B to jump to the declaration of a method. Use the same
shortcut Ctrl B to see all of its usages, then select one of them. Press Alt F7 to see a more
detailed view of usages. You can invoke Alt F7 on either a declaration or a usage. From the Find
view you can navigate both to usages and declarations. The next search will override these
results in the Find view. To prevent it, pin the results: Right-click the tab title, discriminant in
All Places. Select Pin Tab. When you have finished browsing usages, press Shift Escape to hide
the view. Press Alt 3 to open the Find view again.
File Structure – A large source file can be difficult to read and navigate. Sometimes you only
need to preview it. Press Ctrl F12 to open the file structure. Suppose you want to find a method
with Homo and Sapiens words in its name. Tupe hose (prefixes of the required words) to filter
the file structure. Only one item remains. Now press Enter to jump to the selected item.
Pycharm can also show you the file structure as a tool window. Open it with Alt 7.
Recent files and locations – to show recently opened files press Ctrl E.
Run Configuration –
Debug Workflow –
GIT – (Global Information Tracker) is a python library used to interact with git
repositories. It is a module in python used to access our git repositories. It provides abstractions
of git objects for easy access of repository data, and additionally allows you to access the git
repository more directly using pure python implementation. There is a local and remote
repository. You personally use the local repository to make commits that can be added to the
main branch of the remote repository. Your colleagues can also be doing this so sometimes you
will need to check for updates to the remote repository.
Commit – changes locally to record the snapshot of your repository to the project history, and
then pushing them to the remote repository so that they become available to others. After
performing a commit, you can push it to the remote repository.
Amend – if you forgot to add some changes to the last performed commit. select Amend
checkbox in the Commit tool window.
Rebase – Updating the featured branch in a remote git repository. be careful about Force
Pushing as it can get rid of colleagues commits.
Shelf – feature that allows you to save changes in a file on your computer. Changes stored in the
Shelf can be applied later to any branch. It helps you avoid losing these changes. Shelve
Changes to store the changes in Shelf. The Changelist is successfully save to Shelf and the
comment has disappeared.
NOTES
Caret - a mark (‸, ⁁) placed below the line to indicate a proposed insertion in a printed or written
text. (the flashing line where you click your mouse, the cursor)
De Morgan’s Laws – describe how mathematical statements and concepts are related
through their opposites. In set theory, De Morgan’s Laws relate the intersection and union of
sets through complements. In propositional logic, De Morgan’s Laws relate conjunctions and
disjunctions or propositions through negation.
F-strings – provide a way to embed expressions inside string literals, using a minimal syntax.
Cocktail Sort is a variation of Bubble sort. The Bubble sort algorithm always traverses
elements from left and moves the largest element to its correct position in first iteration and
second largest in second iteration and so on. Cocktail Sort traverses through a given array in both
directions alternatively.
JVM arguments are Java Virtual Machine – is a virtual machine that enables a computer to run
Java programs as well as programs written in other languages that are also compiled to Java
bytecode.