- Vim
- Neovim
- Emacs
- Helix
Vim Configuration
Vim can be configured with the YouCompleteMe plugin to provide code completion.Setup
Install YouCompleteMe
Follow the installation instructions for your platform.
Features
With YouCompleteMe configured, you’ll have:- Code completion
- Jump to definition
- Error/warning diagnostics
- Semantic highlighting
Neovim Configuration
Neovim can be configured with COC-clangd for code completion and git-blame for inline git information.Make sure you’ve run
Meta/serenity.sh run at least once before configuring Neovim.Install vim-plug
See https://github.com/junegunn/vim-plug for installation instructions.Install coc.nvim
Add Plugin to init.vim
The config file is at
~/.config/nvim/init.vim or $XDG_CONFIG_HOME/nvim/init.vim.Add the plugin:Plug 'neoclide/coc.nvim', { 'branch': 'release' }
Install coc-clangd
Configure coc-clangd
Edit~/.config/nvim/coc-settings.json or run :CocConfig:{
"clangd.fallbackFlags": ["-std=c++26"],
"clangd.arguments": ["--query-driver=${workspaceFolder}/Toolchain/Local/**/*"],
"semanticTokens.enable": true,
"inlayHint.subSeparator": "︴",
"inlayHints.enableParameter": true,
"clangd.inlayHints.sep": "⇝"
}
- If you had another C++ language server configured, remove it first to avoid conflicts
- If you configured
clangdas a languageServer incoc-settings.json, remove it to avoid running clangd twice clangd.inlayHints.sepbreaks on clangd 15.0.6
Formatting
Install the formatter plugin:Plug 'mhartington/formatter.nvim'
require("formatter").setup{
filetype = {
cpp = {
require("formatter.filetypes.cpp").clangformat
}
}
}
Git Blame (Optional)
Complete init.vim Configuration
View complete init.vim excerpt
View complete init.vim excerpt
"IMPORTANT: the leader key for <leader> keycombos
let mapleader = "\\"
"BEGIN: git blame (optional)
hi GitBlame guifg=#7b7b7b
let g:gitblame_date_format = '%d.%m.%y %H:%M'
let g:gitblame_highlight_group = 'GitBlame'
let g:gitblame_message_when_not_committed = 'You: Uncommitted changes'
let g:gitblame_message_template = ' <author> (<committer>), <date> <sha> • <summary>'
"END: git blame
"BEGIN: coc
"inline hints (depending on clangd version one or another gets used)
hi CocHintVirtualText guifg=#84afe0
hi CocInlayHint guifg=#84afe0 guibg=#393939
hi CocInlayHintParameter guifg=#84afe0 guibg=#393939
hi CocInlayHintType guifg=#89ddff guibg=#393939
"semantic highlighting
hi CocSemMethod guifg=#bfaa87 gui=bold
hi CocSemFunction guifg=#bfaaf7 gui=bold
hi CocSemParameter guifg=#a9bfd1 gui=underline
hi CocSemVariable guifg=#8edbdb
hi CocSemProperty guifg=#23ce6d
hi link CocSemEnumMember Constant
hi link CocSemEnum CocSemClass
hi Constant guifg=#f78c6c
hi CocSemClass guifg=#89ddff
hi Statement guifg=#c792ea
hi Type guifg=#db954a
"remap keys for applying refactor code actions (on warnings) (\re)
nmap <silent> <leader>re <Plug>(coc-codeaction-refactor)
xmap <silent> <leader>r <Plug>(coc-codeaction-refactor-selected)
nmap <silent> <leader>r <Plug>(coc-codeaction-refactor-selected)
"outline for file (\o)
nmap <silent><nowait> <leader>o :<C-u>CocList outline<cr>
"goto definition etc.
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gt <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
"coc rename (\rn)
nmap <leader>rn <Plug>(coc-rename)
"prev or next error
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
"confirm coc-suggestion with enter
imap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm() : "\<CR>"
"ctrl+space for completion
imap <silent><expr> <c-space> coc#refresh()
"show documentation with ctrl+k
nmap <silent><c-k> :call ShowDocumentation()<CR>
"show documentation if it's available
function! ShowDocumentation()
if CocAction('hasProvider', 'hover')
call CocActionAsync('doHover')
else
call feedkeys('K', 'in')
endif
endfunction
"coc-clangd switch between header and source
nmap <silent>gs :CocCommand clangd.switchSourceHeader vsplit<CR>
"END: coc
Configure .clangd
Configure.clangd as explained in ClangdConfiguration.Emacs Configuration
Emacs can be configured withlsp-mode and clangd for excellent SerenityOS development support.clangd Setup
The official clangd extension provides C++ comprehension. See ClangdConfiguration for configuration details.There are several ways to specify which clangd to use:- Default:
lsp-modewill find and use your systemclangd(easiest, but may be outdated) - Manual path: Specify any clangd binary with
lsp-clangd-binary-path - Managed installation: Use
lsp-install-serverto letlsp-modemanage the installation
lsp-mode Configuration
(use-package lsp-mode
:hook ((c++-mode) . lsp-deferred)
:commands lsp
:config
;; clangd arguments, refer to ClangdConfiguration.md for what other arguments may be needed.
(setq lsp-clients-clangd-args '("-j=4" "-background-index" "--log=error" "--clang-tidy" "--enable-config"))
;; Optionally, set the location of clangd -- See above for options.
(setq lsp-clangd-binary-path "/usr/bin/clangd"))
clang-format Integration
There are multiple packages for auto-formatting with clang-format:Alternative: Use lsp-mode for Formatting
You can format without additional packages by usinglsp-mode. Create .dir-locals.el in the project root:((c++-mode
(eval add-hook 'before-save-hook #'lsp-format-buffer nil t)))
Helix Configuration
Helix comes with support forclangd and clang-format out of the box!Setup
See ClangdConfiguration for how to configure clangd.To configure clangd command-line arguments, create.helix/languages.toml in the project root:[language-server.serenity]
command = "clangd"
# clangd arguments, refer to ClangdConfiguration.md for what may be needed.
args = []
[[language]]
name = "cpp"
language-servers = ["serenity"]
Features
Helix provides out of the box:- Code completion via clangd
- Jump to definition
- Find references
- Automatic formatting with clang-format
- Syntax highlighting
- Error diagnostics
