modelines.md

 1# Modelines
 2
 3Modelines are special comments at the beginning or end of a file that configure editor settings for that specific file. Zed supports both Vim and Emacs modeline formats, allowing you to specify settings like tab size, indentation style, and file type directly within your files.
 4
 5## Configuration
 6
 7Use the [`modeline_lines`](./configuring-zed.md#modeline-lines) setting to control how many lines Zed searches for modelines:
 8
 9```json [settings]
10{
11  "modeline_lines": 5
12}
13```
14
15Set to `0` to disable modeline parsing entirely.
16
17## Emacs
18
19Zed has some compatibility support for [Emacs file variables](https://www.gnu.org/software/emacs/manual/html_node/emacs/Specifying-File-Variables.html).
20
21Example:
22
23```python
24# -*- mode: python; tab-width: 4; indent-tabs-mode: nil; -*-
25```
26
27### Supported Emacs Variables
28
29| Variable                   | Description                    | Zed Setting                                                           |
30| -------------------------- | ------------------------------ | --------------------------------------------------------------------- |
31| `mode`                     | Major mode/language            | Language detection                                                    |
32| `tab-width`                | Tab display width              | [`tab_size`](./configuring-zed.md#tab-size)                           |
33| `fill-column`              | Line wrap column               | [`preferred_line_length`](./configuring-zed.md#preferred-line-length) |
34| `indent-tabs-mode`         | `nil` for spaces, `t` for tabs | [`hard_tabs`](./configuring-zed.md#hard-tabs)                         |
35| `electric-indent-mode`     | Auto-indentation               | [`auto_indent`](./configuring-zed.md#auto-indent)                     |
36| `require-final-newline`    | Ensure final newline           | [`ensure_final_newline`](./configuring-zed.md#ensure-final-newline)   |
37| `show-trailing-whitespace` | Show trailing whitespace       | [`show_whitespaces`](./configuring-zed.md#show-whitespaces)           |
38
39## Vim
40
41Zed has some compatibility support for [Vim modeline](https://vimhelp.org/options.txt.html#modeline).
42
43Example:
44
45```python
46# vim: set ft=python ts=4 sw=4 et:
47```
48
49### Supported Vim Options
50
51| Option         | Aliases | Description                       | Zed Setting                                                           |
52| -------------- | ------- | --------------------------------- | --------------------------------------------------------------------- |
53| `filetype`     | `ft`    | File type/language                | Language detection                                                    |
54| `tabstop`      | `ts`    | Number of spaces a tab counts for | [`tab_size`](./configuring-zed.md#tab-size)                           |
55| `textwidth`    | `tw`    | Maximum line width                | [`preferred_line_length`](./configuring-zed.md#preferred-line-length) |
56| `expandtab`    | `et`    | Use spaces instead of tabs        | [`hard_tabs`](./configuring-zed.md#hard-tabs)                         |
57| `noexpandtab`  | `noet`  | Use tabs instead of spaces        | [`hard_tabs`](./configuring-zed.md#hard-tabs)                         |
58| `autoindent`   | `ai`    | Enable auto-indentation           | [`auto_indent`](./configuring-zed.md#auto-indent)                     |
59| `noautoindent` | `noai`  | Disable auto-indentation          | [`auto_indent`](./configuring-zed.md#auto-indent)                     |
60| `endofline`    | `eol`   | Ensure final newline              | [`ensure_final_newline`](./configuring-zed.md#ensure-final-newline)   |
61| `noendofline`  | `noeol` | Disable final newline             | [`ensure_final_newline`](./configuring-zed.md#ensure-final-newline)   |
62
63## Notes
64
65- The first kilobyte of a file is searched for modelines.
66- Emacs modelines take precedence over Vim modelines when both are present.
67- Modelines in the first few lines take precedence over those at the end of the file.