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/

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.

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.

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 …

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.

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 …