spacevim/docs/_posts/2019-05-10-use-vim-as-a-c-cpp-ide.md
JIe 2bb7059579
Some checks failed
Detach Plugins / check (FlyGrep.vim) (push) Has been cancelled
Detach Plugins / check (GitHub.vim) (push) Has been cancelled
Detach Plugins / check (JavaUnit.vim) (push) Has been cancelled
Detach Plugins / check (SourceCounter.vim) (push) Has been cancelled
Detach Plugins / check (cpicker.nvim) (push) Has been cancelled
Detach Plugins / check (dein-ui.vim) (push) Has been cancelled
Detach Plugins / check (git.vim) (push) Has been cancelled
Detach Plugins / check (iedit.vim) (push) Has been cancelled
Detach Plugins / check (scrollbar.vim) (push) Has been cancelled
Detach Plugins / check (vim-chat) (push) Has been cancelled
Detach Plugins / check (vim-cheat) (push) Has been cancelled
Detach Plugins / check (vim-todo) (push) Has been cancelled
Detach Plugins / check (xmake.vim) (push) Has been cancelled
test / Linux (nvim, nightly) (push) Has been cancelled
test / Linux (nvim, v0.3.8) (push) Has been cancelled
test / Linux (nvim, v0.4.0) (push) Has been cancelled
test / Linux (nvim, v0.4.2) (push) Has been cancelled
test / Linux (nvim, v0.4.3) (push) Has been cancelled
test / Linux (nvim, v0.4.4) (push) Has been cancelled
test / Linux (nvim, v0.5.0) (push) Has been cancelled
test / Linux (nvim, v0.5.1) (push) Has been cancelled
test / Linux (nvim, v0.6.0) (push) Has been cancelled
test / Linux (nvim, v0.6.1) (push) Has been cancelled
test / Linux (nvim, v0.7.0) (push) Has been cancelled
test / Linux (nvim, v0.7.2) (push) Has been cancelled
test / Linux (nvim, v0.8.0) (push) Has been cancelled
test / Linux (nvim, v0.8.1) (push) Has been cancelled
test / Linux (nvim, v0.8.2) (push) Has been cancelled
test / Linux (nvim, v0.8.3) (push) Has been cancelled
test / Linux (nvim, v0.9.0) (push) Has been cancelled
test / Linux (nvim, v0.9.1) (push) Has been cancelled
test / Linux (true, vim, v7.4.052) (push) Has been cancelled
test / Linux (true, vim, v7.4.1689) (push) Has been cancelled
test / Linux (true, vim, v7.4.629) (push) Has been cancelled
test / Linux (true, vim, v8.0.0027) (push) Has been cancelled
test / Linux (true, vim, v8.0.0183) (push) Has been cancelled
test / Linux (vim, nightly) (push) Has been cancelled
test / Linux (vim, v8.0.0184) (push) Has been cancelled
test / Linux (vim, v8.0.1453) (push) Has been cancelled
test / Linux (vim, v8.1.2269) (push) Has been cancelled
test / Linux (vim, v8.2.2434) (push) Has been cancelled
test / Linux (vim, v8.2.3995) (push) Has been cancelled
test / Windows (nvim, nightly) (push) Has been cancelled
test / Windows (nvim, v0.3.8) (push) Has been cancelled
test / Windows (nvim, v0.4.2) (push) Has been cancelled
test / Windows (nvim, v0.4.3) (push) Has been cancelled
test / Windows (nvim, v0.4.4) (push) Has been cancelled
test / Windows (nvim, v0.5.0) (push) Has been cancelled
test / Windows (nvim, v0.5.1) (push) Has been cancelled
test / Windows (nvim, v0.6.0) (push) Has been cancelled
test / Windows (nvim, v0.6.1) (push) Has been cancelled
test / Windows (nvim, v0.7.0) (push) Has been cancelled
test / Windows (nvim, v0.7.2) (push) Has been cancelled
test / Windows (nvim, v0.8.0) (push) Has been cancelled
test / Windows (nvim, v0.8.1) (push) Has been cancelled
test / Windows (nvim, v0.8.2) (push) Has been cancelled
test / Windows (nvim, v0.8.3) (push) Has been cancelled
test / Windows (nvim, v0.9.0) (push) Has been cancelled
test / Windows (nvim, v0.9.1) (push) Has been cancelled
test / Windows (vim, nightly) (push) Has been cancelled
test / Windows (vim, v7.4.1185) (push) Has been cancelled
test / Windows (vim, v7.4.1689) (push) Has been cancelled
test / Windows (vim, v8.0.0027) (push) Has been cancelled
test / Windows (vim, v8.0.1453) (push) Has been cancelled
test / Windows (vim, v8.1.2269) (push) Has been cancelled
test / Windows (vim, v8.2.2434) (push) Has been cancelled
test / Windows (vim, v8.2.3995) (push) Has been cancelled
docker / docker (push) Has been cancelled
mirror / check (coding) (push) Has been cancelled
mirror / check (gitee) (push) Has been cancelled
mirror / check (gitlab) (push) Has been cancelled
init
2024-08-21 14:17:26 +08:00

