Kate – File Type Based Indentation

kate

So after quite a lot of searching and frustration I'm here to ask how to do one of the most basic (or so I thought) things in a modern text editor. I want to set a different indentation for different files types. I almost all the time edit javascript+HTML/XML+python together, and cannot have a fixed 4-spaces or 2-spaces indentation.

I tried setting the indentation mode for different files. However, I cannot find a way to change the number of spaces to indent for each mode. In Settings->Configure Kate->Editing->Indentation, I can set the Default Indentation Mode and select the number of spaces to indent. But there's no way to change the number of spaces to indent for each mode.

Temporary solution:

add,

<!-- kate: indent-width 2; -->

at the beginning of every XML file. Which is quite annoying.


Obviously I want to know if there's a easier way to do it, but if there's no way to do it from the UI, I would love if someone can help me cook up a solution.

I found this bug report (filed 5years ago), where the person mentions something like

The current workaround is to type "kate: indent-mode " into Variables under filetype properties.

I don't know where to find this filetype properties :/ or even if it exists.

Best Answer

Being a Kate developer myself, the answer is indeed as discussed in the comments. Each mode / filetype can be configured individually through document variables in Settings → Configure Kate → Editor Component → Open/Save → Modes & Filetypes. Therein, select your desired filetype, e.g. Scripts/Python. Then select your preferred indentation mode. To set the indent width, you can click on the little tool-button next to the Variables line edit, which will popup a list with all document variables available. Set indent-width to e.g. 4 and close the popup. The Variables line edit then contains the string kate: indent-width 4:, which is exactly the same string that you can also embedd directly into your document, if wanted.

Related Question