spyder icon indicating copy to clipboard operation
spyder copied to clipboard

Add multiline editing to the Editor

Open spyder-bot opened this issue 10 years ago • 95 comments

From [email protected] on 2015-01-13T04:28:43Z

Is a feature of multi-editing / multi-selection planned?

Basically the idea is to be able to set multiple cursors to edit at different places of the code at the same time.

Link with the ability to select several occurrence of the same word, it can be used as a very quick "find and replace" for instance.

Here an example: http://blog.jetbrains.com/ruby/2014/03/whats-mining-multiple-cursors-and-selection/

Original issue: http://code.google.com/p/spyderlib/issues/detail?id=2112

spyder-bot avatar Feb 17 '15 22:02 spyder-bot

From ccordoba12 on 2015-01-13T04:31:20Z

Nop, it hasn't been considered so far. It seems cool but I don't know how hard it will be to implement it.

Summary: Add multiline editing to the Editor (was: Feature Request)
Labels: Cat-Editor

spyder-bot avatar Feb 17 '15 22:02 spyder-bot

I think with what Qt offers by default there is no (easy and clean) way to do this, so I would considered a wont fix for this one

goanpeca avatar Apr 12 '15 08:04 goanpeca

Does QtCreator have this functionality? Because if it does, then we should be able to implement it too ;-)

ccordoba12 avatar Apr 12 '15 17:04 ccordoba12

I SOO want to switch to Sypder from sublime text / pycharm but multiple select/editing has become ingrained in my workflow and I find myself unable to remain for long in an editor that can't do this. PLEASE consider this.

xguse avatar Sep 06 '15 17:09 xguse

Ok, we'll explore it for 3.1 :-)

ccordoba12 avatar Sep 06 '15 17:09 ccordoba12

I will look into it for 3.1

goanpeca avatar Sep 06 '15 17:09 goanpeca

Does QtCreator have this functionality? Because if it does, then we should be able to implement it too ;-)

Alt + drag works in qtcreator 3.5.0. Now get to work !

Nodd avatar Sep 07 '15 10:09 Nodd

So, here is a proof of concept :smiley:

It is doable but it is a bit hackish:

  • Basically we keep track of the main and the additional cursors (here entered by Ctrl+MouseClick for convenience)
  • We make the main cursor invisible
  • We set a timer and draw the main cursor (ourselves) plus any other stored additional cursor to ensure proper blinking sync
  • Any keys collected in the keyPressEvent are forwarded to all cursors (if any).

goanpeca avatar Sep 21 '15 04:09 goanpeca

Looks good!

blink1073 avatar Sep 21 '15 12:09 blink1073

Oh dear god thank you. SOO excited for this.

xguse avatar Sep 21 '15 12:09 xguse

That's amazing!! I think this feature is very very very pratical!

Nodragem avatar Sep 22 '15 08:09 Nodragem

Nice ! It looks like the cursors are a bit out of sync at the end, but I'm not 100% sure. Also a nice feature for adding a column of cursors is to use Ctrl+drag. It can be extended to a rectangular selection feature which can be very useful. It exists on geany as a plugin, I don't know if it's present in any other editor.

Nodd avatar Sep 22 '15 09:09 Nodd

@Nodd, yes you are correct, the main cursor is out of sync with the rest, even though I am also manually drawing it.... but it was a 60 minute work.. so don't expect much at this point :-p

goanpeca avatar Sep 22 '15 14:09 goanpeca

Looking forward to this! Also if ctrl-d, ctrl-u workflow could be included! :) (select next occurrence, skip select next)

Twizzledrizzle avatar Dec 13 '15 21:12 Twizzledrizzle

@Twizzledrizzle want to give me a hand?, and also can you explain a bit more on the Ctrl+D, Ctrl+U, is that sublime-like?

goanpeca avatar Dec 13 '15 23:12 goanpeca

Aye, sublime and atom like. I added the documenation below from sublime text. I would very much like to give you a hand, please let me know what I can do.

Multiple Selection with the Keyboard

Adding a Line

To add the line above or below to the selection, use Ctl+Alt+Up and Ctrl+Alt+down (OS X: Ctrl+Shift+Up and Ctrl+Shift+Down).

