Kakoune: filetype based on filename

=> Comment on Mastodon

Introduction

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

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.

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
}

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
}
Proxy Information
Original URL
gemini://perso.pw/blog//articles/kakoune-filetypes.gmi
Status Code
Success (20)
Meta
text/gemini
Capsule Response Time
133.721948 milliseconds
Gemini-to-HTML Time
0.446602 milliseconds

This content has been proxied by September (3851b).