Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
add comment

2 Answers

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
endfunction

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
add comment

Your Answer

 
discard

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