BlogSnippets In KDevelop / Kate Syndicate content

Wed, 02/03/2010 - 17:59

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
  • create a snippet repository (or download via GHNS [see below])
  • create snippets in that repository
  • insert snippets via the snippets view (i.e. double click), or (imo better/faster) insert them via code-completion (remember: CTRL + Space requests code completion at the current cursor position!).
  • snippet gets inserted (properly indented) and potential placeholders/variables get expanded. A variable is something like %{date} or ${email}. Also take a look at the API documentation.
  • variables that get inserted via “${…}” will be “selectable”, meaning you can jump from one var to the other by hitting TAB / Shift TAB
  • the %{...} vars will only get expanded and inserted, without getting selectable.
  • multiple occurrences of the same variable will be updated once one of them gets edited, something that is called “mirroring” in other editors.
  • once one edits ESC the cursor is placed at the end of the snippet or to the first occurrence of ${cursor} or %{cursor} and the user types something, the snippet-handler quits and you are left with your normal editor until you insert the next snippet
  • nested snippets (i.e. insert snippet than insert another one) should “just work”.
Snippet Management
  • group snippets by file type, i.e. PHP snippets will only be offered during code completion when one edits a PHP file.
    Note: In KDevelop and KDE 4.4 nested documents are supported, e.g. create a CSS snippet and it will be shown inside the CSS parts of a HTML document or similar. This uses my HighlightInterface I wrote for KDE 4.4. I still have to rewrite some parts of the snippets_tng plugin for Kate so that it works there as well
  • group snippets in repositories, set an Author and a License of your choice
  • publish snippet repositories via GHNS: In Kate you can already download snippets from GHNS but we sadly don’t have any repos up on opendesktop… I’ll have to add some prior to KDE 4.4. Also we didn’t have enough time to implement uploading of Repos from inside Kate in time for KDE 4.4. So stay tuned for KDE 4.5. KDevelop currently has no support for GHNS, but I plan to fix this tomorrow or the next days - together with uploading from inside KDevelop, i.e. all the nice features of GHNS v3.
  • in KDevelop (and someday in Kate as well) you can simply select a part of your currently opened document and select the “create snippet from selection” in the ContextMenu - easy & fast!

There’s much to do.

  • Highest priority right now for me is to get GHNS with all bells and whistles supported for KDevelop.
  • Then I’ll merge and integrate the Kate & KDevelop plugins as much as possible, so we have a reduce code base.
  • Also important is to make all shortcuts configurable
  • Another thing is: How could we improve interoperability even between e.g. editors like TextMate or Gedit? Both have snippets features and their bundles are available in the net. If we can support those we’d save us a lot of work

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


Hi Millian, first, thank you Fri, 04/05/2013 - 07:20 — Igor (not verified)

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!


Hello, I use the software Wed, 01/18/2012 - 12:20 — Geo Lours (not verified)


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:

  1. <strong>${fn`getSelect`}</strong>

and this javascript function

  1. function getSelect(src)
  2. {
  3. return view.selectedText();
  4. }

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:

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

fonction javascript

  1. function getFileName(src) {
  2. return document.fileName();
  3. }

and it works

What did I do wrong? What should I modify ?

I found out after explore Mon, 08/03/2015 - 05:54 — Anonymous

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.

if I understand you, you want Wed, 01/18/2012 - 21:20 — Milian Wolff

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:



This does not work for me Fri, 03/18/2016 - 14:37 — Anonymous

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

Use ${text} instead of Thu, 03/31/2016 - 13:41 — Anonymous

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

  1. <strong>${text}</strong>

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

Actually, this doesn’t seem Thu, 03/31/2016 - 14:14 — Anonymous

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).

Thanks a lot. It’s OK cheers Thu, 01/19/2012 - 16:34 — Geo Lours (not verified)

Thanks a lot. It’s OK cheers

Maybe it is a stupid Sat, 04/23/2011 - 01:27 — gorn (not verified)

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.

you can also assign shortcuts Wed, 01/18/2012 - 21:20 — Milian Wolff

you can also assign shortcuts to single snippets.

I do not agree that Tue, 12/14/2010 - 19:26 — Slava (not verified)

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.

Hy, Milian, what’s about the Mon, 09/13/2010 - 06:50 — Jacq-ny-mouse (not verified)

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 <item> or any <xxx> between the <fillin> 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 <<<<<

This plugin has made my day! Tue, 07/06/2010 - 01:02 — jaymz (not verified)

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.

Yes, so happy to see this. Sun, 05/09/2010 - 23:25 — craig (not verified)

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

Thanx for your work. It’s Sun, 03/14/2010 - 13:21 — kamil (not verified)

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.

would like to see Thu, 02/04/2010 - 10:34 — NoSpox (not verified)

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

Yes that is true - I totally Thu, 02/04/2010 - 11:25 — Milian Wolff

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.

Hi! I don’t remember if I’ve Thu, 02/04/2010 - 01:30 — FiNeX (not verified)

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?

See TODO list ;-) I updated Thu, 02/04/2010 - 11:26 — Milian Wolff

See TODO list ;-) I updated it.

a blog post without Wed, 02/03/2010 - 19:04 — shamaz (not verified)

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

well the real magic of the Wed, 02/03/2010 - 23:06 — Milian Wolff

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

This stuff is simply amazing! Wed, 02/03/2010 - 18:35 — Dan Leinir Turthra Jensen (not verified)

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 :)

Post new comment

  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <pre>.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options