completions.md

  1# Completions
  2
  3Zed supports two sources for completions:
  4
  51. "Code Completions" provided by Language Servers (LSPs) automatically installed by Zed or via [Zed Language Extensions](languages.md).
  62. "Edit Predictions" provided by Zed's own Zeta model or by external providers like [GitHub Copilot](#github-copilot) or [Supermaven](#supermaven).
  7
  8## Language Server Code Completions {#code-completions}
  9
 10When there is an appropriate language server available, Zed will provide completions of variable names, functions, and other symbols in the current file. You can disable these by adding the following to your Zed `settings.json` file:
 11
 12```json
 13"show_completions_on_input": false
 14```
 15
 16You can manually trigger completions with `ctrl-space` or by triggering the `editor::ShowCompletions` action from the command palette.
 17
 18For more information, see:
 19
 20- [Configuring Supported Languages](./configuring-languages.md)
 21- [List of Zed Supported Languages](./languages.md)
 22
 23## Edit Predictions {#edit-predictions}
 24
 25Zed has built-in support for predicting multiple edits at a time [via Zeta](https://huggingface.co/zed-industries/zeta), Zed's open-source and open-data model.
 26Edit predictions appear as you type, and most of the time, you can accept them by pressing `tab`.
 27
 28### Configuring Zeta
 29
 30Zed's Edit Prediction was initially introduced via a banner on the title bar.
 31Clicking on it would take you to a modal with a button ("Enable Edit Prediction") that sets `zed` as your `edit_prediction_provider`.
 32
 33![Onboarding banner and modal](https://zed.dev/img/edit-prediction/docs.webp)
 34
 35But, if you haven't come across the banner, Zed's Edit Prediction is the default edit prediction provider and you should see it right away in your status bar.
 36
 37### Switching Modes {#switching-modes}
 38
 39Zed's Edit Prediction comes with two different display modes:
 40
 411. `eager` (default): predictions are displayed inline as long as it doesn't conflict with language server completions
 422. `subtle`: predictions only appear inline when holding a modifier key (`alt` by default)
 43
 44Toggle between them via the `mode` key:
 45
 46```json
 47"edit_predictions": {
 48  "mode": "eager" | "subtle"
 49},
 50```
 51
 52Or directly via the UI through the status bar menu:
 53
 54![Edit Prediction status bar menu, with the modes toggle.](https://zed.dev/img/edit-prediction/status-bar-menu.webp)
 55
 56### Conflict With Other `tab` Actions {#edit-predictions-conflict}
 57
 58By default, when `tab` would normally perform a different action, Zed requires a modifier key to accept predictions:
 59
 601. When the language server completions menu is visible.
 612. When your cursor isn't at the right indentation level.
 62
 63In these cases, `alt-tab` is used instead to accept the prediction. When the language server completions menu is open, holding `alt` first will cause it to temporarily disappear in order to preview the prediction within the buffer.
 64
 65On Linux, `alt-tab` is often used by the window manager for switching windows, so `alt-l` is provided as the default binding for accepting predictions. `tab` and `alt-tab` also work, but aren't displayed by default.
 66
 67{#action editor::AcceptPartialEditPrediction} ({#kb editor::AcceptPartialEditPrediction}) can be used to accept the current edit prediction up to the next word boundary.
 68
 69See the [Configuring GitHub Copilot](#github-copilot) and [Configuring Supermaven](#supermaven) sections below for configuration of other providers. Only text insertions at the current cursor are supported for these providers, whereas the Zeta model provides multiple predictions including deletions.
 70
 71## Configuring Edit Prediction Keybindings {#edit-predictions-keybinding}
 72
 73By default, `tab` is used to accept edit predictions. You can use another keybinding by inserting this in your keymap:
 74
 75```json
 76{
 77  "context": "Editor && edit_prediction",
 78  "bindings": {
 79    // Here we also allow `alt-enter` to accept the prediction
 80    "alt-enter": "editor::AcceptEditPrediction"
 81  }
 82}
 83```
 84
 85When there's a [conflict with the `tab` key](#edit-predictions-conflict), Zed uses a different context to accept keybindings (`edit_prediction_conflict`). If you want to use a different one, you can insert this in your keymap:
 86
 87```json
 88{
 89  "context": "Editor && edit_prediction_conflict",
 90  "bindings": {
 91    "ctrl-enter": "editor::AcceptEditPrediction" // Example of a modified keybinding
 92  }
 93}
 94```
 95
 96If your keybinding contains a modifier (`ctrl` in the example above), it will also be used to preview the edit prediction and temporarily hide the language server completion menu.
 97
 98You can also bind this action to keybind without a modifier. In that case, Zed will use the default modifier (`alt`) to preview the edit prediction.
 99
100```json
101{
102  "context": "Editor && edit_prediction_conflict",
103  "bindings": {
104    // Here we bind tab to accept even when there's a language server completion
105    // or the cursor isn't at the correct indentation level
106    "tab": "editor::AcceptEditPrediction"
107  }
108}
109```
110
111To maintain the use of the modifier key for accepting predictions when there is a language server completions menu, but allow `tab` to accept predictions regardless of cursor position, you can specify the context further with `showing_completions`:
112
113```json
114{
115  "context": "Editor && edit_prediction_conflict && !showing_completions",
116  "bindings": {
117    // Here we don't require a modifier unless there's a language server completion
118    "tab": "editor::AcceptEditPrediction"
119  }
120}
121```
122
123### Keybinding Example: Always Use Alt-Tab
124
125The keybinding example below causes `alt-tab` to always be used instead of sometimes using `tab`. You might want this in order to have just one keybinding to use for accepting edit predictions, since the behavior of `tab` varies based on context.
126
127```json
128  {
129    "context": "Editor && edit_prediction",
130    "bindings": {
131      "alt-tab": "editor::AcceptEditPrediction"
132    }
133  },
134  // Bind `tab` back to its original behavior.
135  {
136    "context": "Editor",
137    "bindings": {
138      "tab": "editor::Tab"
139    }
140  },
141  {
142    "context": "Editor && showing_completions",
143    "bindings": {
144      "tab": "editor::ComposeCompletion"
145    }
146  },
147```
148
149If `"vim_mode": true` is set within `settings.json`, then additional bindings are needed after the above to return `tab` to its original behavior:
150
151```json
152  {
153    "context": "(VimControl && !menu) || vim_mode == replace || vim_mode == waiting",
154    "bindings": {
155      "tab": "vim::Tab"
156    }
157  },
158  {
159    "context": "vim_mode == literal",
160    "bindings": {
161      "tab": ["vim::Literal", ["tab", "\u0009"]]
162    }
163  },
164```
165
166### Keybinding Example: Displaying Tab and Alt-Tab on Linux
167
168While `tab` and `alt-tab` are supported on Linux, `alt-l` is displayed instead. If your window manager does not reserve `alt-tab`, and you would prefer to use `tab` and `alt-tab`, include these bindings in `keymap.json`:
169
170```json
171  {
172    "context": "Editor && edit_prediction",
173    "bindings": {
174      "tab": "editor::AcceptEditPrediction",
175      // Optional: This makes the default `alt-l` binding do nothing.
176      "alt-l": null
177    }
178  },
179  {
180    "context": "Editor && edit_prediction_conflict",
181    "bindings": {
182      "alt-tab": "editor::AcceptEditPrediction",
183      // Optional: This makes the default `alt-l` binding do nothing.
184      "alt-l": null
185    }
186  },
187```
188
189### Missing keybind {#edit-predictions-missing-keybinding}
190
191Zed requires at least one keybinding for the {#action editor::AcceptEditPrediction} action in both the `Editor && edit_prediction` and `Editor && edit_prediction_conflict` contexts ([learn more above](#edit-predictions-keybinding)).
192
193If you have previously bound the default keybindings to different actions in the global context, you will not be able to preview or accept edit predictions. For example:
194
195```json
196[
197  // Your keymap
198  {
199    "bindings": {
200      // Binds `alt-tab` to a different action globally
201      "alt-tab": "menu::SelectNext"
202    }
203  }
204]
205```
206
207To fix this, you can specify your own keybinding for accepting edit predictions:
208
209```json
210[
211  // ...
212  {
213    "context": "Editor && edit_prediction_conflict",
214    "bindings": {
215      "alt-l": "editor::AcceptEditPrediction"
216    }
217  }
218]
219```
220
221If you would like to use the default keybinding, you can free it up by either moving yours to a more specific context or changing it to something else.
222
223## Disabling Automatic Edit Prediction
224
225There are different levels in which you can disable edit predictions to be displayed, including not having it turned on at all.
226
227Alternatively, if you have Zed set as your provider, consider [using Subtle Mode](#switching-modes).
228
229### On Buffers
230
231To not have predictions appear automatically as you type, set this within `settings.json`:
232
233```json
234{
235  "show_edit_predictions": false
236}
237```
238
239This hides every indication that there is a prediction available, regardless of [the display mode](#switching-modes) you're in (valid only if you have Zed as your provider).
240Still, you can trigger edit predictions manually by executing {#action editor::ShowEditPrediction} or hitting {#kb editor::ShowEditPrediction}.
241
242### For Specific Languages
243
244To not have predictions appear automatically as you type when working with a specific language, set this within `settings.json`:
245
246```json
247{
248  "language": {
249    "python": {
250      "show_edit_predictions": false
251    }
252  }
253}
254```
255
256### Turning Off Completely
257
258To completely turn off edit prediction across all providers, explicitly set the settings to `none`, like so:
259
260```json
261"features": {
262  "edit_prediction_provider": "none"
263},
264```
265
266## Configuring GitHub Copilot {#github-copilot}
267
268To use GitHub Copilot as your provider, set this within `settings.json`:
269
270```json
271{
272  "features": {
273    "edit_prediction_provider": "copilot"
274  }
275}
276```
277
278You should be able to sign-in to GitHub Copilot by clicking on the Copilot icon in the status bar and following the setup instructions.
279
280Copilot can provide multiple completion alternatives, and these can be navigated with the following actions:
281
282- {#action editor::NextEditPrediction} ({#kb editor::NextEditPrediction}): To cycle to the next edit prediction
283- {#action editor::PreviousEditPrediction} ({#kb editor::PreviousEditPrediction}): To cycle to the previous edit prediction
284
285## Configuring Supermaven {#supermaven}
286
287To use Supermaven as your provider, set this within `settings.json`:
288
289```json
290{
291  "features": {
292    "edit_prediction_provider": "supermaven"
293  }
294}
295```
296
297You should be able to sign-in to Supermaven by clicking on the Supermaven icon in the status bar and following the setup instructions.
298
299## See also
300
301You may also use the Assistant Panel or the Inline Assistant to interact with language models, see [the assistant documentation](assistant/assistant.md) for more information.