Vim: Sudo Edit Breaks Apache Syntax Highlighting

Sudo Edit (sudo -e) allows unprivileged users to edit files safely. To do this, he creates a temporary copy of the file for editing, and then copies it when editing.

When I edit the apache file (e.g. / etc / apache2 / sites-enabled / mysite.com), sudoedit vim cannot understand that it should use Apache syntax highlighting, so I need to manually: set the syntax = apache. I suspect that the Vim rule for syntax highlighting depends on the full path to the file, and since sudoedit changes the file to something like /var/tmp/mysiteRANDOMCHARS.com, it loses this path information.

Is there a way to automatically tell Vim that it should use apache syntax highlighting?

Thanks!

+4
source share
2 answers

This sounds like one of the rare uses for the vi model:

In .vimrc :

 set modeline 

And in your Apache configuration file, somewhere above or below:

 # vi: syntax=apache 
+2
source

See /usr/share/vim/vim7x/filetype.vim how Vim determines that the file is apache .

In my configuration, using $ vim or $ sudo -e does not matter, because the .com extension is considered dcl .

I do not see a smart and reliable workaround that, in addition to overriding the .com auto command in your ~/.vimrc :

 au BufNewFile,BufRead *.com set ft=apache 
+2
source

Source: https://habr.com/ru/post/1480856/


All Articles