Text Editor in PyCharm

Contents
Introduction
Place the cursor at the beginning of several lines in a row
Vertical line limiter
Split the window into two parts
Switch between the terminal and the code editor
Remove the green background from the code
Comment out the selected code
refactor: Rename a function in a file
Wrap the code
Related articles

Introduction

PyCharm is an integrated development environment for the Python programming language. It provides code analysis tools, a graphical debugger, a unit test runner, and supports web development on Django. PyCharm is developed by JetBrains based on IntelliJ IDEA.

PyCharm is a cross-platform development environment that is compatible with Windows, macOS, Linux. PyCharm Community Edition (free) is licensed under the Apache License, and PyCharm Professional Edition (paid) is proprietary software.

Pycharm: Place cursor at beginning of multiple lines in a row

If you need to add or remove something from several lines that go in a row

Place the cursor in the desired place on the top line

Multiple cursors at once in PyCharm image from the site www.aredel.com

Press CTRL then CTRL again and do not release it. Press the down arrow the required number of times.

Multiple cursors at once in PyCharm image from the site www.aredel.com

Vertical line line length limiter

A vertical line after a certain number of characters helps to understand that the line has become too long.

What is considered too long and what is not is usually decided on the project.

PEP 8 limits the length to 79 characters.

Limit all lines to a maximum of 79 characters.

For flowing long blocks of text with fewer structural restrictions (docstrings or comments), the line length should be limited to 72 characters.

The documentation for Django recommends a line length of up to 119 characters. This is due to a limitation in GitHub

An exception to PEP 8 is our rules on line lengths. Don’t limit lines of code to 79 characters if it means the code looks significantly uglier or is harder to read.

We allow up to 119 characters as this is the width of GitHub code review; anything longer requires horizontal scrolling which makes review more difficult.

This check is included when you run flake8. Documentation, comments, and docstrings should be wrapped at 79 characters, even though PEP 8 suggests 72.

The popular Python linter Black limits the length to 88 characters.

You can set the position of the vertical line in PyCharm in

File → Settings → Editor → Code Style → Hard wrap at

Установить вертикальную линию в PyCharm изображение с сайта www.aredel.com

Split window into two parts

There are different ways to split a window into two parts

Half on the left, half on the right: select the desired tab → right-click → Split Right

Half on the bottom, half on the top: select the desired tab → right-click → Split Down

If you do this, the tab will split into two - the same file will be visible both in the old tab and in the new one (on the right or bottom)

To simply move the tab to the new half of the screen, select Split and Move Right or Split and Move Down

Switching from the terminal

To quickly switch between the terminal and the code editor, you can use the following method

Press

ALT + F12

The terminal will be hidden if active and will appear if hidden. The cursor will automatically jump back and forth.

Remove green background from code in PyCharm

If a fragment in another language is inserted into the code, PyCharm can highlight it in green.

If there is a lot of such code, it becomes unpleasant to read.

This is especially true for Dockerfile

You can solve the problem by disabling the highlighting in the injected language fragment

Settings → Editor → Color Schema → General

injected language fragment PyCharm изображение с сайта www.aredel.com
injected language fragment

Switch off Background

injected language fragment PyCharm изображение с сайта www.aredel.com
injected language fragment

Comment out the highlighted code

To comment out the highlighted code, click

CTRL + /

In the same way, the selected area can be uncommented

Rename a function in a file

To quickly rename a function inside a file, select the function name and press

SHIFT + F6

The rename window will appear, in which you will be asked to replace the old function name (in the example - get_network_targets) with a new one (in the example - post_network_targets)

refactor rename function PyCharm image from www.aredel.com
Rename function

If you need to replace only in one file - Scope should be selected as Current File

Click Refactor

A preview will appear at the bottom right. Study it if necessary and click Do Refactor at the bottom left.

Wrap the code

Ctrl + Alt + T

Remove Wrapping

Ctrl + Shift + Delete

Wrap the code image from www.aredel.com website
Wrap the code
https://aredel.com

Wrap the code image from www.aredel.com website
Wrap the code
https://aredel.com

Wrap the code image from www.aredel.com website
Wrap the code
https://aredel.com

Wrap the code image from www.aredel.com website
Wrap the code
https://aredel.com
Related Articles
PyCharm: IDE
Install
Add Path to Project
Editor Basics
Python
Add Selenium to PyCharm
Banner Image

Search on this site

Subscribe to @aofeed channel for updates

Visit Channel

@aofeed

Feedback and Questions in Telegram

@aofeedchat