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: , , , ,

10 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!!

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 *