sudo vim /etc/hosts runs the whole editor, with all its plugins and shell escapes, as root. sudoedit takes a safer route and also keeps your own editor setup.
sudoedit /etc/ssh/sshd_config
The sudo man page explains what happens. sudo makes a temporary copy of the file, owned by you, and opens it in your editor with your environment unchanged. When you save and quit, the copy is written back over the original, but only if you changed something. So your editor runs without root, and your .vimrc or nano settings just work.
The editor is taken from SUDO_EDITOR, then VISUAL, then EDITOR, in that order. To pick one for this purpose only:
export SUDO_EDITOR=nano
It also fits nicely with a limited sudo rule. A sudoers line can allow sudoedit /etc/nginx/sites-available/* for a user, without giving them a root shell, which they would get with sudo vim through a shell escape.
I like that it has some deliberate limits. It refuses to edit a symbolic link, and it refuses files in a folder that you can write to yourself, because both could be used to trick root into overwriting something else. Since the original is only replaced when you save, a program that reads the file in the meantime sees the old version, which is usually what you want. Do check the syntax afterwards, for example with sshd -t, before you reload the service.
Further reading: sudoedit(8) manual page