How can I change the default editor of the sudoedit command to be vim?

Solution 1:

Run sudo update-alternatives --config editor and choose for vim. After this, sudoedit /etc/hosts should open /etc/hosts using vim.

Alternatively you can use sudo vim /etc/hosts.

Solution 2:

Try exporting the variable i.e.:

$ SUDO_EDITOR=/usr/bin/vim
$ export SUDO_EDITOR

A new shell is started when you run the command and if this variable is not exported it will not exist in the new shell.