Not really a sollution for this problem, but why don't you use 'sudo -e <filename>' instead of 'sudo vi <filename>' ?
Not really a sollution for this problem, but why don't you use 'sudo -e <filename>' instead of 'sudo vi <filename>' ?