Writing Scripts for Kate

When I moved from Ubuntu to Kubuntu I attempted to move from gedit to Kate but I struggled to get the snippets that I use constantly thru the day in Kate. Almost all of the tutorials are poorly written.

In gedit (which Im still using years later on Kubuntu) I have tab trigger of q, (QUOTE)$1(/QUOTE) and that is all it is. Same for tab trigger of t, $(1:date +%H%M" "). Has anyone found some decent, clear tutorials for Kate?

There is this Kate Snippets

Yeah… yes there is … and as everyone posts that and it doesnt help… thanks for responding.

Where are you having the problem? In the formatting of creating them or something like getting them to work at all?

While both programs have the term snippets - they do not work the same. In gedit I type capital T and Tab and it inserts the time - which is important in my daily work. In Kate, while the button to the right says you can create an input short cut like capital T + Tab, I do not see how that is actually done as the button itself does nothing and just hitting the required keys also does nothing. So I do not see how to use this code.


I discover snippet with this topic :slight_smile:
It looks powerfull, I need to read documentation!

I created this one just to see

Snippet definition


  1. CTRL<
  2. T + click on Time entry in list
  3. T followed by TAB
  4. T followed by ENTER

@wadesmart is it something like this you’re looking for?


If you want to style the for example, the date a bit more, this is an example of how

A list of the .get***() options can be seen here JavaScript Date Reference

I just need the time formatted to 24hr but as I read this, each time you click T+tab you have to select the function to run it. Is there no faster way to just insert it and go on?

ps: I like the videos. Very much help me to get what you are saying.

Just replace script content for function dt() with

function dt() { return new Date().toTimeString('hh:mm:ss'); }

On my example, I’ve set CTRL< as shortcut to insert date/time directly
So you can affect anything else, like CTRLT if you prefer

You just need to check if this shortcut is not already used by something else…

On my side, as this is the only one snippet for which function name start with T I don’t need to select function: it’s the selected one, then just T followed by TAB is enough to insert current time, without need to do anything else


How did you input your short cut?
When I click on it - it just highlights. There is no selection.


When you have Input... , just press CTRLT or any combination key you want to use as shorctut, then it will be taken in account; once you’ve pressed the shortcut you want to use, wait 1~2seconds and that ok


Ok. I have to run errands but Im going to try that and post when I get back. Thanks Grum999- appreciate it.

Ok, the ctl+T is used for something else so I went with alt+T and it does seem to work


though it would be nice if I didnt have to confirm it once hitting the key combination.

function dt() { return new Date().toTimeString(‘hh:mm’);}
produces: 15:48:27

How can I remove the seconds?

Mmhh yes I misinterpreted Javascript toTimeString method documentation

Formatting date/time in javascript looks like hell :sweat_smile:
You cant try this instead:

function dt() { return new Date().toTimeString().substring(0,5); }

In menu Settings > Configure keyboard shortcuts…
Then type ctrl+t to check which commands are using the shorcut


If I click on alt+T as Im typing it does insert right away.

YES! Your js worked!!!

You can also use scripting to do that. We even have a builtin command to add date to the current position. See The Editor Component Command Line

Hit F7, then type date with the format that you want. Bit cumbersome if you have to type in the format all the time so you can just write your own script with the format you want and invoke that script form the F7 command line.

1 Like

I dont see how that helps at all.

When Im writing documentation I have to two 2 things: Time and Quote. For every single entry I have to put in the time and I have to put in multiple quotes. So, for example, when Im writing I hit t+tab to write the time and then q+tab to insert [QUOTE] $[/QUOTE] and where the $ is, that is my cursor and Im quoting comment.

Not sure what you really need in fact :slight_smile:

But modifying the snippet like this

${dt()} [quote]${view.selectedText()}${cursor}[/quote]

Allows you with only one shortcut action to add time and reformat selected text in quote


I dont see how that helps at all.

It helps because you can then assign shortcuts to scripts and invoke those shortcuts directly instead of

  • typing t
  • waiting for dialog and then pressing tab on the first entry.

This works, but is not a good workflow and might break if there are more completion entries due to whatever reason.