External command editor
Edit the current Zsh command with Alt+E while preserving multiline content, bindings, and Vim cursor position.
When Alt+E is undefined in a supported keymap during initialization, the
integration binds it to open the current Zsh editing buffer in an external
editor. Save and close the editor to return the text to the prompt. The command
is not executed until you press Enter.
Both the opinionated and detached integrations expose the private
nbsp-edit-command-line widget and conditionally bind it.
Choose an editor
The editor is selected in this order:
- a nonempty
editorstyle for the:zle:edit-command-linecontext; $VISUAL;$EDITOR;vi.
The zstyle form keeps the executable and arguments as distinct array values:
zstyle :zle:edit-command-line editor nvim --clean
eval "$(nbsp init zsh)"
Both environment variables can include arguments:
export EDITOR='nvim'
eval "$(nbsp init zsh)"
Another example:
export VISUAL='nano --linenumbers'
eval "$(nbsp init zsh --detached)"
Values from VISUAL and EDITOR are split using Zsh’s lexical word parser and
quote removal rather than evaluated by another shell. The implementation then
delegates buffer editing to the current edit-command-line function, loading
Zsh’s standard
edit-command-line
implementation when that function is absent.
Buffer behavior
- Empty, single-line, and multiline commands are supported.
- Saving returns the edited text without executing it.
- The private widget returns the status from Zsh’s
edit-command-linehelper. - Existing prompt content and terminal output are not redirected or hidden.
Cursor restoration
With vi, vim, or nvim, nbsp records the editor’s final line and Unicode
character column. When the edited text returns to Zsh, the cursor is restored
to that position when the report is valid.
In a normal invocation, other editors or an invalid cursor report place the cursor at the end of the edited command.
The temporary cursor file is removed after editing, including error paths.
Existing key bindings
The integration creates nbsp-edit-command-line; it does not replace a public
edit-command-line widget supplied by the user or another plugin. It considers
the Emacs, Vi insert, and Vi command keymaps and binds Alt+E only where that
key is currently undefined-key.
Existing user and plugin bindings are left unchanged.