Expression builder (--edit)
--edit opens $EDITOR on a temporary copy of the file. When you save and quit, nesdit diffs the before and after versions and prints:
- A suggested invocation — the
nesditcommand you can paste into a script or CI step. - The underlying query alone — useful with
-f/--from-file. - A preview of the transformed document in the source format.
--edit always writes to stdout. It never modifies the source file.
Requirements
$EDITORmust be set (or$VISUALas a fallback, thenvi).- The terminal must be an interactive TTY.
--editrejects non-TTY invocations with a clear error.
Basic usage
nesdit opens your editor on a copy of deploy.yaml. Change replicas: 3 to replicas: 5, save, and quit.
Output:
## Suggested command:
nesdit deploy.yaml --query '.replicas = 5'
## Query:
.replicas = 5
# yaml
replicas: 5
image: nginx
Sections are separated so that grep -A1 'Suggested command' extracts the command and # yaml is a language hint for terminal syntax highlighters.
No change detected
If you quit the editor without modifying the file, nesdit exits 0 and reports:
$EDITOR not set
If $EDITOR is unset, nesdit falls back to $VISUAL, then vi. If none is available, it exits 1 with guidance:
nesdit: error: flag.invalid: $EDITOR is not set; set $EDITOR to your preferred editor or use --query for non-interactive edits
Editor exits non-zero
If your editor exits non-zero (e.g., :cq in Vim to quit without saving), nesdit treats it as a user cancel and exits 0 with a stderr notice:
Flag conflicts
--edit is an interactive authoring mode and is mutually exclusive with all other mode flags:
| Combination | Error |
|---|---|
--edit -i |
nesdit: error: flag.conflict: --edit and -i are mutually exclusive: --edit always prints to stdout; use the emitted query with -i in a second invocation |
--edit --dry-run |
nesdit: error: flag.conflict: --edit is interactive and emits its own preview; --dry-run is not compatible |
--edit --check |
nesdit: error: flag.conflict: --edit is interactive; --check is for non-interactive drift detection |
Note
-e is not a short flag for --edit. In jq, -e means --exit-status. To avoid confusing pipelines, nesdit reserves -e and rejects it with an "unknown flag" error. Always use --edit.
Workflow: build a reproducible query
- Run
nesdit --edit values.yamland make the desired change in your editor. - Copy the Suggested command from the output.
- Paste it into your Makefile, CI workflow, or script.
- On the next run, use the
-iflag to apply it in-place:
Related flags
--query— provide the query directly (non-interactive).-f/--from-file— load the query from a.jqfile.-i/--in-place— apply the generated query back to the source file.