Preview: Multi-Cursor support in the Kate Text Editor

I started to implement multiple cursor and selection support in KDE’s famous text editor kate a while ago, but eventually didn’t quite have the time to finalize it. I am currently at Akademy in Spain, KDE’s annual developer conference, and decided that would be a good time to pick it up again and make it actually work. Here it is in action:

Multiple cursors in kate

What does it do?

It allows you to have an arbitrary amount of cursors and selections in KTextEditor. They all mirror what you do with the primary one — text input, text removal, navigation, text selection, …

Features include:

  • Place any amount of cursors with mouse and keyboard shortcuts.
  • Have any amount of (disconnected, i.e. non-continuous) selections. Each selection has exactly one cursor at either its start or its end, but the selection for a cursor is allowed to be empty. Selections do not need to have the same size.
  • Freeze and unfreeze your secondary cursors, allowing you to move only the primary cursor, or all of them simultaneously.
  • Perform most editing, text selection and text navigation features on all cursors simultaneously.

What is it good for?

You decide.

Multiple selections of different sizes

How do I use it?

Usage is relatively simple; the shortcut for controlling multicursors is currently Ctrl+Meta (Meta is the key with the Windows icon on it). Press Ctrl+Meta and click in your document to place a secondary cursor. Then, just do whatever you would normally do with the keyboard. Press Esc to clear all secondary cursors.

You can place cursors with just the keyboard by pressing Ctrl+Meta+D (“toggle secondary cursor at current position”). Doing that will freeze all secondary cursors, and the keyboard now only moves the primary cursor until you unfreeze them again with Ctrl+Meta+F.

You can also create multiple and additional selections by pressing Ctrl+Meta, and then just using the mouse to select text.

Multiple cursors in a Kate document

What’s the state?

Most things work, there will be some issues I’m not aware of. What is at the moment completely broken is persistent selection, and the block selection mode. Both just do random things. I will need to fix that — or do you want to help? Assistance is very welcome.

If you want to test things, I’m sure you can find issues around static and dynamic word wrap, and folding.

How do I try it?

Check out the “multicursor” branch in the ktexteditor repo and build it, then start kate or any other application using the katepart editor component. Or, get a kate AppImage with multicursor support from here: http://files.svenbrauch.de/kate-linux/multicursor/

Please leave feedback in the comments if you try it out!

Categories: Everything

Tags: , , , ,

23 replies

  1. Awesome, really good work!
    I can’ wait to try it out 🙂

    would it be possible to add multiple cursor from a search:
    – selecting all/next occurrences of the current selection
    – add cursor next to a given pattern

    • Try out the AppImage right now!
      Yes, certainly possible, and among the first things we should do with it once it works — but for now, I really want to have the minimum possible subset of things which works correctly before turning to anything fancy.

  2. This is just perfect. I spend all my day on Kate. Great work! Cannot wait to get it.

  3. You are my new hero ! Really awesome. I’m used to Sublime Text 2 and the only feature I miss from it in Kate is the possibility of multiple cursors. Then I select a text and hit Ctrl + D is selects the next match from my selection so I am able to rename a variable extrem fast for example. When I get you right this sould also be possible then (maybe in the future) ? You did a great job. Thumbs up.

    • The framework I created certainly makes it easy to implement such a feature, yes. Let me know how it works for you if you try it out!

  4. this is so awesome! Multicursor support really enables some incredibly useful workflow.

    thanks for putting such a great feature into the editor we all love 🙂

  5. awesome feature!!

    Happy hacking in Almería!!

  6. Nice feature, and good that the preview is available without having to compile it.

    However, for some reason the appimage needs the complete path of a file if I want to open it by command line. Any quick workaround for this?

    • If you want to use this, you should re-compile anyways, I did lots of fixes and it’s working a lot better now. I should update the AppImage at some point.

      The issue is probably because the AppImage changes its working directory to some temp dir … you can write a shell script wrapper around it which adds the pwd to the path you type, but that should probably be fixed in the AppImage as well …

  7. Hello, this is a great thing for me, thanks for this!

    Would it be possible to use it in kile as well and how would I need to compile it?

    Thanks once more.

    • Yes you can use it in Kile, just clone git://anongit.kde.org:ktexteditor.git and switch to the “multicursor” branch, then install it. Unfortunately, right now you need to recompile Kile as well, because the branch breaks ABI. The easiest way will be to remove your system version of ktexteditor to avoid confusion.

  8. Hi Sven.

    Is it still a planned feature for kate/kdevelop? I really want to see this feature in kdevelop and I’m ready to help tackle remaining issues if it could bring multicursor to my favourite IDE 🙂

    • Hi Guillaume, yes, I would very much like to have this merged at some point; if you want to help with tackling the remaining issues, that would be amazing! You can just check out the “multicursor” branch in the KTextEditor repository and start fixing 🙂

      Maybe I can spend some time on the feature at this year’s Akademy again, but there are lot of things in KDevelop requiring attention as well …

  9. This feature was not merged to mainline Kate, was it?

    • No, it wasn’t. It still exists in a branch and could probably be revived with moderate effort. I have the feeling though that the need for this feature is very loud, but not actually very large, if you know what I mean 😉

      • I know what you mean. Probably because when you are used to this feature you won’t switch to an editor without it anymore 😉
        I’ve been a Geany user for years, some day I’ve tried Sublime Text and this feature got me. Now I cannot find a reasonable free editor with this feature.

  10. Is there any update on this? Could we get this feature in Kate, please?

  11. Hi Sven,

    Awesome work. You’re my hero. I wish I could have read this your post earlier.

    I’ve been looking after some similar efforts to make multi-cursor happen, but alas also without a final resolution in a form of merging it to mainline – https://forum.kde.org/viewtopic.php?t=159930

    What I’ve recently stumbled upon is this one https://kate-editor.org/post/2022/2022-03-10-ktexteditor-multicursor/
    Looks very fresh.
    Is it a continuation of your work or a complete brand new implementation from scratch?

    • Hi Alex, oh, I think the Kate community pretty much completely missed your effort! Sorry for that — most people don’t read the forums that closely, please mention your projects in the mailing list instead.

      The current effort is a fresh start (not by me) and is already in with many great features. Try it out!

Trackbacks

  1. Links 24/7/2017: Linux 4.13 RC2, Mesa 17.2 RC1, Akademy Coverage | Techrights
  2. Multi-Cursor Support in the Kate Text Editor - Amicki's Tech Store
  3. Akademy 2017 in Almería, Spain: Wrap-up – Linux, Games, Programming and some random science stuff

Leave a Reply

Your email address will not be published. Required fields are marked *