Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multiline editing to the Editor #2112

Open
spyder-bot opened this issue Feb 17, 2015 · 102 comments · May be fixed by #4987 or #22996
Open

Add multiline editing to the Editor #2112

spyder-bot opened this issue Feb 17, 2015 · 102 comments · May be fixed by #4987 or #22996

Comments

@spyder-bot
Copy link
Collaborator

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
Copy link
Collaborator Author

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

@goanpeca
Copy link
Member

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

@ccordoba12
Copy link
Member

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

@xguse
Copy link

xguse commented Sep 6, 2015

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.

@ccordoba12 ccordoba12 added this to the v3.1 milestone Sep 6, 2015
@ccordoba12
Copy link
Member

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

@goanpeca
Copy link
Member

goanpeca commented Sep 6, 2015

I will look into it for 3.1

@goanpeca goanpeca self-assigned this Sep 6, 2015
@Nodd
Copy link
Contributor

Nodd commented Sep 7, 2015

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 !

@goanpeca
Copy link
Member

So, here is a proof of concept 😃

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).

@blink1073
Copy link
Contributor

Looks good!

@xguse
Copy link

xguse commented Sep 21, 2015

Oh dear god thank you. SOO excited for this.

@Nodragem
Copy link

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

@Nodd
Copy link
Contributor

Nodd commented Sep 22, 2015

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.

@goanpeca
Copy link
Member

@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

@Twizzledrizzle
Copy link

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

@goanpeca
Copy link
Member

@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?

@Twizzledrizzle
Copy link

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.

@sho-87
Copy link

sho-87 commented Jan 25, 2016

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

@Nodd
Copy link
Contributor

Nodd commented Jan 27, 2016

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).

@Twizzledrizzle
Copy link

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

neovim/neovim#211

@cocoaaa
Copy link

cocoaaa commented Apr 24, 2016

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!

@Nodd
Copy link
Contributor

Nodd commented Apr 24, 2016

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

@brupelo
Copy link

brupelo commented Apr 13, 2021

I'm not involved in this project but from what I've seen I think is pretty amazing.

One thing I'm really interested in is how this feature is evolving over time, why? Because you won't see many qt/pyqt projects out there having proper multiline edit. When I say "proper" I really mean it... for instance, Scintilla/QScintilla... when you delete/cut blocks of text the multiselections these will be lost in the ether. But if do the same on editors such as vscode/atom/sublime... the multiple selections will be preserved properly when undoing/redoing and that's really unvaluable. But I guess achieving that level of quality is difficult to reach though.

With that said, this PR is pretty amazing https://github.com/spyder-ide/spyder/pull/4987/files !

@hyamanieu
Copy link

I can also say I tried to switch to VS Code or Jupyter Lab (which both have this function), but Spyder feels like home when it gets down to software developing.
I was thinking GitHub sponsoring could be linked with issues, so that we vote with money, because I'm willing to give money to have this function implemented. I know Spyder uses opencollective rather than github sponsors.

@cliffckerr
Copy link

cliffckerr commented Apr 13, 2021

@hyamanieu I think think it's a balance between providing useful information on which features are highest priority from the community perspective, vs. letting the Spyder developers prioritize features in a way that makes the most sense for them and for the project. But I encourage you to donate anyway, since more resources could help accelerate all timelines :) (Disclosure: I've donated.) https://opencollective.com/spyder

@hyamanieu
Copy link

I did that and I encourage others to do it as well.
But we're digressing.

@Firestar-Reimu
Copy link

This has been asked many times in the past and we'll try to implement in Spyder 6, to be released next year.

Do you have any idea about using Ctrl or Alt for multi cursor, or we should give a choice?

@ccordoba12
Copy link
Member

@1900011604, I don't understand what you mean.

@Firestar-Reimu
Copy link

Firestar-Reimu commented Sep 22, 2021

@1900011604, I don't understand what you mean.

I mean choice like this: https://code.visualstudio.com/docs/editor/codebasics#_multicursor-modifier

@sergiokapone
Copy link

Has Spyder 5.1.5 a multi cursor support now?

@Firestar-Reimu
Copy link

Firestar-Reimu commented Dec 13, 2021

Has Spyder 5.1.5 a multi cursor support now?

Sorry, no

@sanjiv856
Copy link

Is multi cursor support available in Spyder version 5.2.2?