4.1 KiB

title categories image description type comments commentsID language
Use Vim as a C/C++ IDE
tutorials
blog
https://img.spacevim.org/58743787-db2bee80-846a-11e9-9b19-17202ac542c9.png A general guide for using SpaceVim as C/C++ IDE, including layer configuration, requiems installation and usage. article true Use Vim as a C/C++ IDE C/C++

Blogs >> Use Vim as a C/C++ IDE

This is a general guide for using SpaceVim as a C/C++ IDE, including layer configuration and usage. Each of the following sections will be covered:

Enable language layer

To add C/C++ language support in SpaceVim, you need to enable the lang#c layer. Press SPC f v d to open SpaceVim configuration file, and add following configuration:

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

for more info, you can read the lang#c layer documentation.

Syntax highlighting

The basic syntax highlighting is based on regular expression, If you want clang based syntax highlighting. Enable enable_clang_syntax_highlight layer option:

[[layers]]
    name = 'lang#c'
    enable_clang_syntax_highlight = true

This option requires +python or +python3 enabled and libclang has been installed.

code completion

By default the autocomplete layer has been enabled, so after loading lang#c layer, the code completion for C/C++ language should works well.

If the autocomplete_method is deoplete, then Shougo/deoplete-clangx will be loaded in lang#c layer.

If the autocomplete_method is asyncomplete, then wsdjeg/asyncomplete-clang.vim will be loaded.

If the autocomplete_method is neocomplete, Then Rip-Rip/clang_complete will be loaded.

You can check the value of autocomplete_method via :SPSet autocomplete_method.

alternate file jumping

To manage alternate files for a project, you may need to create a .project_alt.json file in the root of your project.

For example, add the following content into the .project_alt.json file:

{
  "*.c": {"alternate": "{}.h"},
  "*.h": {"alternate": "{}.c"}
}

With this configuration, you can jump between alternate files via command :A

code running

The default code running key binding is SPC l r. It will compile and run current file asynchronously. And the stdout will be shown on a runner buffer.

c-cpp-runner

The default runner compile option is defineded in clang_std and clang_flag option. If you want to use c11, you can change clang_std option to:

[[layers]]
  name = "lang#c"
  [layers.clang_std]
    cpp = "c11"

You can also create a .clang file in the root directory of you project. Within this file, all compile option should be defineded in it. for example:

-I/home/test
-I/user/std/include

Syntax lint

The checker layer provides syntax checking for many programming languages. Including C/C++, and the default plugin is neomake. The default lint for C/C++ is gcc/g++. These commands also read configuration in .clang file.

code format

In order to be able to format C/C++ files, you need to install uncrustify, clangformat or astyle. The key binding SPC b f is defineded in format layer which is loaded by default. In this layer, the default format engine is neoformat.

REPL support

Start a igcc inferior REPL process with SPC l s i. After the REPL process being started, you can send code to inferior process, all key bindings prefix with SPC l s, including sending line, sending selection or even send whole buffer.

c_repl