Sudo Edit (sudo -e) allows unprivileged users to edit files securely. To achieve this, it makes a temporary copy of a file to edit and then copies it over when editing is done.
When I'm editing an apache file (eg, /etc/apache2/sites-enabled/mysite.com), sudoedit vim can't figure out that it should use Apache syntax highlighting, so I have to manually :set syntax=apache. I suspect that Vim's rule for syntax highlighting relies on the full path of the file, and since sudoedit changes the file to something like /var/tmp/mysiteRANDOMCHARS.com, it loses that path information.
Is there any way for me to automatically tell Vim that it should use apache syntax highlighting?
Thanks!
This sounds like one of the rare use-cases for the vi modeline feature:
In your .vimrc
:
set modeline
And in your Apache config file, somewhere at the top or the bottom:
# vi: syntax=apache