Pycharm has the function to "surround with" pieces of code. There are some already setted up functions:
I would like to add print()
(using python3) to it, how can I do?
Press Ctrl+Alt+S to open the IDE settings and select Editor | Live Templates. Select the template group where you want to create a new live template (for example, other). If you do not select a template group, the live template will be added to the user group. and select Live Template.
By default, PyCharm suggests to print the name of a file $FILE$ in the header and the current page number $PAGE$ of all pages $TOTALPAGES$ in the footer. The following print keywords are recognized: $FILE$ prints fully qualified filename. $PAGE$
Live templates Last modified: 12 May 2022. Expand a live template: Tab. Configure: Ctrl+Alt+S Settings/Preferences | Editor | Live Templates. Use live templates to insert common constructs into your code, such as loops, conditions, various declarations, or print statements.
Shortcut: shift + control + F10.
AFAIU, you can define your own “Live” templates for this.
Go to File
→Settings
→Editor
→Live Templates
. In the right pane tree, click on Python then click the green “+” button on the right; select “Live Template”.
Enter a name for Abbreviation (e.g. “printer”), a Description, and then in the Template text:
print($SELECTION$)
Afterwards click on the “Define” of the “No applicable contexts. Define” line at the bottom. Select “Python” in the tree. This step is important!
Now your template will be usable by the Code
→Surround with Live Template
action (in my case, the shortcut is Ctrl+Alt+J).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With