Kate allows you to specify local document variables by setting the corresponding modelines. The hidden file .kateconfig provides exactly the same functionality, but for all files in the directory.
Enable the Feature
To use a .kateconfig file you first have to enable the feature by invoking Settings > Configure Kate. In the config page Open/Save you can find the option Search depth for config file, which defaults to Do not use a config file. Change the value to an appropriate number,
- __ means look in the current folder
- 1 means look in the current folder, and if there is no .kateconfig file, look in the parent folder
In short – Kate will search the number of given folder levels upwards for a .kateconfig file and load the settings from it.
Fill the .kateconfig File
The .kateconfig file simply contains modelines.
The following example will cause all documents to indent with 4 spaces with a tab width of 4. Tabs will be replaced during editing text and the end-of-line symbol is a linefeed (\n).
kate: space-indent on; tab-width 4; indent-width 4; replace-tabs on; eol unix;
Extended Options in KDE 3.5.x, KDE 4 and Kate 5
Kate in KDE 4 as well as later versions of Kate always search for a .kateconfig file for local files (not remote files). In addition, it is now possible to set options based on wildcards (file extensions) as follows:
kate: tab-width 4; indent-width 4; replace-tabs on; kate-wildcard(*.xml): indent-width 2; kate-wildcard(Makefile): replace-tabs off;
In this example, all files use a tab-width of 4 spaces, an indent-width of 4 spaces, and tabs are replaced expanded to spaces. However, for all *.xml files, the indent width is set to 2 spaces. And Makefiles use tabs, i.e. tabs are not replaced with spaces. Wildcards are semicolon separated, i.e. you can also specify multiple file extensions as follows:
kate-wildcard(*.json;*.xml): indent-width 2;
Further, you can also use the mimetype to match certain files, e.g. to indent all C++ source files with 4 spaces, you can write :
kate-mimetype(text/x-c++src): indent-width 4;
Note: Next to the support in .kateconfig files, wildcard and mimetype dependent document variables are also supported in the files itself as comments.