On a fresh Ubuntu server, sudo visudo or crontab -e drops me in nano, and I’m a Vim person. Ubuntu decides that through the alternatives system: a set of symlinks such as /usr/bin/editor that point to one of the installed programs. You can switch the link with one command.
sudo update-alternatives --config editor
It lists every installed program that can be the editor, with a number, a priority and a * in front of the current choice. Type the number you want and press Enter. That is the whole change.
The same works for other link groups. --display shows what a group points to without changing anything, and --set does the switch without the menu, which is what you want in a setup script:
update-alternatives --display editor
sudo update-alternatives --set editor /usr/bin/vim.basic
Once you pick something by hand, the group goes from automatic to manual mode. In automatic mode, installing a package with a higher priority can move the link; in manual mode apt leaves your choice alone. To hand the decision back, run sudo update-alternatives --auto editor.
The caveat is that this is only the system default. Programs that use sensible-editor look at $VISUAL and $EDITOR first, then at the choice you made with select-editor, and only after that at the editor link. So if an export EDITOR=nano sits in your .bashrc, that still wins for your user. And the link group must exist: --config on a name the system doesn’t know just tells you there is no alternative for it.
Further reading: update-alternatives manual page (Ubuntu), sensible-editor manual page (Ubuntu)