Thankfully I've had 'set nomodeline' in my config ever since I found out about this insane option.
Thankfully I've had 'set nomodeline' in my config ever since I found out about this insane option.
# vim: set fileencoding=iso-8859-1
Trivia bit: the Python interpreter understands Vim and Emacs modelines as encoding declaration for source files: https://www.python.org/dev/peps/pep-0263/#defining-the-encod...Another use case was specifying the indentation scheme for the file for weird conventions like "2 space indentation with 4-column tabs" (first level is two spaces, second level is one tab, third level is one tab plus two spaces...)
Fortunately now everything's UTF-8 and weird indentation schemes are uncommon.
Also comes in handy for working with files that have an incorrect extension, for whatever reason, or different formatting from all the other files of that type that you work with. (Per-project formatting stuff can often by solved with .dir-locals.el, but not always.)
Usually just to `set ft=zsh' to set a filetype on a file with no (or incorrect) file extensions. Which syntax highlighting and other plugins rely on to activate.
For example, I use them on a TODO.md file to set it as a `task` filetype which is a markdown-friendly todo list: https://github.com/irrationalistic/vim-tasks whereas in Github I want it to render as markdown only so I keep the file extension `.md`.
Another usecase is system/software user config files which have all sorts of file extensions (ie, `.rc` or '.conf') but use a variety of internal formatting (ie, json). These files never leave your personal machines or arrive that way, in my experience at least.
I'd imagine they'd also stick out like a sore-thumb at the bottom of most files if they were maliciously inserted but I'm sure there's some exceptions (targets who don't know what Vim modelines are).
$ cat foo.sh
#!/usr/bin/env zsh
echo $SHELL
Which most editors understand. $ file foo.sh
foo.sh: a /usr/bin/env zsh script text executable, ASCII text
$ vim --clean -c ':set filetype?' foo.sh
...
filetype=zsh
This ALSO ensures that the correct shell is invoked on your script, instead of your current or default shell. $ ./foo.sh
/usr/local/bin/zshEven when it's actual part of ZSH script I'm only using `ft=zsh` when it's a file I'm sourcing, not intended as a runnable script by itself. For example: `~/.exports` which includes my PATH and env variables, as I also import it into `.bashrc` in addition to `.zshrc`.
Moreover, they're super handy for loading the proper syntax highlighting when working with template engines (e.g. Jinja2) to produce anything other than HTML.
I'd argue the use of a modeline to convey that is poor.