Skip to content
vstiagoPublic

About

Vim Compiler Explorer

Resources

Security policy

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

vice — Local Compiler Explorer for Vim & Neovim

vice brings a fast, local-first, live Compiler Explorer directly into Vim (8.2+/9+) and Neovim (0.10+) on Windows and Linux.

No web APIs, no uploading private code, no embedded +python3 build headaches, and zero runtime third-party Python dependencies.


See It in Action

Live Compilation & Bidirectional Source↔Assembly Sync

Type in your buffer and watch demangled assembly update asynchronously with color-coded line mappings (:ViceOpen clang -O2):

Live C++ compilation and bidirectional highlight sync in vice

Side-by-Side Optimization Comparison with Semantic Diff Cues

Compare flags or compilers side-by-side (:ViceCompare clang -O0 vs clang -O2) with label-normalized +/-/~ gutter diff cues:

Side-by-side clang -O0 vs -O2 comparison with semantic diff cues

Zero-Install Python Bytecode (auto Routing)

Open any .py file and run :ViceOpen with zero external compiler installs — or compare -O0 vs -O1 to watch assert bytecode disappear:

Python bytecode disassembly and -O0 vs -O1 comparison

All demos above are reproducibly generated from live vice-core output via scripts/demos/generate_gifs.py.


