Skip to content

Commit dc77c46

Browse files
committed
docs: add Modelines documentation
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
1 parent 611392b commit dc77c46

File tree

4 files changed

+83
-0
lines changed

4 files changed

+83
-0
lines changed

docs/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# Configuration
1414

1515
- [Configuring Zed](./configuring-zed.md)
16+
- [Modelines](./modelines.md)
1617
- [Configuring Languages](./configuring-languages.md)
1718
- [Toolchains](./toolchains.md)
1819
- [Key bindings](./key-bindings.md)

docs/src/configuring-zed.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ For example you can set `tab_size`, `formatter` etc. but not `theme`, `vim_mode`
4343

4444
The syntax for configuration files is a super-set of JSON that allows `//` comments.
4545

46+
## Per-file Settings
47+
48+
Zed has some compatibility support for Emacs and Vim [modelines](./modelines.md), so you can set some settings per-file.
49+
4650
## Per-release Channel Overrides
4751

4852
Zed reads the same `settings.json` across all release channels (Stable, Preview or Nightly).
@@ -2710,6 +2714,16 @@ Positive `integer` values or `null` for unlimited tabs
27102714

27112715
`boolean` values
27122716

2717+
## Modeline Lines
2718+
2719+
- Description: Number of lines to search for modelines at the beginning and end of files. Modelines contain editor directives (e.g., vim/emacs settings) that configure the editor behavior for specific files. See [Modelines](./modelines.md) for more details on supported modeline variables.
2720+
- Setting: `modeline_lines`
2721+
- Default: `5`
2722+
2723+
**Options**
2724+
2725+
Positive `integer` values. Set to `0` to disable modeline parsing.
2726+
27132727
## Multi Cursor Modifier
27142728

27152729
- Description: Determines the modifier to be used to add multiple cursors with the mouse. The open hover link mouse gestures will adapt such that it do not conflict with the multicursor modifier.

docs/src/extensions/languages.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ line_comments = ["# "]
2727
- `tab_size` defines the indentation/tab size used for this language (default is `4`).
2828
- `hard_tabs` whether to indent with tabs (`true`) or spaces (`false`, the default).
2929
- `first_line_pattern` is a regular expression, that in addition to `path_suffixes` (above) or `file_types` in settings can be used to match files which should use this language. For example Zed uses this to identify Shell Scripts by matching the [shebangs lines](https://github.com/zed-industries/zed/blob/main/crates/languages/src/bash/config.toml) in the first line of a script.
30+
- `modeline_aliases` is an array of additional Emacs modes or Vim filetypes to map modeline settings to Zed language.
3031
- `debuggers` is an array of strings that are used to identify debuggers in the language. When launching a debugger's `New Process Modal`, Zed will order available debuggers by the order of entries in this array.
3132

3233
<!--

docs/src/modelines.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Modelines
2+
3+
Modelines 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+
7+
Use 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+
15+
Set to `0` to disable modeline parsing entirely.
16+
17+
## Emacs
18+
19+
Zed has some compatibility support for [Emacs file variables](https://www.gnu.org/software/emacs/manual/html_node/emacs/Specifying-File-Variables.html).
20+
21+
Example:
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+
41+
Zed has some compatibility support for [Vim modeline](https://vimhelp.org/options.txt.html#modeline).
42+
43+
Example:
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.

0 commit comments

Comments
 (0)