Vim Controller
Security Notice
This extension includes executable binaries. They run with your user permissions. Review each binary before installing.
- swamp_vim.vim
Control the Vim buffer a human is watching: read the buffer, replace exact text or line ranges atomically, move the cursor, draw a virtual agent cursor, and read quickfix — without spawning sed or cat. WHAT IT DOES
Vim is already a programmable editor when it is started with
--servername: --remote-expr can read lines, replace a buffer, move the
cursor, draw text properties and read quickfix. This extension wraps that
surface as swamp methods: servers, open, status, read, edit,
write, cursor, annotate, command, expr, keys, diagnostics,
undo, openFile, focus and close. editFile loads a path, edits and saves it through that same buffer, so
every text write is visible where the person is looking; openFile loads any path into the
editor the person is already watching, so an agent's file changes land in the
same visible buffer every time. open places Vim in one visible editor tab per
Herdr space, created the first time that space needs it and without taking
focus from the person; focus shows that tab when asked. edit applies exact-text or
line-range changes in one call, rejects an ambiguous match before touching
the buffer, returns the undo sequence and a unified diff, and never leaves
a half-applied edit. annotate uses Vim text properties for a virtual
cursor, so the human keeps the real one. Prefer it to sed -i or a
terminal-scraping wrapper when you want the change to happen in the editor
the person is already looking at. Every method can emit one OTLP/HTTP span
with swamp.route=vim, resolved from @svendowideit/otel-settings when
that contract is configured, then from the standard OTEL environment. Each
method also appends one JSONL event for the Herdr activity panel, which
shows routed vs bypassed tool calls live.
INSTALL
swamp extension pull @svendowideit/vim-controllerDEPENDENCIES
Vim 9 with +clientserver, +channel, +textprop and +quickfix, and an
X11 display (XWayland is fine). open also needs the herdr-core binary
(or its hc alias) to host the terminal; an existing Vim started with
--servername works without herdr-core. Optional:
@svendowideit/otel-settings for automatic OTLP endpoint discovery.
RUN
# See which Vim servers exist, then open one in this space's editor tab.
# The tab is created once per space, without taking focus, so the person
# keeps looking at the tab they chose.
swamp behavior run vim servers
swamp behavior run vim open \
--input file=src/index.ts --input cwd=$PWD
# Every method reopens this space's editor tab when its Vim is gone, so a
# tab the person closed comes back on the next read or edit. `focus` shows
# it when they should watch, and `status` reports where it is.
swamp behavior run vim focus \
--input server=swamp-vim-swamp-project
swamp behavior run vim status \
--input server=swamp-vim-swamp-project
# Read what the human sees, then replace one exact sentence. The edit
# is rejected if the text is missing or occurs more than once.
swamp behavior run vim read \
--input server=swamp-demo --input mode=visible
swamp behavior run vim edit \
--input server=swamp-demo \
--input 'edits:json=[{"old":"old sentence","new":"new sentence"}]'
# Show where the agent is looking without moving the human's cursor.
swamp behavior run vim annotate \
--input server=swamp-demo \
--input line=12 --input text="▶ agent"
# Read Vim's quickfix list, or run one Ex command.
swamp behavior run vim diagnostics \
--input server=swamp-demo
swamp behavior run vim command \
--input server=swamp-demo --input command="set number"
# Check whether tracing is live, then post one test span.
swamp behavior run vim otel-status
swamp behavior run vim otel-status \
--input test=trueCONFIGURE
Global arguments, set on the model definition:
vimBin Vim binary (vim)
herdrBin herdr-core binary used by `open` (herdr-core)
herdrAppBin herdr-app binary used to place the tab (herdr-app)
autoOpen reopen the editor tab when a method (true)
needs a Vim that is not running
editorTab name of the per-space editor tab (Edit)
serverPrefix prefix for a space/cwd-derived server (swamp-vim)
defaultServer server used when a method names none (empty)
open.place tab (default) or background terminal (tab)
defaultCwd cwd for `open` when the method gives none (empty)
maxOutputBytes retained buffer/command output (200000)
otelEnabled export OTLP spans (true)
otelModel otel-settings model name (otel)
otelVaultName vault holding the OTLP bearer token (empty)
otelTokenRef vault/env key for the token (OTEL_EXPORTER_OTLP_TOKEN)
otelEndpoint explicit OTLP/HTTP traces endpoint (empty)
otelMesh preferred contract mesh (empty)
otelServiceName service.name for spans (swamp-vim)
otelTimeoutMs maximum time for one span POST (2500)
otelDebug log the resolved endpoint and errors (false)
eventLogEnabled append JSONL activity events (true)
eventLog activity log for the Herdr panel (~/.local/state/swamp-agent-ide/events.jsonl) Per-call arguments are documented by swamp behavior type describe @svendowideit/vim --json.
WHAT IT INSTALLS
No services, cron triggers, daemons or webhooks. It runs the existing vim,
herdr-core and herdr-app binaries, sources the bundled swamp_vim.vim
runtime into a Vim server, and writes swamp resources. In a Herdr window it
also creates one tab per space named by editorTab, which is visible UI
state the person can close; close closes that tab again when nothing else
is in it. It never edits .vimrc or any other Vim configuration.
Global Arguments
| Argument | Type | Description |
|---|---|---|
| vimBin? | string | Vim binary to run. |
| herdrBin? | string | herdr-core binary used by `open` to host Vim in a persistent terminal. |
| herdrAppBin? | string | Herdr app binary used by `open` to place Vim in a per-space editor tab, |
| editorTab? | string | Name of the per-space tab `open` creates for Vim. |
| autoOpen? | boolean | Reopen this space's editor tab when a method needs a server that is not |
| serverPrefix? | string | Prefix for a server name derived from the working directory. |
| defaultServer? | string | Vim server to use when a method does not name one. |
| defaultCwd? | string | Working directory for `open` when the method does not give one. |
| maxOutputBytes? | number | Maximum bytes of buffer/command output retained in data. |
| Argument | Type | Description |
|---|---|---|
| terminal? | string | The caller's Herdr terminal id (a pane's HC_TERMINAL_ID). A method called |
| server? | string | Vim server name (`vim --servername`); empty uses defaultServer. |
| Argument | Type | Description |
|---|---|---|
| terminal? | string | The caller's Herdr terminal id (a pane's HC_TERMINAL_ID). Methods called |
| server? | string | Server name to create or reuse; empty derives one from the cwd. |
| file? | string | File to open in the new server. |
| cwd? | string | Working directory for the server. |
| reuse? | boolean | Return an already-running server instead of failing. |
| place? | enum | `tab` starts Vim in this space's editor tab without taking focus; |
| waitMs? | number | How long to wait for the server to appear. |
| Argument | Type | Description |
|---|---|---|
| terminal? | string | The caller's Herdr terminal id (a pane's HC_TERMINAL_ID). A method called |
| server? | string | Vim server name (`vim --servername`); empty uses defaultServer. |
| Argument | Type | Description |
|---|---|---|
| terminal? | string | The caller's Herdr terminal id (a pane's HC_TERMINAL_ID). A method called |
| server? | string | Vim server name (`vim --servername`); empty uses defaultServer. |
| Argument | Type | Description |
|---|---|---|
| terminal? | string | The caller's Herdr terminal id (a pane's HC_TERMINAL_ID). Methods called |
| server? | string | Server to use; empty derives one from this space, opening the editor tab |
| file | string | Path to load, edit and save. |
| cwd? | string | Directory a relative `file` resolves against; empty uses the process |
| edits | array | Applied to the buffer, bottom-up for line ranges; all or none. |
| expectedHash? | string | Optional SHA-256 of the buffer the caller saw; refuse if it changed. |
| force? | boolean | Replace a buffer with unsaved changes instead of refusing (this is the |
| Argument | Type | Description |
|---|---|---|
| test? | boolean | Also post a test span and report the HTTP result. |
Resources
Render a Vim method's edit, buffer, undo sequence, diff, diagnostics and tracing data as a reviewable summary
- Has README or module doc2/2earned
- README has a code example1/1earned
- README is substantive1/1earned
- Most symbols documented1/1earned
- No slow types (deprecated)1/1earned
- Dependencies pass trust audit2/2earned
- Docs keep secrets in a vault1/1earned
- Has description1/1earned
- Platform support declared (or universal)2/2earned
- License2/2earned
- Verified public repository2/2earned