Aaron Johnson wrote:
List,

How can I include vim settings in the files I'm editing? For example, if system wide I have syntax highlighting disabled but I want to enable it just for one particular file. For c code I'd like to be able to include something like this:

/*
* ?:syntax on
*/

It would have to always always be commented obviously, and the '?:' would trigger reading those lines as vim options.

Any ideas if this is somehow supported by default or how to implement it?

Thanks.




The problem with ":syntax on" is that it is global. You either enable or disable it for all files being edited in all windows.

One way to do it yet, would be to disable _all_ filetype checking for _all_ files (which would in effect disable not only syntax highlighting but filetype-plugins and filetype-related indenting too). This might or might not be what you want, but it is done with

        :filetype off

It would mean that even with

        :syntax on

in your vimrc, no syntax highlighting would happen because no files would get a nonempty 'filetype'.

Then you could set the 'syntax' option for just that file by means of a modeline, which for C source would typically be

        /* vim: set syntax=c : */

(which allows a */ comment trailer on the same line) or

        /*
         * vim: syntax=c
         */

(which doesn't) (see "help modeline") in one of the first or last 5 lines of the file. With that modeline and the global ":syntax on", that particular file would get syntax highlighting even if filetype detection is off.


Best regards,
Tony.

Reply via email to