I'm using a Python file with the following modeline at the end:
# vim: sts=4:ts=4:sw=4
If I start Vim with this file the modeline is ignored. How can I fix this? And BTW, I have nocompatible
set in my .vimrc
.
Make sure your settings are right. Do...
:verbose set modeline? modelines?
If you see either of these values returned, it's not going to work.
nomodeline modelines=0
(By adding verbose
before the set
command, you will be told what file produced that setting. Thank you, drew010)
What you need to see is this (where that 4 is anything greater than 0)
modeline Last set from /usr/share/vim/vimrc modelines=4 Last set from ~/.vim/vimrc
Note from the comments: If you have either nomodeline
or modelines=0
, you are going to need to add set
and the corresponding setting from the previous code block. (Thank you @pilat)
Do you have a line with a vim:
that is not touching any else within the last <modelines> lines of your document?
Seriously, that's all it takes.
These modelines all work...
# vim: cursorline // vim: cursorline ; vim: cursorline vim: cursorline # anything here vim: cursorline even without a valid comment vim: cursorline literally anything as long a space separates> vim: cursorline # vim: set cursorline: <-that colon is required if you use the word "set" and this comment after the colon does not affect it.
Notice that the only way to have a comment after the modeline is to use the word set
. But if you use set
, you must put a colon at the end of your settings even if you have no comment. Thank you, Amadan
And this is an important one! Are you using the word set
? (as described as the "second form" in the options doc) Take out the set
or add a colon to the end.
None of these work...
# vim: set cursorline ^^^ issue: use of the word set without a trailing colon (:) # vim:cursorline ^ issue: no space after the colon #vim: cursorline ^ issue: no space before the word vim
Have you been awake for more than 18 hours? Before you lose your mind, get some sleep. It'll still be broken tomorrow. You'll be more likely to notice the issue when you go through this list again then.
This answer used to include this claim:
Are you using the word set? (as described as the "second form" in the options doc) Well, that doesn't work in version 8, and I don't know when it stopped working. Use the "first form".
I was wrong. It was pointed out by @Amadan and I have corrected Step 3.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With