You are not logged in.
I'm referring to a line in a file s/a
# vim: ft=sh ts=4 et sw=4:I have that line at the bottom of a .bashrc file. When I open it with vim as a regular user, the settings are applied. When I open it with vim as root (logged in as root; no sudo involved) on the same machine, the settings are ignored. Any ideas as to why this is, or how to fix it?
Both reguser and root have identical .vimrc and .vim folders. If I remove both users' .vimrc, reguser still applies the settings and root still ignores them. I also tried starting vim with full path to rule out any user env. weirdness, no change.
Last edited by alphaniner (2013-08-23 18:10:45)
But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner
Offline
Hi,
Vim disables modelines for root per default. You need to have a
set modelinein your vimrc to enable them for root as well.
I do recommend a different approach, though. Vim is actually pretty good at recognizing file types. You can use something like this in your vimrc:
autocmd FileType python setlocal et sta ts=4 sw=4No need to go through the trouble of modelines.
Offline
I do recommend a different approach, though. Vim is actually pretty good at recognizing file types. You can use something like this in your vimrc:
autocmd FileType python setlocal et sta ts=4 sw=4No need to go through the trouble of modelines.
Vim is reasonably good at recognizing file types, but not always. Especially if we are not using a proper extension, or custom extensions. So modelines are useful in such cases.
For example, try renaming .bashrc to .bashrc.py and see the difference ![]()
Offline
X33a, I think that's a bit over stated. .bashrc.py fails because vim has essentially be "lied" to with the py extension. If you rename bashrc to "nosuchfile" it works fine as vim reads the shebang.
File specific modelines are quite handy at times, but there certainly shouldn't be a need to specify "ft=sh" in a modeline of bashrc, it is already recognized as such.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
X33a, I think that's a bit over stated. .bashrc.py fails because vim has essentially be "lied" to with the py extension. If you rename bashrc to "nosuchfile" it works fine as vim reads the shebang.
That was a quick example ![]()
But my point about custom extensions remains. Custom extensions I use tend to be categorised as "conf".
Offline
Thanks for all the input and for pointing out it's called a modeline. Not knowing what it's called made it difficult to research.
In the case I cited, I added the modeline just as an experiment. I copied it verbatim from /usr/lib/network/network because I didn't understand it enough to be sure I could just remove ft=sh .
Vim is reasonably good at recognizing file types, but not always. ...
I remove all comments from a lot of config files. Thus I've also found that vim considers the following (my linux.preset) to have no ft:
ALL_config="/etc/mkinitcpio.conf"
ALL_kver="/boot/vmlinuz-linux"
PRESETS=('default')
default_image="/boot/caddywhompus.img"But if I add a new line to the top with just a '#', vim suddenly recognizes it as ft=conf.
File specific modelines are quite handy at times, but there certainly shouldn't be a need to specify "ft=sh" in a modeline of bashrc, it is already recognized as such.
Completely unrelated to my experiment with the modeline, but when I back up that .bashrc as root-bashrc it's recognized as ft=conf .
Last edited by alphaniner (2013-08-23 18:19:23)
But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner
Offline