Vim plugin for Cap'n Proto schema files (.capnp).
- Syntax highlighting – keywords, types, literals, annotations, file IDs, field ordinals, strings, hex data, numbers, and comments
- Indentation – smart 2-space indentation based on Cap'n Proto block structure
- Compiler integration – run
capnp compilefrom inside Vim and parse errors into the quickfix list - File type settings – comment string, folding,
gfnavigation on imports - Utility commands – encode/decode messages, evaluate constants, and auto-number field ordinals
- Vim 8+ or Neovim
- The
capnpcommand-line tool must be on your$PATHfor compiler integration and the utility commands
Use your favourite plugin manager.
Plug 'capnproto/capnp.vim'{ 'capnproto/capnp.vim' }Manual – copy the directories into your ~/.vim (Vim) or
~/.config/nvim (Neovim) folder.
The plugin activates automatically for any file with the .capnp extension.
| Command | Description |
|---|---|
:CapnpId |
Insert a new unique file ID at the cursor |
:CapnpEncode |
Encode the buffer (or visual selection) to binary Cap'n Proto |
:CapnpDecode |
Decode a binary Cap'n Proto buffer to text |
:CapnpEval [const] |
Evaluate a Cap'n Proto constant expression |
:CapnpSetOrdinals [n] |
Replace @? placeholders with sequential ordinals |
The capnp compiler is set automatically for .capnp buffers. Use :make to
compile the current file and :copen to inspect errors.
Customise the flags passed to capnp compile:
" Global default (syntax-check only by default: -ocapnp)
let g:capnp_compiler_flags = '-I/usr/local/include -oc++'
" Buffer-local override (takes precedence)
let b:capnp_compiler_flags = '-oc++'Set the schema and type name for the current buffer before calling
:CapnpEncode or :CapnpDecode:
let b:capnp_schema = '/path/to/schema.capnp'
let b:capnp_type_name = 'MyMessage'If these variables are not set the commands will prompt you interactively.
BSD 2-Clause. See LICENSE.