Open Policy Agent (OPA) is the leading open-source engine for enforcing fine-grained, programmable policies across microservices, Kubernetes, APIs, and CI/CD pipelines. When paired with Vim, OPA lets you write, test, and iterate on Rego policies without leaving your editing flow. No switching tabs. No breaking concentration.
Why OPA in Vim
OPA policies are written in Rego, a declarative language built for evaluating structured data like JSON. Rego is powerful but strict, making real-time feedback crucial. With Vim integration, you can:
- Run
opa evalon current buffers - Validate policy syntax instantly
- Autofold and navigate complex Rego blocks with ease
- Connect to live datasets for rapid policy prototyping
This tight loop speeds up development and catches errors early. It turns policy into code you can shape as quickly as any function or config.
Setting Up OPA in Vim
Install OPA CLI from GitHub or your package manager. Add Vim plugins that support Rego syntax highlighting, such as vim-rego. Configure Vim to map keys for opa eval commands. With a few lines in .vimrc, you can trigger policy evaluation against JSON input from within your editor.
Example workflow: