Snippets In KDevelop / Kate

Hey all!

Just wanted to give you a little rundown on Snippets in Kate 4.4 (via the snippets_tng plugin) and KDevelop Beta 8 (soon to be released).

Note: The Kate plugin was written by Jowenn and introduced me to all these nice features. For KDevelop I wrote a somewhat simpler yet imo better implementation. We will try to get the best of both worlds into KDE 4.5. Stay tuned!

General Usage & Features

Snippet Management


There’s much to do.

Also, I should probably do a screencast… Not now though ;-)


Want to comment? Send me an email!

Comment by Igor (not verified) (2013-04-05 07:20:00)

Hi Millian,

first, thank you for your work on Kate.

I use the snippets plugin a lot in KDevelop, but only static snippets, i.e. no variables or scripting. I wonder, do you have any documentation available? Specifically I would like to learn about the variables available and how to write scripts. I want to write a snippet for PHPDOC comments creation. It’s easy to just create a snippet with all the comment fields preset, but I would also like the snippet to insert an asterisk character at the beginning of the line each time I press Enter inside a comment. Can this be done with snippet scripting? Is there any documentation? Are you aware of any existing plugins that would do this thing?

Thank you again!


Comment by Geo Lours (not verified) (2012-01-18 12:20:00)


I use the software “kate” and I want to insert html tags in a document. I can’t find tools to do that. For instance, I want to replace the expression this is bold by <strong >this is bold</strong >. Does that exist?

I’ve found the tool “snippets” in the external modules. But I can’t use it. I’ve create a snippet called “strong” with this content:


and this javascript function

    function getSelect(src) 
    return view.selectedText();

But it doesn’t work.

To do that, I’ve had a look in kate’s help file (in particular “scripting API”) and I imitated a snippet which is supplied and which is designed like that:

    The filename of the document is ${fn`getFileName`}

fonction javascript

    function getFileName(src) {
            return document.fileName();

and it works

What did I do wrong? What should I modify ?

Comment by Anonymous (2015-08-03 05:54:00)

I found out after explore this problem that object view don’t work in snippets document works good. The object view works goon in comands and identation scripts. So if you want to manipulate with selected text use scripts not snippets! As to html-tag operations there are a lot of scripts I found in my Kate now. I don’t how this problem occurred that time is actual now. But if it is I may send this scripts to you by email. Leave it if necessary.

Comment by Milian Wolff (2012-01-18 21:20:00)

if I understand you, you want to select something and then trigger a snippet to wrap that in a tag? Yes, that is doable, and much easier than you think. Just create a snippet with the following contents:



Comment by Anonymous (2016-03-18 14:37:00)

This does not work for me (Kate Version 3.11.5 Using KDE Development Platform 4.11.5) %{selection} is always empty

Comment by Anonymous (2016-03-31 13:41:00)

Use ${text} instead of %{selection}. The following works for me in Kate 3.13.3:


Not sure why this isn’t documented anywhere as it’s very useful…

Comment by Anonymous (2016-03-31 14:14:00)

Actually, this doesn’t seem to work anymore either. Would be great to find a solution to this (and also to the bug that prevents shortcuts for snippets from working).

Comment by Geo Lours (not verified) (2012-01-19 16:34:00)

Thanks a lot. It’s OK cheers

Comment by gorn (not verified) (2011-04-23 01:27:00)

Maybe it is a stupid question, but how do I activate snipped from keyboard. I do not like to have to doubleclick the snippet everytime. Ctrl+space is mentioned in the text, but it does nothing.

Comment by Milian Wolff (2012-01-18 21:20:00)

you can also assign shortcuts to single snippets.

Comment by Slava (not verified) (2010-12-14 19:26:00)

I do not agree that ctrl+space is slower then a mouse, just leave namespace empty in repository, and name your snippet properly! then I just type for (fo also works), press ctrl+space, and, voila, required snippets are at the top of the list. The only thing that bothers me (apart from textmate users :)) is the snippet text selection color, for us using dark colorschemes result is hardly usable, shell it somehow respect the parent window palette? The same happens to semantic code highlighting and some other smart stuff, but that is still usable as I can tune the level of highlighting.

Comment by Jacq-ny-mouse (not verified) (2010-09-13 06:50:00)
Hy, Milian, what’s about the weather today am “Unter de Linden” ? (we all are “Berliner’s”)(the wall’s muffins !) So a
nice thing these snippets, thanks a lot for that job. When lonely with MSWindows, in the past, I used a very nice editor
Notetab from Fookes, a masterpiece with a kind of snippets, fabulous ! And I was dispited without it under Linux. Now it’s done, full of thanks, Milian ! (for my own, I edit the files *.xml in /data and the file katesnippets_tngrc) But we miss/lack some things : (have a test on Notetab-trial !)(I speak here about “Code Fragments for Kate” a) rapid change of file on the way (without going through “configuration”) by a litle menu ; b) editing directly, like in “Fragments” (those under katesnippetspluginrc) ; c) pasting xml code with or any between the tags ; (it’s possible with “Fragments”) ; About Textmate & Gedit : a converter-script in Python/Perl/Awk/JS ? (are there copyrights ?) Same remark for the Notetab “Clipbook libraries”… I use Kate daily, it’s my main tool. I use it for writing texts, not code. So my needs are different from other people. I’m now wrinting some snippets of general usage. You and Kate users will benefit later… (I also have written some “Syntax colorations” & “howto’s” to share…) Question-1 : what is the usage/utility of <prefix|postfix|arguments> (I didn’t find !) ? Question-2 : (usefull for making lists of snippets) Who knows a tool making wordcount with the words “outing”, like with the “statistic” of Notetab ( a very usefull little thing ) ? (I still use Notetab, under Wine, only for that job !) Some other suggestions coming soon… That’s all folks… All of You, have nice time and coding. Jacques Bidaux, from the east of France (j’écris souvent en Français, aussi :)).

sorry for this text-lenght, just post your selection ««<

Comment by jaymz (not verified) (2010-07-06 01:02:00)

This plugin has made my day! Thank you all for your hard work. I’m really loving this. I use kate all day at work and all evening at home, its my editor for everything and the last thing I was waiting for was snippets like this.

Comment by craig (not verified) (2010-05-09 23:25:00)

Yes, so happy to see this. Thanks for the hard work.

Comment by kamil (not verified) (2010-03-14 13:21:00)

Thanx for your work. It’s very important. Up to now missing snippets in kate was blocking me to dig Mac with TextMate and switch totally to Linux.

Comment by NoSpox (not verified) (2010-02-04 10:34:00)

would like to see compatibility with TextMate’s snippets, and a configurable trigger (CTRL + Space, Tab, …)

Comment by Milian Wolff (2010-02-04 11:25:00)

Yes that is true - I totally forgot to mention that in the TODO section of the arcticle. I’ll update it accordingly. Thanks for the reminder.

Comment by FiNeX (not verified) (2010-02-04 01:30:00)

Hi! I don’t remember if I’ve talked about snipplets with you in b.k.o. Did you asked to gedit devs if it could be possible to port their snipplets which works very well?

Comment by Milian Wolff (2010-02-04 11:26:00)

See TODO list ;-) I updated it.

Comment by shamaz (not verified) (2010-02-03 19:04:00)

a blog post without screencast is acceptable. but a blog post without screenshot is unacceptable ! ;)

Comment by Milian Wolff (2010-02-03 23:06:00)

well the real magic of the snippets handler cannot be shown with a simple screenshot, a screencast is required!

Comment by Dan Leinir Turthra Jensen (not verified) (2010-02-03 18:35:00)

This stuff is simply amazing! We’re really getting up to spec here :) Snippets is one of the final things that’s made Visual Studio more interesting, and well… now that just begins looking… damn yeah :)

Published on February 03, 2010.