About me: My name is Solène Rapenne, pronouns she/her. I like learning and sharing knowledge. Hobbies: '(BSD OpenBSD Qubes OS Lisp cmdline gaming security QubesOS internet-stuff). I love percent and lambda characters. Qubes OS core team member, former OpenBSD developer solene@. No AI is involved in this blog.

Contact me: solene at dataswamp dot org or @solene@bsd.network (mastodon).

I'm a freelance OpenBSD, FreeBSD, Linux and Qubes OS consultant, this includes DevOps, DevSecOps, technical writing or documentation work. If you enjoy this blog, you can sponsor my open source work financially so I can write this blog and contribute to Free Software as my daily job.

Kakoune: filetype based on filename

Written by Solène, on 30 May 2021.
Tags: #kakoune #editor

Comments on Fediverse/Mastodon

1. Introduction §

I will explain how to configure Kakoune to automatically use a filetype (for completion/highlighting..) depending on the filename or its extension.

2. Setup §

The file we want to change is ~/.config/kak/kakrc , in case of issue you can use ":buffer *debug*" in kakoune to display the debug output.

2.1. Filetype based on the filename §

I had a case in which the file doesn't have any extension. This snippet will assign the filetype Perl to files named Rexfile.

hook global BufCreate (.*/)?Rexfile %{
	set buffer filetype perl
}

2.2. Filetype based on the extension §

While this is pretty similar to the previous example, we will only match any file ending by ".gmi" to assign it a type markdown (I know it's not but the syntax is quite similar).

hook global BufCreate .*\.gmi %{
	set buffer filetype markdown
}