Wikia

Vim Tips Wiki

Backing up and commenting vimrc

Talk0
1,612pages on
this wiki
Revision as of 15:01, November 8, 2011 by Chrisbra (Talk | contribs)

Tip 807 Printable Monobook Previous Next

created October 22, 2004 · complexity basic · author zzapper · version 5.7


Backing up vimrc

You can always easily reinstall Vim however the loss of your vimrc file could be a catastrophe!

So remember to back it up in several places. One good place would be to store it as say vimrc.txt, on your free webspace then you can recover it from anywhere. Make sure there is no confidential data in your .vimrc of course.

A more robust method is to version control your .vimrc file and .vim folder. There are many version control systems available, including centralized systems like SVN or CVS, however for config files like the .vimrc and installed plugins, a distributed version control software (DVCS) like git or Mercurial makes more sense, so that you are not required to set up/communicate with a server. With this method the real .vimrc file and .vim folders are part of a version control repository, and you create symbolic links to them if needed.

One of the benefits of using version control system instead of just backups, is the ease of sharing the same configuration between several computers, and syncing changes. If desired, you can push to a DVCS hosting service like github or BitBucket, but you could just as easily share DVCS repositories using email, flash drives, and the like.

Commenting vimrc

A further (unrelated) tip is to store as a comment (vi(m) comments begin with a ") a few notes on how you configure FireFox, Cygwin etc for Vim, as these details are easy to forget.

My vimrc now has 348 lines, but about 50% is deadwood because it's no longer clear to me what it's supposed to do. Wish I'd thought of this tip years ago! In vimrc you use the double quote as a comment, for example:

" open search result in a new window (the comment)
map zm :let @/=expand("<cword>") <BAR> split <BAR> execute 'normal n'<CR>

Comments

The two topics in this tip (and the suggestions below) are unrelated. Perhaps we should split this tip into multiple at some point, or maybe there's a merge target. Or it could become a collection of tips for organizing/maintaining your Vim config.


You can also use folds in vimrc, which tends to do wonders for organization and readability as well.


In your vimrc you can read an environment variable to allow different command depending on which OS or PC you're on and thus have same vimrc.

if $USER == 'davidr'
echo "on home pc"
set .. etc
else
echo "on work pc"
set .. etc
endif

Around Wikia's network

Random Wiki