I have a handful of files (LaTeX documents) that have one specific proper name that is really obnoxious to type out but used frequently. I've eased the pain of this with an abbreviation like so:

iab Eİ Elçilerin İşleri

This works great, but I don't want to pollute my global vimrc with document specific hacks like this. Is there a way to set an abbrieviation in the modeline? I tried appending it as is, but modelines appear to only work with set commands.

  • iab <buffer> E...?
    – muru
    Commented Mar 14, 2015 at 8:42
  • @muru That doesn't work from a modeline.
    – Caleb
    Commented Mar 14, 2015 at 9:08
  • This specific scenario is calling for \newcommand{\EI}{Elçilerin İşleri} Commented Mar 14, 2015 at 12:04
  • @Gilles I actually started out with that, but it has a couple drawbacks. One is that it makes post-processing harder. There are a couple of scripts that keep track of what gets referenced where (that checks an API to validate the references) and doing this against the TeX source is a lot easier that having to compile it and run against the formatted output.
    – Caleb
    Commented Mar 14, 2015 at 12:36
  • Would it work to define a filetype for those files and set the filetype in the modeline?
    – Nate C-K
    Commented Oct 30, 2015 at 14:30

2 Answers 2


As it has been said, it's not possible by design.

If you want something like modelines, you'll have to write your own plugin. In the early 2000 I wrote let-modeline that decodes a slightly different format of modelines (i.e. Vim: let var=expr) to set variables.

For something more complex than a variable, I'd also use a local vimrc. However I wouldn't use .exrc that works only for files in the same directory where the .exrc file is. Plugins like local_vimrc support hierarchies of directories.


:help modeline is pretty specific about this:

No other commands than "set" are supported, for security reasons (somebody might create a Trojan horse text file with modelines). And not all options can be set. For some options a flag is set, so that when it's used the |sandbox| is effective[...]

Hint: If you would like to do something else than setting an option, you could define an autocommand that checks the file for a specific string. For example:

   au BufReadPost * if getline(1) =~ "VAR" | call SetVar() | endif

And define a function SetVar() that does something with the line containing "VAR".

If you're looking for a workaround, you could try using a local .vimrc with :set exrc. Before doing so, be sure to consider the security implications mentioned in :help 'exrc'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.