Skip to main content

Vim Controller

@svendowideit/vim-controllerv2026.11.28.1· MIT· 1d agoBEHAVIORSREPORTS
01README

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-controller

DEPENDENCIES

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=true

CONFIGURE

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.

02Behaviors1
@svendowideit/vim-controllerv2026.11.28.1vim.ts

Global Arguments

ArgumentTypeDescription
vimBin?stringVim binary to run.
herdrBin?stringherdr-core binary used by `open` to host Vim in a persistent terminal.
herdrAppBin?stringHerdr app binary used by `open` to place Vim in a per-space editor tab,
editorTab?stringName of the per-space tab `open` creates for Vim.
autoOpen?booleanReopen this space's editor tab when a method needs a server that is not
serverPrefix?stringPrefix for a server name derived from the working directory.
defaultServer?stringVim server to use when a method does not name one.
defaultCwd?stringWorking directory for `open` when the method does not give one.
maxOutputBytes?numberMaximum bytes of buffer/command output retained in data.
fn servers(terminal?: string, server?: string)
List the Vim servers reachable with --serverlist.
ArgumentTypeDescription
terminal?stringThe caller's Herdr terminal id (a pane's HC_TERMINAL_ID). A method called
server?stringVim server name (`vim --servername`); empty uses defaultServer.
fn open(terminal?: string, server?: string, file?: string, cwd?: string, reuse?: boolean, place?: enum, waitMs?: number)
Start Vim with a stable --servername in a herdr-core terminal, or
ArgumentTypeDescription
terminal?stringThe caller's Herdr terminal id (a pane's HC_TERMINAL_ID). Methods called
server?stringServer name to create or reuse; empty derives one from the cwd.
file?stringFile to open in the new server.
cwd?stringWorking directory for the server.
reuse?booleanReturn an already-running server instead of failing.
place?enum`tab` starts Vim in this space's editor tab without taking focus;
waitMs?numberHow long to wait for the server to appear.
fn status(terminal?: string, server?: string)
Report the file, modified flag, line count, cursor, mode and filetype.
ArgumentTypeDescription
terminal?stringThe caller's Herdr terminal id (a pane's HC_TERMINAL_ID). A method called
server?stringVim server name (`vim --servername`); empty uses defaultServer.
fn read()
Read the whole buffer, the visible window, or the visual selection.
fn edit()
Apply exact-text or line-range edits to the buffer in one atomic
fn write()
Write the buffer; force is a separate, explicit choice.
fn cursor()
Move the cursor to a 1-indexed line and column.
fn select()
Select a visual range (1-indexed) and return the selected lines; the
fn diff()
Compare the current buffer with the file on disk and return a unified diff.
fn annotate()
Draw the agent's virtual cursor/annotation with Vim text properties;
fn command()
Execute one Ex command. Shell escapes and process-starting commands
fn expr()
Evaluate a Vimscript expression. Expressions that can mutate files or
fn keys()
Send a literal key sequence with --remote-send. Prefer the structured
fn diagnostics(terminal?: string, server?: string)
Read Vim's quickfix and location lists.
ArgumentTypeDescription
terminal?stringThe caller's Herdr terminal id (a pane's HC_TERMINAL_ID). A method called
server?stringVim server name (`vim --servername`); empty uses defaultServer.
fn undo()
Undo to a sequence recorded by an edit, or one step.
fn editFile(terminal?: string, server?: string, file: string, cwd?: string, edits: array, expectedHash?: string, force?: boolean)
Make sure this space's editor is running, load the path into its
ArgumentTypeDescription
terminal?stringThe caller's Herdr terminal id (a pane's HC_TERMINAL_ID). Methods called
server?stringServer to use; empty derives one from this space, opening the editor tab
filestringPath to load, edit and save.
cwd?stringDirectory a relative `file` resolves against; empty uses the process
editsarrayApplied to the buffer, bottom-up for line ranges; all or none.
expectedHash?stringOptional SHA-256 of the buffer the caller saw; refuse if it changed.
force?booleanReplace a buffer with unsaved changes instead of refusing (this is the
fn openFile()
Load a path into the running server so the person watching the editor
fn focus()
Show a server's editor tab to the person: focus the Herdr terminal
fn close()
Close the Vim server. force=true sends :qa!; false sends :qa and can
fn otel-status(test?: boolean)
Report whether OTLP tracing is configured, where it points, and why
ArgumentTypeDescription
test?booleanAlso post a test span and report the HTTP result.

Resources

server(infinite)— One Vim server created or adopted by this extension.
servers(infinite)— The Vim servers reachable on this host.
server-status(infinite)— File, modified flag, cursor, mode and line count.
buffer(infinite)— The whole, visible or selected buffer with line numbers.
diff-result(infinite)— The current buffer compared with the saved file.
edit-result(infinite)— One atomic buffer edit, its undo sequence and its diff.
open-file(infinite)— The path loaded into the buffer, and whether it existed.
annotation(infinite)— The agent's virtual cursor/annotation in the buffer.
diagnostics(infinite)— Vim's quickfix and location lists.
command-result(infinite)— The output of one Ex command.
expr-result(infinite)— The value of one Vimscript expression.
keys-result(infinite)— One literal key sequence sent to Vim.
write-result(infinite)— The result of writing the buffer.
close-result(infinite)— The result of closing the Vim server.
focus-result(infinite)— Whether the person was put in front of the server's editor tab.
otel-status(infinite)— Whether and where this model exports OTLP spans.
03Reports1
@svendowideit/edit-sessionmethod
vim_report.ts

Render a Vim method's edit, buffer, undo sequence, diff, diagnostics and tracing data as a reviewable summary

vimeditorsummary
04Stats
A
100 / 100
Downloads
2
Archive size
68.7 KB
  • 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
05Platforms
06Labels