Skip to content

New commands for selecting text

Hello all,

This merge request introduces two new commands: fsel and bsel (for "forward select" and "backward select", I modeled modeled after the existing ltrim and rtrim commands, and shortened "select" to "sel" for efficiency purpose).

By default these commands select text from the current cursor position to the end of the line (for fsel) or the beginning of the line (for bsel).

However, where they're really useful is that they take an argument and will select forward/backward to that argument. This, in combination with the new Keyboard Macros Plugin that I'm proposing for Kate allows for a lot of repetitive but very specific tasks to be automated.

For example, let's say I have this HTML code:

<li><span class="foo">the first element</span></li>
<li><span class="foo bar">a second element</span></li>
<li><span class="foo baz">and why not a third element</span></li>
<li><span class="foo quux">you'll take the fourth one too</span></li>

and I want to transform it to this one:

<li class="foo">
  the first element
</li>
<li class="foo bar">
  a second element
</li>
<li class="foo baz">
  and why not a third element
</li>
<li class="foo quux">
  you'll take the fourth one too
</li>

I can just start recording a macro, do the first transformation using only the keyboard thank to fsel and bsel (e.g., to select the CSS class names I can select from the first " found using search to the next " using fsel because I cannot know in advance the number of class or the length of this HTML attribute value), and then stop recording the macro and just use it to make the transformation instantaneous for the subsequent lines.

Here is a video of me doing it on my instance of Kate (which has my Keyboard Macros Plugin and which uses a version of KTextEditor that has my fsel and bsel commands). I was very slow because I didn't want to mess up while recording, but still messed up as you can see but the macro recorded the mess up and its fix so its all good in the end ^^).

(Sorry about Screenkey using the french names.)

https://www.youtube.com/watch?v=BeZlgE_IXuo

PS: as is, this should probably be merged after my other command proposal (align, see !391 (merged)), if it isn't it's not a problem, I'll just need to add my name and email at the top of the file in this branch, since it seems to be how it is done in the utils.js file.

Merge request reports