Reputation: 4271
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?
Upvotes: 8
Views: 1335
Reputation: 95901
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).
Upvotes: 12