Highlights

  • Works in both Vim and Neovim (Windows & Linux): Async binary NDJSON JSON-RPC 2.0 stdio worker (vice-core, Python 3.11+ stdlib-only)—never freezes your editor and needs zero pip install.
  • Real project & unsaved buffer support: Pipes unsaved buffer contents via stdin with -iquote <source_dir> so relative #include "..." works while typing, plus trust-gated compile_commands.json flag loading.
  • Cross-platform ABI & debug info: Parses Linux ELF DWARF v4/v5 (.file/.loc), Windows Clang COFF/CodeView (.cv_file/.cv_loc, quoted MSVC labels, SEH), ARM64 (// comments, arch-gated -masm=intel), and LLVM IR (!dbg/!DILocation).
  • Batched symbol demangling: Demangles hundreds of C++ symbols in one call (in-process Windows dbghelp.dll for MSVC + llvm-cxxfilt / c++filt).
  • Multi-language, bytecode & performance analysis: Built-in adapters for C/C++ (GCC, Clang, MSVC cl.exe), LLVM IR (llvm-ir), LLVM-MCA (llvm-mca cycle/IPC/resource-pressure reports), WebAssembly (wasm/wat via clang --target=wasm32 + llvm-objdump/wasm2wat), Binary Disassembly (objdump / llvm-objdump), Python Bytecode & AST (python-dis, python-ast, zero external tools, never executes user code), Java Bytecode (java, javac -g + javap -c -p -l with LineNumberTable), Rust (rustc), Zig (zig), and Go (go Plan 9 asm). :ViceOpen automatically routes by filetype/extension.
  • Interactive assembly UX & inline metrics: Press K (:ViceExplain) on any x86-64, ARM64, Python, JVM, or WebAssembly instruction for an offline opcode explanation; press gd or <CR> on a branch target/call to jump straight to its label (<C-o> jumps back); fold functions with za/zM/zR; toggle inline per-line instruction counts ([3 insns]) with :ViceToggleMetrics; and toggle Clang optimization remarks (-Rpass*) with :ViceRemarks.
  • Multi-pane comparisons with semantic diff cues: Open synchronized mirrors (:ViceCompare clang -O0 vs clang -O3, or :ViceCompare clang -O2 vs llvm-ir -O1) with color-coded source↔output highlighting, label-normalized semantic diff signs (+/-/~, ignoring synthetic .LBB0_1 vs .L3 label differences), bidirectional cursor sync, and dimmed [STALE] retention on transient syntax errors.
  • Extensible by design: Add any local compiler declaratively via user-owned compilers.toml (gas, llvm-ir, or passthrough parsers), or ship third-party Python adapters via the vice.compilers entry-point group.
  • AI-friendly: Export selected source + exact mapped assembly/IR + flags via :ViceContext, script structured Schema v1 JSON with vice compile --format json, or connect MCP-compatible AI agents directly via the zero-dependency vice mcp server (compile_code, compare_compilers, list_compilers).

Requirements

  • Editor: Vim 8.2+ / 9+ or Neovim 0.10+
  • Python: Python 3.11+ on PATH (no external Python packages required)
  • Compiler: clang/clang++ and/or gcc/g++ (or any custom compiler configured in compilers.toml)

Installation

Neovim (lazy.nvim)

{
  "vstiago/vice",
  config = function()
    require("vice").setup({
      default_compiler = "auto",
      syntax = "intel", -- automatically gated to x86/x86-64 targets
      debounce_ms = 400,
      keymaps = {
        open = "<leader>vo",
        compare = "<leader>vd",
        close = "<leader>vc",
        toggle_highlight = "<leader>vh",
        context = "<leader>vx",
      },
    })
  end,
}

Vim (vim-plug)

Plug 'vstiago/vice'

" Optional configuration & <Plug> mappings:
let g:vice_default_compiler = 'auto'
let g:vice_debounce_ms = 400

nmap <leader>vo <Plug>(ViceOpen)
nmap <leader>vd <Plug>(ViceCompare)
nmap <leader>vc <Plug>(ViceClose)
nmap <leader>vh <Plug>(ViceToggleHighlight)
nmap <leader>vx <Plug>(ViceContext)
xmap <leader>vx <Plug>(ViceContext)

Native Vim / Neovim Packages

git clone https://github.com/vstiago/vice.git ~/.vim/pack/plugins/start/vice

Verify your setup

  • Neovim: :checkhealth vice
  • Vim: :ViceCheckHealth

Quickstart Commands

Command Description
:ViceOpen [compiler] [flags...] Open a synchronized output pane (auto-routes C/C++, Python, Java, Rust, Go, Zig; e.g. :ViceOpen clang -O2, :ViceOpen llvm-mca, :ViceOpen python-dis -O1).
:ViceCompare [A] vs [B] Open two synchronized mirrors side-by-side (defaults to -O0 vs -O3; try :ViceCompare clang -O2 vs llvm-ir -O1 or :ViceCompare python-dis -O0 vs python-dis -O1).
:ViceFlags [flags...] Update compiler flags on the current pane/session and recompile immediately.
:ViceRemarks [pattern] Toggle Clang optimization remarks (-Rpass*) as inline note diagnostics.
:ViceExplain [mnemonic] (K) Show offline opcode documentation (x86-64, ARM64, Python, JVM, WebAssembly) in a floating window / popup.
:ViceToggleHighlight Toggle color-coded source↔output line highlights (light & dark theme aware).
:ViceToggleSyntax Flip active mirror(s) between Intel and AT&T syntax and recompile immediately.
:ViceToggleDemangle Toggle symbol demangling on active mirror(s) and recompile immediately.
:ViceToggleMetrics Toggle inline per-source-line instruction-count virtual text ([N insns]).
:[range]ViceContext[!] [markdown|json] Copy selected source + exact mapped assembly/IR + flags to clipboard (+) and unnamed register ("); add ! to open in a vice://context buffer.
:ViceCompilers List detected built-in and user-configured compilers.
:ViceTrust [path] Trust a project .vice.toml or compile_commands.json by canonical path + SHA-256 hash.
:ViceClose Close the current mirror (or all mirrors for the current source buffer).

See :help vice (doc/vice.txt) for full documentation.


Standalone CLI (Scripts, CI & AI Agents)

vice-core also runs directly as a CLI (install with pipx install . or run zero-install via PYTHONPATH=src python -m vice_core):

# Emit normalized Schema v1 JSON (lines, source_to_asm, asm_to_source, diagnostics)
vice compile path/to/file.cpp --compiler clang --args "-O2" --format json --pretty

# Inspect LLVM IR from the CLI
vice compile path/to/file.cpp --compiler llvm-ir --args "-O1" --format text

# Explain any x86-64, ARM64, Python, JVM, or WebAssembly opcode offline
vice explain cmovg

# List detected compilers and targets
vice list-compilers

# Run as an MCP (Model Context Protocol) stdio server for AI coding agents
vice mcp

MCP Server Configuration (Zero Dependencies)

Point any MCP-compatible AI client (Claude Code, Cursor, Antigravity, etc.) at vice mcp:

{
  "mcpServers": {
    "vice": {
      "command": "python",
      "args": ["-m", "vice_core", "mcp"],
      "env": { "PYTHONPATH": "/path/to/vice/src" }
    }
  }
}

Exposes compile_code, compare_compilers (with label-normalized semantic diff), and list_compilers.


Adding Custom Compilers (compilers.toml)

Define custom compilers, cross-compilers, or other languages in your user-owned compilers.toml:

  • Linux / macOS: ~/.config/vice/compilers.toml
  • Windows: %APPDATA%\vice\compilers.toml
[compilers.arm64-clang]
name = "Clang ARM64 Cross"
executable = "clang++"
args = ["--target=aarch64-linux-gnu", "-S", "-g1", "-x", "c++", "-", "-o", "-"]
languages = ["cpp"]
input_mode = "stdin"
output_mode = "stdout"
parser = "gas"          # "gas" | "llvm-ir" | "passthrough"
target = "aarch64-linux-gnu"

Then run :ViceOpen arm64-clang -O2 inside Vim or Neovim!

Security & Workspace Trust

  • Custom compiler executables/templates are never loaded from repository .vice.toml files—only from your user-owned compilers.toml.
  • Repository .vice.toml flags and compile_commands.json are ignored until explicitly approved with :ViceTrust (stored by canonical path + SHA-256 hash; any change on disk automatically revokes trust).

Architecture & Development

See docs/ARCHITECTURE.md for the layered architecture and Schema v1 specification, and AGENTS.md for contributor & AI-agent guidelines.

python -m venv .venv
# Linux/macOS: source .venv/bin/activate | Windows: .\.venv\Scripts\Activate.ps1
pip install -e ".[dev]"
ruff check src tests && ruff format --check src tests && mypy src && pytest -v

(The original 2021 +python3 prototype is preserved at git tag v0.0-legacy.)


License

MIT — see LICENSE.

About

Vim Compiler Explorer

Resources

Security policy

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages