94

Sublime Text has this functionality where you can select text and start editing each line with a (multiple) cursor:

enter image description here

Is there PyCharm equivalent?

4

12 Answers 12

103

Another option: with text selected, toggle column selection mode:

enter image description here

The default shortcut to toggle the mode is:

  • Linux/Windows: alt-shift-insert
  • Mac cmd-shift-(numpad) *

(or EditColumn Selection Mode)

It's an inconvenient shortcut for Mac, as most laptops have no numpad. I remapped it to cmd-shift-8.

Column selection mode actually has other purposes too: it changes the default behavour when selecting text with the keyboard and mouse. Toggle it off again to return to normal selection behaviour.

2
  • 3
    In phpstorm 10, I found I can press cmd-shift, then click twice 8. ;p
    – shrekuu
    Mar 25, 2016 at 2:54
  • Thanks, this helped me.
    – akarthik10
    Jul 11, 2017 at 21:06
70

From source:

To add carets, do one of the following

  • Press Shift+Alt and click the LEFT mouse button at the location of the caret.

  • Double-click Ctrl and press up arrow or down arrow keys.

On OSX it seems to be enough to press down the LEFT-ALT and add new carets with mouse LEFT CLICK, or press down SHIFT+ALT and paint the cursors with mouse.

6
  • 4
    In addition there's Alt + J that allows you to select the next occurrence of your selection. Apr 18, 2015 at 16:19
  • 1
    Thanks. SHIFT+ALT is what I was looking for. It is not exactly what Sublime Text does (converts existing selection to multiple cursors), but close enough. Apr 18, 2015 at 17:35
  • 2
    @BornToCode it seems to just be alt alone on Linux, for me, no shift. Additionally, many distros by default map one of the alts to a different keypress (meta or something), so try both the left and right alt keys. This can be changed, but the directions are different depending on your distro.
    – jeremyh
    Jan 18, 2018 at 4:17
  • 5
    @BornToCode one can try Ctrl+Shift+Alt +LMB (left mouse button)
    – peremeykin
    Apr 19, 2018 at 19:58
  • 1
    @fikr4n Shift-Alt does work on PyCharm 2019.2 on linux. It used to be only Alt (as it still is in CLion, for example)
    – David
    Oct 22, 2019 at 16:01
25

This functionality was added to Pycharm in June 2020.

It's called "Add Carets to Ends of Selected Lines", and is bound to Alt + Shift + G by default.

1
21

Hold Alt and drag the mouse over the desired text.

Source: https://www.jetbrains.com/help/pycharm/2016.1/selecting-text-in-the-editor.html

1
  • 2
    out of all the answers, your answer was most simple and useful. Thanks @Vagelis
    – Ash Singh
    Jun 23, 2017 at 6:29
8

To do this on Linux (tested on Ubuntu 16.04), do as follows:

In your editor, press Alt + Windows Key and use your mouse to place the cursor on the lines you want to have multiple cursors on.

You may also want to allow placement of caret after the end of line or inside tabs. In that case you need to change your settings:

Go to Editor -> Generaral -> Virtual Space:

  • [x] Allow placement of caret after end of line
  • [x] Allow placement of caret inside tabs

And make sure the above mentioned two settings are enabled.

5

You can use plugin Extra Actions.

You must add a combination to this action:

Split Selection into Lines

No shortcuts are set by default.

You can easily set them by going to

Settings > Keymap > Plugins > Extra Actions

Configuring keyboard shortcuts.

4

Press SHIFT + DownArrow ( instead of mouse and drag) in pycharm for multi cursor editing

2

The simple way I think is to select the text and go on pressing Alt + J for Linux and Ctrl + G for Mac until you reach the last match.

PyCharm blog

1

Sublime like features for MacOS X in PyCharm:

Select/Unselect the next occurrence with Ctrl+G / Shift+Ctrl+G

Select all occurrences at once with Ctrl+Cmd+G

Remove occurrences with ESC

0

you can use alt + shift + G for selected lines to enable caret for them and use Home and End buttons to go to the start or end of your line(s).

  1. select your line(s).
  2. press alt + shift + G
  3. press Home or End to go to the start or the end of your line(s).

you could also use alt + click for selecting by clicking and alt + J to select same values.

0
{
    "key": "ctrl+t",
    "command": "editor.action.insertCursorAtEndOfEachLineSelected",
    "when": "editorHasSelection && editorTextFocus && !editorReadonly",
},

ctrl+t - as an example.

-1

For macOS users: looks like if you hold shift + down or up arrow keys to select with multiple cursors.

image

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.