3 min read 794 words Updated Mar 16, 2026 Created Mar 16, 2026

Inline Editing

Inline Editing is Dwight's core interaction model. Select code (or let treesitter pick the scope), choose a mode like /refactor or /test, and the AI edits your buffer in place. No context switching, no copy-pasting.


How It Works

  1. Select code — visual selection, or just place your cursor inside a function (treesitter auto-selects the enclosing scope).
  2. Invoke:DwightInvoke opens a prompt buffer. Type your instruction and reference skills with @skill-name, libraries with %lib-name, or features with $feature-name.
  3. AI generates — Dwight sends the selection, LSP context (types, diagnostics, references), and your instruction to the AI.
  4. Review — if diff_preview = true, a side-by-side diff opens before applying. Otherwise changes are applied directly.
  5. Undo — standard u for single-file changes, :DwightMultiUndo for multi-file edits.
" Visual select a function, then invoke
:'<,'>DwightInvoke

" Or use a mode directly
:'<,'>DwightMode refactor

Invoke prompt flow


Modes

Modes are pre-built instructions for common tasks. Each mode constrains the AI's scope so it stays focused.

Code Modes

ModeDescription
documentAdd idiomatic doc comments (JSDoc, docstrings, godoc, EmmyLua)
refactorImprove structure and readability, preserve behavior
optimizePerformance optimization, prefer algorithmic improvements
fixFix bugs and broken logic
securityAudit and harden: input validation, injection prevention, secrets
testGenerate tests using the project's framework
stubGenerate function signatures and type stubs (multi-file)
codeImplement stubs, TODOs, and incomplete code (multi-file)
lintAI-powered linting with severity and line numbers
macroGenerate Neovim commands and macros
explainAdd explanatory comments without modifying code

Prose Modes

ModeDescription
brainstormGenerate ideas and approaches from selected text
planCreate a structured implementation plan with @dwight:action steps
refineImprove clarity, fix grammar, make text more actionable
docsGenerate user-facing or developer documentation

Custom Modes

You can register project-specific modes in setup(). See Configuration for details.


Multi-File Output

Modes marked as multi-file (stub, code) can create, edit, or delete multiple files in one operation. The AI outputs changes in a structured XML format:

<changes>
<file path="src/auth.ts" action="create">
...file content...
</file>
<file path="src/handler.ts" action="edit" lines="15-30">
...replacement...
</file>
</changes>

Use :DwightMultiUndo to revert all files from a multi-file operation at once.


Dot-Repeat

After any inline operation, :DwightRepeat replays the same mode and instruction on a new selection. Select different code, run :DwightRepeat, and the last operation is applied to the new scope.

:'<,'>DwightMode refactor    " Refactor first function
" Select another function
:'<,'>DwightRepeat            " Same refactor on the new selection

Prompt Buffer Syntax

The prompt buffer opened by :DwightInvoke supports special tokens:

TokenExampleResolves To
@name@go-api-designSkill from .dwight/skills/
%name%htmxLibrary reference from .dwight/libs/
$name$authFeature context (files, signatures)
!model!opusOverride the model for this call
/mode/refactorApply a built-in mode

Tips

  • Let treesitter pick the scope. In normal mode, :DwightInvoke auto-selects the enclosing function/class. No need to visually select unless you want a specific range.
  • Use /lint before /fix. Lint gives you a diagnostic overview; fix acts on it. Running lint first lets you decide which issues are worth fixing.
  • Combine modes with skills. /refactor @go-api-design applies your project's conventions during the refactor instead of generic rules.
  • Enable diff preview for destructive modes. Set diff_preview = true in config, or toggle at runtime with :DwightDiffToggle.

Commands

CommandArgsDescription
:DwightInvokeOpen prompt buffer for current selection or treesitter scope
:DwightMode<mode>Apply a mode directly (tab-complete available)
:DwightRepeatReplay last operation on current selection
:DwightMultiUndoUndo last multi-file change set
:DwightCancel[all]Cancel nearest active job, or all jobs
:DwightDiffToggleToggle diff preview before applying
:DwightStreamToggleToggle streaming output
:DwightLintClearClear dwight lint diagnostics from buffer

See Also