Here is part of my .vimrc from github .
This installs undodir (and includes it), installs backupdir and directory (used for .swp files). Note that it creates directories if they do not already exist.
" Save your backup files to a less annoying place than the current directory. " If you have .vim-backup in the current directory, it'll use that. " Otherwise it saves it to ~/.vim/backup or . if isdirectory($HOME . '/.vim/backup') == 0 :silent !mkdir -p ~/.vim/backup >/dev/null 2>&1 endif set backupdir-=. set backupdir+=. set backupdir-=~/ set backupdir^=~/.vim/backup/ set backupdir^=./.vim-backup/ set backup " Save your swap files to a less annoying place than the current directory. " If you have .vim-swap in the current directory, it'll use that. " Otherwise it saves it to ~/.vim/swap, ~/tmp or . if isdirectory($HOME . '/.vim/swap') == 0 :silent !mkdir -p ~/.vim/swap >/dev/null 2>&1 endif set directory=./.vim-swap// set directory+=~/.vim/swap// set directory+=~/tmp// set directory+=. " viminfo stores the the state of your previous editing session set viminfo+=n~/.vim/viminfo if exists("+undofile") " undofile - This allows you to use undos after exiting and restarting " This, like swap and backup files, uses .vim-undo first, then ~/.vim/undo " :help undo-persistence " This is only present in 7.3+ if isdirectory($HOME . '/.vim/undo') == 0 :silent !mkdir -p ~/.vim/undo > /dev/null 2>&1 endif set undodir=./.vim-undo// set undodir+=~/.vim/undo// set undofile endif
Hopefully he commented well enough to understand what was going on. If not, add a comment and I will fix it.
Ciao!
Update [07/16/2012]
I received an email from Rob Keane asking these questions about the backupdir section, which I wanted to answer everyone:
- It looks like you are deleting the current directory and then re-adding it. what does it do?
- What does the
^= operator do? - How does priority order in using folders work in Vim? (Like the last folder, the first one that it checks is added?)
The first thing to describe for different operators. These operators have different meanings for parameters other than the string list, so be warned!
-= removes the value from the list of strings;+= adds value to the list of lines;^= adds the value to the list of strings.
So backupdir has the following operations:
- Delete the current directory from the list.
- Add the current directory to the list (this ensures that it is checked last).
- Remove the home directory from the list (I don't like it when stuff is saved there).
- Prepare
~/.vim/backup/ . - Prepend
~/.vim-backup/ .
When Vim searches for where to save backups, it checks from the first to the last; therefore, it checks for the presence of ~/.vim-backup/ , then checks for ~/.vim/backup , then checks for the default list (with the exception of . and ~/ , which were deleted), and finally check .
You can get help on all of these in Vim using (for example) :help ^= or :help backupdir .
The Doctor What Mar 02 '12 at 5:12 2012-03-02 05:12
source share