c.md

 1# C
 2
 3C support is available natively in Zed.
 4
 5- Tree Sitter: [tree-sitter/tree-sitter-c](https://github.com/tree-sitter/tree-sitter-c)
 6- Language Server: [clangd/clangd](https://github.com/clangd/clangd)
 7
 8## Clangd: Force detect as C
 9
10Clangd out of the box assumes mixed C++/C projects. If you have a C-only project you may wish to instruct clangd to all files as C using the `-xc` flag. To do this, create a `.clangd` file in the root of your project with the following:
11
12```yaml
13CompileFlags:
14  Add: [-xc]
15```
16
17## Formatting
18
19By default Zed will use the `clangd` language server for formatting C code. The Clangd is the same as the `clang-format` CLI tool. To configure this you can add a `.clang-format` file. For example:
20
21```yaml
22---
23BasedOnStyle: GNU
24IndentWidth: 2
25---
26```
27
28See [Clang-Format Style Options](https://clang.llvm.org/docs/ClangFormatStyleOptions.html) for a complete list of options.
29
30You can trigger formatting via {#kb editor::Format} or the `editor: format` action from the command palette or by adding `format_on_save` to your Zed settings:
31
32```json
33  "languages": {
34    "C" {
35      "format_on_save": "on",
36      "tab_size": 2
37    }
38  }
39```
40
41See [Clang-Format Style Options](https://clang.llvm.org/docs/ClangFormatStyleOptions.html) for a complete list of options.