KatePart Modelines

Kate Part’s modelines - also called Kate document variables - are Kate Part’s implementation of document variables, similar to Emacs and vim modelines.

Document variables can be used to set Kate settings local to a file. This is for example for using another Writing Indenters than the one defined in the GUI settings. - Or assume you work on two projects, the first indents with spaces and the second with tabs, then you can simply add a modeline that contains the specific document variables that set the specific indentation properties.

The following contents is mainly from the Kate Handbook.

Modeline Format

A modeline in the Kate Part has the following format:

kate: VARIABLENAME VALUE; [ VARIABLENAME VALUE; ... ]

The lines can be in a comment, in C++ for example in /*...*/ sections. Multiple modelines are supported, i.e. modelines can be split over several lines for better visibility. Variable names are single words (no whitespace), and anything up to the next semicolon is the value. The trailing semicolon (;) is required.

Here is an example of how a modeline could look like, forcing indentation settings for a C++, Java or JavaScript file:

// kate: space-indent on; indent-width 4; mixedindent off; indent-mode cstyle;

NOTE: Only the first and last 10 lines in a file are searched for modelines.

There are variables to support almost all options in Kate Part, and additionally plugins can use variables, in which case it should be documented in the plugin’s documentation.

How Kate Part uses Variables

When reading settings, Kate Part looks in the following places in the order

  1. the global configuration, i.e. settings made in the user interface
  2. the Filetypes configuration
  3. the The File ./.kateconfig file
  4. the modelines in the document itself

This means Kate Part’s modelines have actually the highest precedence. Whenever a document is saved, the document variables are reread, and will overwrite changes made using menu items or the Command Line. Any variable not listed below is stored in the document and can be queried by other objects such as plugins, which can use them for their own purpose. For example the Variable based Indenter uses document variables for its configuration.

Available Modelines

The variables listed here documents Kate version 2.4. More variables may be added in the future. There are defied 3 types of values for variables, with the following valid expressions:

  • BOOL - on|off|true|false|1|0
  • INTEGER - any integer number
  • STRING - anything else

Available modelines are, in detail:

  • auto-brackets [BOOL]
    Set auto insertion of brackets on or off.
  • auto-center-lines [INT]
    Set the number of autocenter lines.
  • auto-insert-doxygen [BOOL]
    Turn insertion of the leading asterisk in doxygen comments on or off. This has no effect unless you use the cstyle auto-indenter.
  • background-color [STRING]
    Sets the document background color. The value must be something that can be evaluated to a valid color, for example #ff0000.
  • backspace-indents [BOOL]
    Turn backspace indenting on or off.
  • block-selection [BOOL]
    Turn block selection on or off.
  • bracket-highlight-color [STRING]
    Sets the color for the bracket highlight. The value must be something that can be evaluated to a valid color, for example #ff0000.
  • current-line-color [STRING]
    Sets the color for the current line. The value must be something that can be evaluated to a valid color, for example #ff0000.
  • dynamic-word-wrap [BOOL]
    Turns dynamic word wrap on or off.
  • eol | end-of-line [STRING]
    Sets the end of line mode. Valid settings are unix, mac and dos
  • encoding [STRING]
    Sets the document encoding. The value must be a valid encoding name, like utf-8.
  • font-size [INT]
    Sets the point size of the document font.
  • font [STRING]
    Sets the font of the document. The value should be a valid font name, for example courier.
  • folding-markers [BOOL]
    Set the display of folding markers on or off.
  • hl | syntax [STRING]
    Set the syntax highlighting. Valid strings are all the names you can find in the menus. For instance, for C++ you write C++.
  • icon-bar-color [STRING]
    Sets the icon bar color. The value must be something that can be evaluated to a valid color, for example #ff0000.
  • icon-border [BOOL]
    Set the display of the icon border on or off.
  • indent-mode [STRING]
    Set the auto-indentation mode. The options none, normal, cstyle, csands, python, xml are recognized. See the section Using Automatic Indenting for details.
  • indent-width [INT]
    Sets the indentation width.
  • keep-extra-spaces [BOOL]
    Set wheather to keep extra spaces when calculating indentation width.
  • keep-indent-profile [BOOL]
    If enabled, prevents unindenting a block if at least one line has no indentation.
  • line-numbers [BOOL]
    Set the display of line numbers on or off.
  • mixed-indent [BOOL]
    Set mixed indentation ala Emacs on or off.
    DEPRECATED for Kate 3.0 From version 3.0 this variable is ignored, set replace-tabs on; instead for that version.
  • overwrite-mode [BOOL]
    Set overwrite mode on or off.
  • persistent-selection [BOOL]
    Set persistent selection on or off.
  • remove-trailing-space [BOOL]
    Set dynamic end of line cleanup on or off.
  • replace-tabs-save [BOOL]
    Set tab->space conversion on save on or off.
  • replace-tabs [BOOL]
    Set dynamic tab->space conversion on or off.
  • replace-trailing-space-save [BOOL]
    Set end of line cleanup on save on or off.
  • scheme [STRING]
    Set the color scheme. The string must be the name of a color scheme that exists in your configuration to have any effect.
  • selection-color [STRING]
    Set the selection color. The value must be something that can be evaluated to a valid color, for example #ff0000.
  • show-tabs [BOOL]
    Set the visual TAB character on or off.
  • smart-home [BOOL]
    Set smart home navigation on or off.
  • space-indent [BOOL]
    Set indentation with spaces on or off.
    DEPRECATED for Kate 3.0 — From Kate 3.0 mixed-indent is the default behavior, set replace-tabs on; to achieve space-only indentation.
  • tab-indents [BOOL]
    Set the TAB key indentation on or off.
  • tab-width [INT]
    Set the tab display width.
  • undo-steps [INT]
    Set the number of undo steps to remember.
  • word-wrap-column [INT]
    Set the hard word wrap width.
  • word-wrap-marker-color [STRING]
    Set the work wrap marker color. The value must be something that can be evaluated to a valid color, for example #ff0000.
  • word-wrap [BOOL]
    Set hard word wrapping on or off.
  • wrap-cursor [BOOL]
    Set cursor wrapping on or off.

Comments

auto indentation like in vim or Emacs

I wonder if the Kate editor can be configured (and how …) to indent a line properly when the tab key is pressed. If you’ve used vim or emacs for coding, you know what I’m talking about. If not, it’s kind of hard to describe. Basically what happens is the indentation is determined by the syntax and sets to what the syntax dictates when you hit tab.

when you press the tab key while the cursor is on the lines of

                    if (a == b)  
       call_function();

will change the code to

if (a == b) call_function();

I hated it when I first tried to use it. Now I feel lost without it.

information up to date

Hello,

is this document here still up to date?

And second question: It would be nice have a kate document variable for the line number. So an application using katepart can store the line number inside the document and jump to that line once the document is opened again.

What do you think?

Bye, Thomas (kile dev team)

Kate and Temp space

Opening large files with Kate can slow down the system. How can you control the amount of Temp space that Kate uses?

Some changes for KDE 4/Kate 3.0

I have made the following changes recently, that apply only to Kate of KDE 4:

  • mixed-indent is no longer available. This kind of indentation is the only behavior.

  • The value of space-indent has the same meaning as replace-tabs, but if both are set, the latter has precedence.

Hannes

Noted in the article content

I added information in the article that those variable are deprecated for Kate 3.0. I believe we should do so, to keep this documentation fully up to date.

Post new comment

  • You can use Markdown syntax to format and style the text.
  • You may link to images on this site using a special syntax
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.