Back to Spacevim

SpaceVim lang#c layer

docs/layers/lang/c.md

2.4.03.7 KB
Original Source

Available Layers >> lang#c

<!-- vim-markdown-toc GFM --> <!-- vim-markdown-toc -->

Description

lang#c layer provides c/c++/object-c language support for SpaceVim.

Install

To use this configuration layer, update the custom configuration file with:

toml
[[layers]]
  name = "lang#c"

for windows users, if you want to install llvm without vs build tools, you can install mingw-winlibs-llvm:

scoop install mingw-winlibs-llvm

Features

  • code completion
  • syntax checking
  • formatting
  • syntax highlighting: Objective-C(.m), C(.c), CPP(.cpp)

Configuration

  • enable_clang_syntax_highlight (boolean)

Enable/Disable clang based syntax highlighting.

  • clang_executable (string)

Set the path to the clang executable

  • libclang_path (string)

The libclang shared object (dynamic library) file path. By default it is empty.

  • clang_std (dict)

A dict containing the standards you want to use. The default is:

json
{
  "c": "c11",
  "cpp": "c++1z",
  "objc": "c11",
  "objcpp": "c++1z"
}
  • clang_flag (list)

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.

Here is an example how to use above options:

toml
[[layers]]
  name = "lang#c"
  clang_executable = "/usr/bin/clang"
  clang_flag = ['-I/usr/include']
  [layers.clang_std]
    c = "c11"
    cpp = "c++1z"
    objc = "c11"
    objcpp = "c++1z"

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.

format_on_save: Enable/disable file formatting when saving current file. By default, it is disabled, to enable it:

toml
[[layers]]
    name = 'lang#c'
    format_on_save = true

Key bindings

Jump to definition

ModeKey BindingsDescription
normalg dJump 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 BindingsDescriptions
SPC l s bsend buffer and keep code buffer focused
SPC l s lsend line and keep code buffer focused
SPC l s ssend 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 bindingDescription
g Djump to declaration
SPC l erename symbol
SPC l xshow references
SPC l sshow line diagnostics
SPC l dshow document
Kshow document
SPC l w llist workspace folder
SPC l w aadd workspace folder
SPC l w rremove workspace folder