Michael
Michael

Reputation: 73

PyCharm comment print lines

Is there any shortcut in the IntelliJ IDE such as PyCharm to comment all the lines start with 'print'?

Since during the debug I always write many prints, after the code runs well I want to find a convenient way to comment on all lines starting with 'print'. Now I select each line/block with command + / which is trouble.

Upvotes: 2

Views: 1275

Answers (3)

Rohit Joshi
Rohit Joshi

Reputation: 182

Why not just:

Find: print(
Replace: #print(

And, to get back:

Find: #print(
Replace: print(

This worked pretty well for me. I don't find the reason for using complex regex for this.

Upvotes: 0

Michael
Michael

Reputation: 73

Find: (^[ \t]*)(print)
Replace: $1## $2

Upvotes: 3

flurble
flurble

Reputation: 1106

Not sure about pycharm, but I guess you could use find/replace with a regex like '^print' and substitute with '# print'. Maybe you can even make this a macro / Hotkey in pycharm.

Upvotes: 1

Related Questions