@FreyGeospatial
Copy link

Just adding here, that I along with everyone else think that it would be great to have multi-cursor support! CTRL-ALT would be a great key combination, like in RStudio.

@NicholasJudge
Copy link

I was quite excited to get going w/ Spyder, but I see there still is no simple hotkey for multiline editing? that seems like too basic functionality to not be included, though. Am I missing something?

@Firestar-Reimu
Copy link

Firestar-Reimu commented Oct 30, 2022

Same here on Spyder 5.3.2 installed via https://archlinux.org/packages/community/any/spyder/

@ccordoba12
Copy link
Member

@NicholasJudge and @Firestar-Reimu, sorry but this is hard to implement and it won't come soon (at least one year because we're quite busy with other things).

@OverLordGoldDragon
Copy link
Contributor

Just noting that, in another editor, multi-line editing is somewhat slower than in Notepad++, and that bothers me enough to just not use it there and instead paste into N++.

With AutoHotKey, I press Ctrl + 3 to open N++ when needed - paste there, edit there, then paste back into Spyder. Personally I'm fully content with this workaround. For reference, here's the script to accomplish that (can use any other hotkey combo) - see full script at bottom:

^3::
Run "C:\Program Files\Notepad++\notepad++.exe"
return

Pressing Ctrl + 3 when N++ is already open will bring up the N++ window if it's minimized, so it's very quick.

(So if it's so hard to do in Spyder, maybe it won't be as good as in N++, and users who are expecting it may not like it as much, and are better off accustoming with alternatives.)

full script
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#InstallKeybdHook

^3::
Run "C:\Program Files\Notepad++\notepad++.exe"
return

@yashpundir
Copy link

Hi, just wanted to get an update on the multiline select feature. Do the devs have this feature on their priority list now?
Spyder is amazing though ❤️ Thanks
Regards

@ccordoba12
Copy link
Member

Hey @yashpundir, thanks for your kind words. Unfortunately, we haven't had time to work on this because it's very tricky and we've been busy with other things, sorry.

@Firestar-Reimu
Copy link

It seems that 6.0.0 still do not have this feature, if it has, how to toggle it?

@ccordoba12
Copy link
Member

Sorry, this is not available yet. We'll try to implement it for 6.2 (most work for 6.1 is already planned).

@athompson673
Copy link
Contributor

Are there any big changes planned for the editor in 6.1 that would make working on this right now fruitless? I'd really like this feature, and I was considering taking a crack at trying to port #4987 up to modern spyder.

@GitHunter0

This comment was marked as off-topic.

@athompson673
Copy link
Contributor

athompson673 commented Nov 4, 2024

I've got the beginnings of an implementation going at https://github.com/athompson673/spyder. I'd love any comments if anyone wants to give it a try...

Add cursors with Ctrl-Alt click.

Lots of shortcuts are still untouched, but basic stuff works. Edit history and cursor position history are pretty broken.

The original implementation example of using an editor extension could partially work, but there's a lot of things in the main editor which would still need modifying to allow extensions to override. Particularly lots of shortcuts are implemented by directly manipulating the primary cursor. If these were to be modified to signal extensions, much of the code would need be simply copied to the extension and re-written anyway. Given all this I'm just implementing directly in the CodeEditor class. I recognize this is taking an already enormous class and making it bigger, so if anyone has better ideas on the layout, feel free to suggest alternatives.

Plans:
I'd like to eventually make sure all shortcuts work or are disabled with multi-cursor (depending on if they make sense in context). Edit history needs to work as expected (even naive implementation; just not broken). Cursor position history needs to work. I would want to see copy and paste go from single cursor to multi-cursor (if copied text has same number of lines as cursors, paste 1 line per cursor). Mouse interactions are currently hard-coded, and it might be nice to make them configurable (currently: ctrl click for goto definition, alt click for jump within document, ctrl-alt click for adding cursors). I'd like to add click and drag for column cursor, as well as place cursor at next occurrence shortcut for creating new cursors.

@ccordoba12 fyi

Media1.mp4

@athompson673 athompson673 linked a pull request Nov 16, 2024 that will close this issue
50 tasks
@ccordoba12
Copy link
Member

ccordoba12 commented Nov 21, 2024

Thanks a lot for working on this @athompson673! It looks awesome so far!!

@cliffckerr
Copy link

This is so exciting! Agree it's looking great so far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment