Search code examples
pythonideselectionpycharmbraces

select content between paired brace in pyCharm or any IDE


I just wonder is there any shortcut to select content in the paired brace instead by selecting them manually in pyCharm or any other IDE? For example,

I want to select

np.mean((predicted == validation).astype(float))

from

print('\n Accuracy:' + str(100*np.mean((predicted == validation).astype(float))) + '%')

So I do not have paired everything and verify it by myself.


Solution

  • You can use extending selection Ctrl + W. Place the cursor inside and repeat pressing until everything you want is selected. To shrink the selection use Ctrl + Shift + W.

    For your example extending selection will work as follows if you place cursor on predicted:

    predicted
    predicted == validation
    (predicted == validation)
    (predicted == validation).astype
    (predicted == validation).astype(float)
    ((predicted == validation).astype(float))
    np.mean((predicted == validation).astype(float))
    

    If you place it on mean, it goes as follows:

    mean
    np.mean
    np.mean((predicted == validation).astype(float))
    

    Experiment to get a feeling for it.

    There is also smart selection with Ctrl + Alt + V, but this is explicit for refactoring. Try it and see if it is what you need. It will split the expression by creating a new variable, assigning the selected expression to it and use the variable in the outer expression. So if I use it for your expression selecting your part it will refactor it to:

    mean = np.mean((predicted == validation).astype(float))
    print('\n Accuracy:' + str(100* mean) + '%')