How do you override vim options via comments in a python source code file?


Question

I would like to set some vim options in one file in the comments section.

For example, I would like to set this option in one file

set syntax=python

The file does not have a .py extension and I am not interested in making my vim installation recognise all files with this extension as python files.

I know this can be done because I have seen it, but my googling for this has not yet been fruitful.

1
25
12/17/2008 9:37:46 PM

Accepted Answer

You're wanting a modeline syntax, e.g.

# vim: set syntax=python:

See: Modeline magic at Vim Wikia for more details.

32
5/25/2017 1:49:42 PM

I haven't used vim much, but I think what you want is to add a line like the following to the end of your file:

# vim: set syntax=python:

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon