2017-12-03 23:21:00 +08:00
|
|
|
---
|
|
|
|
title: "SpaceVim lang#c layer"
|
2021-06-21 20:39:29 +08:00
|
|
|
description: "C/C++/Object-C language support for SpaceVim, including code completion, jump to definition, and quick runner."
|
2017-12-03 23:21:00 +08:00
|
|
|
---
|
|
|
|
|
2018-06-23 14:37:41 +08:00
|
|
|
# [Available Layers](../../) >> lang#c
|
2017-12-03 23:21:00 +08:00
|
|
|
|
|
|
|
<!-- vim-markdown-toc GFM -->
|
|
|
|
|
|
|
|
- [Description](#description)
|
2018-05-12 19:01:00 +08:00
|
|
|
- [Install](#install)
|
2017-12-24 20:43:20 +08:00
|
|
|
- [Features](#features)
|
2017-12-03 23:42:37 +08:00
|
|
|
- [Configuration](#configuration)
|
2018-05-12 19:01:00 +08:00
|
|
|
- [Key bindings](#key-bindings)
|
2022-04-26 01:45:08 +08:00
|
|
|
- [Jump to definition](#jump-to-definition)
|
|
|
|
- [Running current script](#running-current-script)
|
|
|
|
- [Inferior REPL process](#inferior-repl-process)
|
|
|
|
- [LSP key Bindings](#lsp-key-bindings)
|
2017-12-03 23:21:00 +08:00
|
|
|
|
|
|
|
<!-- vim-markdown-toc -->
|
|
|
|
|
|
|
|
## Description
|
|
|
|
|
2018-05-12 19:01:00 +08:00
|
|
|
`lang#c` layer provides c/c++/object-c language support for SpaceVim.
|
2017-12-03 23:21:00 +08:00
|
|
|
|
2018-05-12 19:01:00 +08:00
|
|
|
## Install
|
2017-12-03 23:21:00 +08:00
|
|
|
|
2020-04-10 19:11:25 +08:00
|
|
|
To use this configuration layer, update the custom configuration file with:
|
2018-06-23 14:37:41 +08:00
|
|
|
|
|
|
|
```toml
|
|
|
|
[[layers]]
|
|
|
|
name = "lang#c"
|
|
|
|
```
|
2017-12-03 23:21:00 +08:00
|
|
|
|
2017-12-24 20:43:20 +08:00
|
|
|
## Features
|
|
|
|
|
|
|
|
- code completion
|
|
|
|
- syntax checking
|
|
|
|
- formatting
|
2021-04-18 15:34:41 +08:00
|
|
|
- syntax highlighting: Objective-C(`.m`), C(`.c`), CPP(`.cpp`)
|
2017-12-24 20:43:20 +08:00
|
|
|
|
2017-12-03 23:42:37 +08:00
|
|
|
## Configuration
|
|
|
|
|
2019-04-13 13:56:41 +08:00
|
|
|
- `enable_clang_syntax_highlight` (boolean)
|
|
|
|
|
|
|
|
Enable/Disable clang based syntax highlighting.
|
|
|
|
|
2017-12-03 23:42:37 +08:00
|
|
|
- `clang_executable` (string)
|
|
|
|
|
2018-06-23 14:37:41 +08:00
|
|
|
Set the path to the clang executable
|
2017-12-03 23:42:37 +08:00
|
|
|
|
|
|
|
- `libclang_path` (string)
|
|
|
|
|
2019-02-03 20:51:01 +08:00
|
|
|
The libclang shared object (dynamic library) file path. By default it is empty.
|
2017-12-03 23:42:37 +08:00
|
|
|
|
|
|
|
- `clang_std` (dict)
|
|
|
|
|
2018-06-23 14:37:41 +08:00
|
|
|
A dict containing the standards you want to use. The default is:
|
|
|
|
|
2017-12-03 23:42:37 +08:00
|
|
|
```json
|
|
|
|
{
|
2022-04-26 01:45:08 +08:00
|
|
|
"c": "c11",
|
|
|
|
"cpp": "c++1z",
|
|
|
|
"objc": "c11",
|
|
|
|
"objcpp": "c++1z"
|
2017-12-03 23:42:37 +08:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2020-09-29 00:35:18 +08:00
|
|
|
- `clang_flag` (list)
|
2017-12-04 00:28:21 +08:00
|
|
|
|
2020-09-29 00:35:18 +08:00
|
|
|
You should be able to just paste most of your compile flags in there.
|
|
|
|
You can also use a list ['-Iwhatever', ...] when loading this layer.
|
2018-05-12 19:01:00 +08:00
|
|
|
|
2019-02-03 20:51:01 +08:00
|
|
|
Here is an example how to use above options:
|
2018-06-23 14:37:41 +08:00
|
|
|
|
|
|
|
```toml
|
|
|
|
[[layers]]
|
|
|
|
name = "lang#c"
|
|
|
|
clang_executable = "/usr/bin/clang"
|
2021-12-13 21:52:51 +08:00
|
|
|
clang_flag = ['-I/usr/include']
|
2018-06-23 14:37:41 +08:00
|
|
|
[layer.clang_std]
|
|
|
|
c = "c11"
|
|
|
|
cpp = "c++1z"
|
|
|
|
objc = "c11"
|
|
|
|
objcpp = "c++1z"
|
|
|
|
```
|
|
|
|
|
2020-09-29 00:35:18 +08:00
|
|
|
Instead of using `clang_flag` options, You can also create a `.clang` file
|
|
|
|
in the root directory of your project. SpaceVim will load the options
|
|
|
|
defined in `.clang` file. For example:
|
|
|
|
|
|
|
|
```
|
|
|
|
-std=c11
|
|
|
|
-I/home/test
|
|
|
|
```
|
|
|
|
|
|
|
|
Note: If `.clang` file contains std configuration, it will override
|
|
|
|
`clang_std` layer option.
|
2018-06-23 14:37:41 +08:00
|
|
|
|
2021-04-11 17:51:03 +08:00
|
|
|
`format_on_save`: Enable/disable file formatting when saving current file. By default,
|
|
|
|
it is disabled, to enable it:
|
2022-04-26 01:45:08 +08:00
|
|
|
|
2021-04-11 17:51:03 +08:00
|
|
|
```toml
|
|
|
|
[[layers]]
|
|
|
|
name = 'lang#c'
|
|
|
|
format_on_save = true
|
2022-04-26 01:45:08 +08:00
|
|
|
```
|
2021-04-11 17:51:03 +08:00
|
|
|
|
2018-05-12 19:01:00 +08:00
|
|
|
## Key bindings
|
|
|
|
|
2022-04-26 01:45:08 +08:00
|
|
|
### Jump to definition
|
|
|
|
|
|
|
|
| Mode | Key Bindings | Description |
|
|
|
|
| ------ | ------------ | ------------------------------------------------ |
|
|
|
|
| normal | `g d` | Jump to the definition position of cursor symbol |
|
|
|
|
|
|
|
|
### Running current script
|
|
|
|
|
|
|
|
To run current file, you can press `SPC l r` to run the current file without losing focus,
|
|
|
|
and the result will be shown in a runner buffer.
|
|
|
|
|
|
|
|
### Inferior REPL process
|
|
|
|
|
|
|
|
Start a `igcc` inferior REPL process with `SPC l s i`.
|
|
|
|
|
|
|
|
Send code to inferior process commands:
|
|
|
|
|
|
|
|
| Key Bindings | Descriptions |
|
|
|
|
| ------------ | ------------------------------------------------ |
|
|
|
|
| `SPC l s b` | send buffer and keep code buffer focused |
|
|
|
|
| `SPC l s l` | send line and keep code buffer focused |
|
|
|
|
| `SPC l s s` | send selection text and keep code buffer focused |
|
|
|
|
|
|
|
|
### LSP key Bindings
|
|
|
|
|
|
|
|
If the lsp layer is enabled for C/C++, the following key bindings can
|
|
|
|
be used:
|
|
|
|
|
|
|
|
| key binding | Description |
|
|
|
|
| ----------- | ----------------------- |
|
|
|
|
| `g D` | jump to declaration |
|
|
|
|
| `SPC l e` | rename symbol |
|
|
|
|
| `SPC l x` | show references |
|
|
|
|
| `SPC l s` | show line diagnostics |
|
|
|
|
| `SPC l d` | show document |
|
|
|
|
| `K` | show document |
|
|
|
|
| `SPC l w l` | list workspace folder |
|
|
|
|
| `SPC l w a` | add workspace folder |
|
|
|
|
| `SPC l w r` | remove workspace folder |
|