문제

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

다른 팁

See /usr/share/vim/vim7x/filetype.vim for how Vim determines that a file is an apache file.

In my config, using $ vim or $ sudo -e makes no difference as the .com extension is treated as dcl anyway.

I don't see a smart and solid way to workaround that beside overriding the .com autocommand in your ~/.vimrc:

au BufNewFile,BufRead *.com set ft=apache
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top