4

Is it possible to have vim automatically source a file consisting of (for instance) imaps if one is editing a particular file. Not a filetype, but one particular file. Ideally, I could set imaps in modelines but this is not possible.

The context is that I am editing a long LaTeX file and rather than define innumerable \newcommands I would prefer to have vim type the TeX for me.

shigeru
  • 43
  • 3

1 Answers1

5

This can be done with autocommands in your .vimrc.

aug MyLaTeXEnvironnementForMyFile
  au!
  au BufRead /pattern/to/*/path/to/my/file :so /the/relevant/script.vim
aug END

The file loaded this way shall be written in the same way we'd write a ftplugin (buffer local mappings, commands, settings, abbreviations).

NB: I prefer to use a local .vimrc that I drop in the directory where is the file for which I have a specific environment. This way I can move my file around, or share the settings between several files very easily without having to edit my .vimrc. See also: Vim: apply settings on files in directory

Community
  • 1
  • 1
Luc Hermitte
  • 31,979
  • 7
  • 69
  • 83