Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I frequently use :ab to save typing time during coding. For e.g. :ab mat matrix to replace mat by matrix every time I type mat.

Is there any way of storing and loading the abbreviations I create for a given file? I want something to store my abbreviations as and when I declare them and also reload them when I open a file. I would prefer the abbreviations to be "local" to a file rather than global but I can work around this if necessary.

share|improve this question
up vote 1 down vote accepted

If it's for a single specific file, you could add an autocommand (:help autocommand or :help 40.3) to your .vimrc:

au BufRead,BufNewFile /path/to/foobar call FoobarSettings()
function FoobarSettings()
  ab mat matrix
  " ... more setup commands

Change "foobar" to something that makes more sense for you.

A less flexible clunkier shotgun-style approach is to use sessions (:help sessions or :help 21.4). It is unwieldy because sessions by default save a great deal of things including window sizes, open files, options, mappings, folds, etc. You can change this with the 'sessionoptions' option if you like.

  • After you've created opened the file and set up the abbreviations, :mksession! sessionfile.vim.
  • To restore the session, from the shell you can do vim -S sessionfile.vim or from inside vim you can do :source sessionfile.vim.
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.