Kate polishing

Phew, I just finished some last-minute backports to the KDE 4.3.5 branch. Lets hope the bug fixes I and pletourn did are as good as they look. Expect a much more stable Kate for 4.3.5 & 4.4! We managed to fix two bugs which are potentially the cause for dozens of bug reports, all seemingly random. Lets see whether our fixes hold up to our hopes!

Other than that: You should look forward to Kate scripting (with JavaScript) in 4.4. It’s dead simple but actually useful. In the utils.js file we ship with Kate there are now the following tools (all operate on the selection or - if none exists - on the whole document):

Do you have more ideas for such simple helper functions?


Want to comment? Send me an email!

Comment by Anonymous (not verified) (2010-05-19 17:52:00)

Joining lines can simply be done by [ctrl]+[j]. Works with or w/o selection, for just the current line in the latter case. (Using Kate 2.5.10 @ KDE 3.5.10)

just my 2¢

Comment by Anonymous (not verified) (2010-01-21 17:48:00)

Two functions I use all the time are “join lines” and “strip blank lines”. Today I do those with external perl scripts called from the “Filter Text” function. They might be useful as helper functions though. Here are the perl scripts (for reference):

Join Lines:

    $s .= $_ while (<>);
    $s =~ s/\n//g;
    print $s;

Strip Blank Lines:

    $s .= $_ while (<>);
    $s =~ s/\n+/\n/g;
    print $s;
Comment by Milian Wolff (2010-01-21 19:19:00)

both added now :)

Comment by sebas (not verified) (2010-01-21 12:02:00)


Right now, getting wordcount in kate seems like black magic (I have tried, but not succeeded). It would be cool if such a function would be easily available, so I don’t have to go to the console and use ‘wc’ just to know how many words I’m allowed to / have to write still.

Comment by Milian Wolff (2010-01-21 19:41:00)

see also:

I think I had a nice idea on how to implement that, stay tuned for 4.5 ;-)

Comment by dereine (not verified) (2010-01-21 10:33:00)

Could you link to a page or sth. where there is a description how to use custom user scripts? I cannot find something.

Comment by Milian Wolff (2010-01-21 14:47:00)

Try that for now:

Comment by niko (not verified) (2010-01-21 08:20:00)

Is it possible to assign shortcuts to such commands? Or add them to the toolbar? And does it work in KDevelop?

Comment by Milian Wolff (2010-01-21 14:46:00)

Assigning shortcuts is on the TODO and will hopefully be there for KDE 4.5. And yes, all this is implemented in Katepart, hence works wherever it is used (KDevelop, Quanta, Kile, …).

Comment by Anonymous (not verified) (2010-01-21 02:46:00)

Hi :-)

Could a “duplicate line” feature be implemented with javascript ? I really miss it in Kate. You said “all operate on the selection or - if none exists - on the whole document”, but there could be a lot of useful scripts (like duplicating a line) that need to work on the whole current line. Do you think something can be done for that ?

and thanks to the Kate team !

Comment by King_DuckZ (not verified) (2011-06-21 17:44:00)

I tried to add the duplicate line script me too but it doesn’t seem to work. At least, I don’t find it anywhere in kate. I saved it to /home/michele/.kde4/share/apps/katepart/script/duplicate_line.js and it looks like so:

    /* kate-script
     * author: King_DuckZ <>
     * license: BSD
     * revision: 1
     * kate-version: 3.4
     * type: commands
     * functions: duplicate_line
    function duplicate_line() {
        var cursor = view.cursorPosition();
        var line = document.line(cursor.line());
        document.insertLine(cursor.line(), line);

How can I bind that action to ctrl+D?

Comment by Milian Wolff (2011-06-23 12:07:00)

You need to implement the action(cmd) function in your script and return an object with the text, icon, category, interactive and shortcut properties set. See also utils.js that comes with that functionality. Also note that my version (i.e. the one from current git) comes with duplicateLinesDown and duplicateLinesUp scripts - maybe you don’t need to do anything custom anymore?

Comment by King_DuckZ (not verified) (2011-06-21 19:25:00)

Sorry for the bad formatting, I don’t know how to get the tags working. It was just the same function you guys posted here plus the commented header as found in kate’s manual.

Comment by Milian Wolff (2010-01-21 04:07:00)

Yes, something like that would be very easy:

    function copy_line() {
      var cursor = view.cursorPosition();
      var line = document.line(cursor.line());
      document.insertLine(cursor.line(), line);

That should be it ;-) Didn’t test it, but maybe I’ll add such kind of commands to utils.js. What else, other than “duplicate line” would you need?

Comment by Mike Smullin (not verified) (2010-04-16 06:30:00)

above code didn’t work for me, but this did:

    function duplicate_line()
      each(function(lines) {
        for (line in lines) {
        return lines;

In order for the function to register, looks like you have to insert the name of the function into the comma-separated list in the docblock at the top of the file, as well.

now how to execute commands using hotkeys? (e.g. mapping keys to commands) I’m using Kate version 3.4.2 on KDE 4.4.2.

Comment by Anonymous (not verified) (2010-01-21 10:52:00)

Thank you :) i don’t see something else right now but this looks very useful !

Published on January 21, 2010.