A Bash 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 ~/.bashrc makes interactive Bash sessions use the same choice instead of falling back to whichever program a tool selects by default.
$VISUAL is the first editor preference many terminal programs check, while $EDITOR is the fallback for programs that only honor the older variable. Export both variables to the same editor command unless a visual editor and a line editor need separate choices.
The change belongs in the Bash startup file that actually loads for the terminal session. On typical Linux desktop terminals and remote shell sessions, interactive non-login Bash shells read ~/.bashrc; Debian and Ubuntu's /usr/bin/editor alternative is separate, so change it only when a program calls the generic editor command instead of reading $VISUAL or $EDITOR.
Related: How to configure Bash login scripts
Related: Change the default editor in Linux
Related: Set the default text editor in Zsh
$ 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, emacs, micro, or another editor command that exists on the system.
$ nano ~/.bashrc
Use the Bash startup file that your terminal reads. Interactive non-login Bash shells read ~/.bashrc when the file exists.
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".
$ source ~/.bashrc
$ printf 'VISUAL=%s\nEDITOR=%s\n' "$VISUAL" "$EDITOR" VISUAL=/usr/bin/nano EDITOR=/usr/bin/nano
$ printf 'VISUAL=%s\nEDITOR=%s\n' "$VISUAL" "$EDITOR" VISUAL=/usr/bin/nano EDITOR=/usr/bin/nano
This confirms that ~/.bashrc loads the editor choice automatically in a new interactive Bash session.
$ 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 Bash variables above.