If you go too far, use Undo Selection (Ctrl+U, or Command+U on OS X) to step backwards.

Splitting the Selection into Lines

Select a block of lines, and then split it into many selections, one per line, using Ctrl+Shift+L, or Command+Shift+L on OS X.

Quick Add Next

To add the next occurrence of the current word to the selection, use Quick Add Next, which is bound to Ctrl+D on Windows and Linux, or Command+D on OS X.

Again, if you go too far, use Undo Selection (Ctrl+U, or Command+U on OS X) to step backwards.

Find All

To add all occurrences of the current word to the selection, use Find All: Alt+F3 on Windows and Linux, or Ctrl+Command+G on OS X.

Single Selection

To go from multiple selections to a single selection, press Escape.

Twizzledrizzle avatar Dec 14 '15 11:12 Twizzledrizzle

This is also one of the primary things keeping me from using spyder as my main IDE. I love spyder for the variable explorer, but without multi cursor support the editing experience is not as fluent as something like sublime. For example, Using Ctrl-D to highlight next occurrence of the highlighted word and editing all selections in one go is a massive time saver

thesimonho avatar Jan 25 '16 15:01 thesimonho

Just a remark, but is Ctrl+D really better than Replace All ? It looks cooler but the functionality looks the same. (Also Ctrl+D is currently set as delete current line).

Nodd avatar Jan 27 '16 09:01 Nodd

Having used both Replace All and multiple cursors, for me multiple cursors is much faster in most cases. And it also opens up possibilities that are not as easy with regex & replace all.

There is a good discussion in a NeoVim issue that I took this screenshot from multicursor

https://github.com/neovim/neovim/issues/211

Twizzledrizzle avatar Feb 15 '16 20:02 Twizzledrizzle

Hi, I was just wondering if the multiple cursor functionality is available in Spyder currently. I really like Spyder and it would be super nice to have this functionality. Thanks!

cocoaaa avatar Apr 24 '16 17:04 cocoaaa

No, it's not available currently. You can see it as an opportunity to become a spyder contributor !

Nodd avatar Apr 24 '16 18:04 Nodd

+1 for multiple cursors!

brooksandrew avatar May 11 '16 19:05 brooksandrew

Hello,

I was wondering, what part of the code would need to be modified?

Because, I wanted to have a look whether I could try to do it (although I am quite a newbie in software programming), but I did not find explanations on the code structure :/ and I found myself a bit lost. Maybe that could help potential coders to explain where and maybe roughly how it could be done.

Thank you!

Nodragem avatar May 29 '16 19:05 Nodragem

@Nodragem thanks for the help. I will ping you back with some details later today or tomorrow.

Cheers :-)

goanpeca avatar May 30 '16 00:05 goanpeca

Bumping this. Would be such a great feature.

akapocsi avatar Jul 28 '16 13:07 akapocsi

I think it would be nice to have this implemented in the same way Kate does it. Just press ctrl+shift+b and you are on column editing mode, press it again and you are back to line editing.

This is really a must have feature for Spyder. I'm actually impressed that Spyder lacks this feature.

arielwrl avatar Sep 23 '16 18:09 arielwrl

We are working on major improvements to the code editor and this would be one of such improvements

goanpeca avatar Sep 23 '16 18:09 goanpeca

Is anyone developing this? I checked up the QtCreator source. In the file "texteditor.cpp", there is a "BlockSelection Mode" implemented for "TextEditorWidgetPrivate". I think it might take some time to find out which parts are relevant to take over and which not, but I think it is doable in principle from Qt based TextEdit widgets. At least we have the basic logic implemented there. However, this is different from the Sublime text version described by @Twizzledrizzle .

vkmaheshbhat avatar Jul 25 '17 11:07 vkmaheshbhat

@rlaverde would you like me to work on this one? I think it is something I could do and that I would like to have in Spyder as well.

jnsebgosselin avatar Jul 27 '17 02:07 jnsebgosselin

@jnsebgosselin yes, go ahead, I'm not currently working on this

rlaverde avatar Jul 27 '17 17:07 rlaverde