How to surround selected text in PyCharm like with Sublime Text

28,533

Solution 1

I think you want something like

Settings | Editor | General | Smart Keys -> Surround selection on typing quote or brace

Solution 2

PyCharm 4.0 has the option to Surround With..., by selecting your code snippet and pressing

ctrl + alt + T

or on Mac: + + T

Option 1 should provide you with the functionality you are looking for:

PyCharm Ctrl+Alt+T

Solution 3

Windows: open pycharm and select file, settings, Editor, Smart Keys, in the list you will check "Surround selection on typing quote or brace", then apply. enter image description here

Image of pycharm location of smart keys

Share:
28,533
Alexis Benoist
Author by

Alexis Benoist

Updated on July 08, 2022

Comments

  • Alexis Benoist
    Alexis Benoist almost 2 years

    Is there a way to configure PyCharm to be able to surround selected code with parenthesis by just typing on the parenthesis key, like when we use SublimText 2?

  • Nic
    Nic about 8 years
    On Windows, this is File | Settings instead of Preferences
  • Douglas Henrique
    Douglas Henrique almost 8 years
    I tried this, but it also adds a line break. If I have, say, "print doc", select "doc" and apply this, "doc" turns into "(doc)", as expected, but it goes to another line.
  • j_walker_dev
    j_walker_dev over 7 years
    @DouglasHenrique that behavior should be able to be changed using the $END$ live template variable.
  • Shovalt
    Shovalt about 7 years
    This results in a behavior similar to that in Jupyter Notebook, which makes the switch between the two much smoother. Thanks!
  • framled
    framled about 7 years
    on mac is Preferences instead of Settings
  • ruslaniv
    ruslaniv about 3 years
    Just to clarify, once this is enabled, go to your code editor window and select part of the text you want wrapped in quotes and then just type SHIFT + ' for example.