KDE Advanced Text Editor - Kate
Kate is my default text editor in Linux and Windows. I use it for everything, from a copy/paste buffer to program microcontrollers. In my opinion, it is one of those high-quality free software which can compete head-to-head with commercial software and win over a good number of them. Kate is great, but I find it difficult to find good user-oriented documentation. The official handbook covers a long list of features, but it is quite succinct and technical.
Here, I highlight the features I find more useful from Kate, showing how to enable and use them.
Snippets
I learned about the Snippets plugin when I wanted to make templates of markdown files in Kate. Well, as of today, there are no templates in Kate. But Kate offers something better for my case, Snippets, which are pieces of text you can insert in the document. The Snippets are shown in a list with a distinct name, and when you click over one, the predefined text appears in the document. But, the Snippets can also contain JavaScript functions, therefore the text can be generated dynamically.
Activate Snippets
Snippets is a plugin which should be activated in Settings > Configure Kate … > Plugins > Snippets Tool View. Then, a side panel will appear.
Add Snippets repositories
A collection of Snippets is stored in a Repository. A right-click on the area of the Snippets panel will let you choose between downloading repositories or creating a local one. Your local repositories are saved as xml files in the folder ~/.local/share/ktexteditor_snippets/data/.
Create a repository and add one Snippet
For example, let’s create a repository to store frequent text I use when writing a post for the Jekyll static website generator (this blog). Jekyll uses a slightly modified markdown called Kramdown. Then, the repository will be called Kramdown. The first Snippet will be the header of a markdown file which looks something like this:
---
layout: post
title: ""
author: Fpm.-
date: 2024-11-26 22:47:11
categories:
tags:
published: false
---
I will name the Snippet frontmatter.
To create the Snippet, right-click over the repository name, then Add Snippet. A window will open. Then, the Snippet’s name should be written in the text field on top (frontmatter, in this case). Below the text field, there are two tabs: Snippets and Scripts. In the Snippets tab, you write the text in the same format it should appear in the document’s text. In the scripts tab, it is possible to write a function that returns a string to add to the Snippet’s text. For example, the field date in the header can be filled automatically by a function that gets the current date and writes it in the correct format. The function is called today:
function today() {
now = new Date();
let a = now.getFullYear() + "-" + String(now.getMonth()).padStart(2,'0') + "-" + String(now.getDate()).padStart(2,'0');
let b = now.toTimeString();
return a + " " + b;
}
In the Snippets tab, the function is called like this: ${today()}. So, the Snippet front matter looks like this:
---
layout: post
title: ""
author: Fpm.-
date: ${today()}
categories:
tags:
published: false
---
Using the Snippets
As I mentioned before, clicking over the name of a Snippet in the list will insert the text. Also, if you write the name of a repository, a list with the Snippets from that repository will appear in the auto-completion combo box, from it, you can call the one you want.
Documentation
I have described one case of use only, but the plugin offers more features. The detailed documentation is published in the Kate handbook, section Kate Snippets.
Enjoy Reading This Article?
Here are some more articles you might like to read next: