Storing vim settings with a document

Yes, vim settings can be included within the document.

They are mostly found within comments, so they don't mess up the original file. An example for tab-specific settings is:

/* ex: set tabstop=8 expandtab: */

Note that this command works in most cases, however, servers are often setup without modeline turned on for security reasons. To turn on that feature add the following in your $HOME/.vimrc or the system $VIM/vimrc:

set modeline

You can use Vim's Session support:

:mksession

you can later load this by either running vim -S Session.vim, or using source Session.vim

There are also vim addons to automate session loading/saving


You can save your settings globally by editing your .vimrc file.

Vim also lets you save settings per file by using modelines


Here's how you save all your current settings to a file:

:redir > textfile.txt 
:set all 
:redir END

If you like, just rename that file to ~/.vimrc and away you go.


You could maybe save the file as a particular type, e.g. special filename format or extension, and then define an autocommand in your .vimrc for that filetype.

I do this for my makefiles to ensure that I have the various settings I need for specific files.

For example, here's my autocommand dec.

if has("autocmd")
  autocmd BufRead,BufNewFile Makefile*  :set noexpandtab
  autocmd BufRead,BufNewFile mirror.conf    :set noexpandtab
  autocmd BufRead,BufNewFile *.html*    :set shiftwidth=2
  autocmd BufRead,BufNewFile diff_files :set autowrite
  autocmd BufRead,BufNewFile lbnamed*   :set ft=perl
  autocmd BufRead,BufNewFile *.t        :set ft=perl
endif