Vim Tips Wiki
Zzapper (talk | contribs)
m (Reverted edits by Emprego.curitiba (talk | block) to last version by Fritzophrenic)
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{review}}
 
 
{{TipImported
 
{{TipImported
 
|id=807
 
|id=807
Line 12: Line 11:
 
|category2=
 
|category2=
 
}}
 
}}
===Backing up vimrc===
+
==Backing up vimrc==
 
You can always easily reinstall Vim however the loss of your vimrc file could be a catastrophe!
 
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.
 
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.
A further 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
 
  +
 
==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.
   
===Commenting vimrc===
 
 
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:
 
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:
   
Line 29: Line 31:
   
 
==Comments==
 
==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.
One thing that a co-worker turn me on to is storing your home dir in cvs. That way not only can you recover from loss of files, but you can version them, and not have to worry about reconciling changes you made to a file on one machine vs changes you made on another.
 
 
It make things incredibly easy to manage and you can configure you environment on a new machine in seconds.
 
   
 
----
 
----
  +
 
You can also use folds in vimrc, which tends to do wonders for organization and readability as well.
 
You can also use folds in vimrc, which tends to do wonders for organization and readability as well.
   

Revision as of 15:01, 8 November 2011

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