Vim abbreviations for a specific file

Recently I came across Bram Moolenaar’s article Vim: Seven habits of effective text editing and learnt about vim abbreviations. Essentially, vim abbreviations allow you to specify shortform words that vim will automatically expand to their long form. For instance, with the following in your vimrc:

ab dev developer

Whenever you type the word dev followed by a space / enter / punctuation mark, vim will automatically expand it to developer. I am not entirely certain of the rule that vim uses to expand the abbreviation, but it seems to me that vim does it on a word boundary basis. Hence you do not have to be afraid that you cannot type devops for fear that it will be expanded to developerops.

This is pretty useful and can save a lot of typing. There are other pieces of wisdom in the article and I highly encourage you to read it.

How to have file specific vim abbreviations

Which brings us to the meat of this post. How do we have abbreviations that apply to a specific file? Some Googling led to this Unix & Linux Stack Exchange answer and here’s some example code on how to do it: