A Zsh terminal passes exported editor variables to programs launched from that shell, so commands such as crontab -e, sudoedit, and git commit open the editor selected for that account. Setting the editor in ~/.zshrc keeps interactive Zsh sessions from falling back to a program chosen separately by each tool.
$VISUAL is the first editor preference many terminal programs check, while $EDITOR remains the fallback for tools that only honor the older variable. Export both variables to the same editor command unless a graphical editor and a terminal editor need separate choices.
Interactive Zsh reads the user's rc file after the global startup files; for a normal home-directory setup that file is ~/.zshrc. If $ZDOTDIR is set, put the same lines in $ZDOTDIR/.zshrc instead, and keep Debian or Ubuntu's /usr/bin/editor alternative separate from these shell variables.
Related: How to configure Zsh startup files
Related: Set default text editor in Bash
Related: Change the default editor in Linux
$ printf 'VISUAL=%s\nEDITOR=%s\n' "${VISUAL-}" "${EDITOR-}"
VISUAL=
EDITOR=
An empty value means no editor preference is exported from the current shell.
$ command -v nano /usr/bin/nano
Replace nano with vim, nvim, emacs, micro, or another editor command that exists on the system.
$ nano ~/.zshrc
Use $ZDOTDIR/.zshrc instead when the account sets ZDOTDIR to store Zsh startup files outside the home directory.
export VISUAL=/usr/bin/nano export EDITOR=/usr/bin/nano
If the file already assigns VISUAL or EDITOR, replace the old lines instead of leaving conflicting values later in the same file.
Quote the value when the editor command includes arguments, for example export VISUAL="code --wait".
$ zsh -n ~/.zshrc
No output from zsh -n means Zsh parsed the file without finding a syntax error. Use $ZDOTDIR/.zshrc instead when that is the file you edited.
$ source ~/.zshrc
Use source "$ZDOTDIR/.zshrc" when the startup file lives under a custom ZDOTDIR directory.
$ printf 'VISUAL=%s\nEDITOR=%s\n' "$VISUAL" "$EDITOR" VISUAL=/usr/bin/nano EDITOR=/usr/bin/nano
$ zsh -ic 'printf "VISUAL=%s\nEDITOR=%s\n" "$VISUAL" "$EDITOR"' VISUAL=/usr/bin/nano EDITOR=/usr/bin/nano
A matching output confirms that ~/.zshrc applies the editor choice to new interactive Zsh sessions.
$ crontab -e
crontab -e, sudoedit, and many other command-line tools read $VISUAL or $EDITOR when choosing which editor to launch.
On Debian and Ubuntu, sudo update-alternatives --config editor changes the generic /usr/bin/editor link. That setting is separate from the Zsh variables above.