55

I am not a very orderly person at times and I often find myself in the situation of losing my old fully tweaked vimrc file and having to start over all again. Or having different versions of vimrc files on different clients. Since this mess is getting out of hand for me, I would like to know if there is a good way of managing my vimrc file.

My first initiative is put my _vimrc on subversion (Google Code) and I intend to maintain it. Other ideas are welcome.

Update

I settled with the following solution:

  • Upload the .vimrc and .gvimrc to an online code repository in a directory called Vim. Use filename _vimrc and _gvimrc so that they aren't hidden, and for compatibility with Windows.

  • Checkout the repository on the target system

  • On Mac OSX/Linux create symbolic links:

    ~ $ ln -s my_repository/Vim/_vimrc $HOME/.vimrc

    ~ $ ln -s my_repository/Vim/_gvimrc $HOME/.gvimrc

  • On Windows I checkout the Vim folder over the one in the Program Files directory. SVN complains about already existing files there, but you can add those to the ignore list.

StackedCrooked
  • 34,653
  • 44
  • 154
  • 278

8 Answers8

88

I use Dropbox. I've created a folder vim in my dropbox, which contains my .vimrc (actually: vimrc.vim) and colors, plugin, etc. directories.

Dropbox pushes all these files to all my computers (home, work, laptop, Bootcamp), so every time I want to change my vimrc, I can do so and I don't have to worry about copying it to the correct directory or checking out the file from SVN or anything. Everything happens automagically!

My actual .vimrc contains only what's necessary to load the stuff I have in my Dropbox. On OSX and Linux, it looks like this:

set runtimepath^=~/Dropbox/vim
source ~/Dropbox/vim/vimrc.vim

On Windows, like this:

set runtimepath^=$HOME/My\ Documents/My\ Dropbox/vim
source $HOME\My Documents\My Dropbox\vim\vimrc.vim

And that's it!

(Actually, I put the vimrc's above in my Dropbox as well, so I don't have to remember them whenever I set up a new computer or re-install an old one.)

The free version of Dropbox will give you a 30 day revision history, the paid one will give you full revision history. Note that if you're on Linux, it's easiest if you use GNOME, for which Dropbox has a nice client.

Conditional Settings

If you have slight configuration changes you would like to use on different machines this is a handy solution:

create a small function in each of your .vimrc files to return the type of system you are on:

fun! MySys()
    return 'linux'
endfun 

then in your global vimrc.vim file:

if MySys() == "linux"
    set backupdir=./.backup,/tmp
    set directory=./.backup,/tmp 
elseif MySys() == "windows"
    set backupdir=$HOME/AppData/Local/backup,$HOME/AppData/Local/tmp
    set directory=$HOME/AppData/Local/backup,$HOME/AppData/Local/tmp
endif

Dropbox Alternatives

There are many cloud storage and syncing services, Dropbox is just one example. OpenSource services such as http://sparkleshare.org/ and http://one.ubuntu.com exist, but you are encouraged to search the internet for a solution that will fit your needs best.

jqno
  • 15,133
  • 7
  • 57
  • 84
  • 11
    I voted this up not because it recommends using dropbox, which I am not such a fan of. I voted it up because of the handy examples of how to use set runtimepath and source to load up external vim and vimrcs. – Apreche Aug 03 '09 at 14:39
  • Out of curiosity only, why do you set a backup *and* a temp? – orolo Sep 01 '11 at 13:45
  • I dunno; @timemachine3030 added that part to my answer. I suppose he does it to be able to fall back on something (tmp) if backup doesn't exist on the system you happen to be on. – jqno Sep 02 '11 at 06:56
  • That snippet is explained in more detail on the [vim wikia page](http://vim.wikia.com/wiki/Remove_swap_and_backup_files_from_your_working_directory) – timemachine3030 Sep 07 '11 at 15:57
  • 5
    You can achieve the conditional settings without adding system specific code - you can test for has('win32') to catch the windows variation and then your're left with everything else. Here's an example: https://gist.github.com/1492157 – jmohr Dec 18 '11 at 02:31
  • @jmohr +1. Why haven't I thought of that myself :)? – jqno Dec 18 '11 at 21:18
  • 1
    On Linux, Dropbox integrates nicely with Nautilus. You don't need GNOME, it's just that this file manager and desktop environment usually go together. – Samuel Tan Dec 23 '11 at 04:21
  • 1
    Whenever I have problem configuring Vim with dropbox on next computer google directs me to this posts and it always helps. If I could upvote it many times I would do it. Thanks! – Piotr Perak Oct 21 '12 at 07:17
  • a event better option to my mind is create a symlink to your Dropbox folder. Instead of a config as described, you have symlink. ln -s ~/.vimrc ~/Dropbox/.vimrc – Uku Loskit Nov 08 '12 at 13:40
  • @Uku That has 2 disadvantages: doesn't work on Windows (may not be an issue though), and doesn't work with plugins etc unless you also symlink `.vim/`. – jqno Nov 08 '12 at 14:49
  • 1
    You can use e.g. `has('win32')` and `has('unix')` to determine which type of system you are on (and you can use `hostname()` to check which specific machine you are on). Also it's often better to prepend 'rtp' with your personal runtime folder so that your files override system-wide defaults (e.g. `:set rtp^=/path/to/my/vimfolder`). – 1983 Jul 04 '13 at 22:42
  • I didn't know about the `^=` syntax. Pretty nice! I'll update my answer (and my scripts) right away :). – jqno Jul 05 '13 at 06:42
  • Attention with this solution: Don't forget to update/modify the location of `~/.vim/after` at the end of rtp. This drove me crazy with jedi-vim. When switching to python buffer, jedi-vim settings are loaded. But then the system wide ftplugin messes up all settings and due to the missing/wrong path the ftplugin located in `bundle/jedi-vim/after/` is ignored. – user334287 Mar 16 '14 at 06:10
  • How do you proceed with line ending from win in linux? e.g. when the config file is edited in win, the carriage return is added (^M), then the config file can't work in linux – lkurylo Jun 22 '14 at 11:56
  • To be honest, it doesn't come up for me very often. I do have some `if has("unix")` and `if has("win32")` blocks in my `vimrc` though to deal with such issues. – jqno Jun 24 '14 at 09:42
20

I put these files in a source control system, subversion specifically, but it doesn't matter which. That gives me a history of all such configuration files, and it's just a matter of checking out the config file when I want the same one on a new/other machine or useraccount.

nos
  • 223,662
  • 58
  • 417
  • 506
  • 1
    This is exactly what I do. Upvoted. (I also keep my Vim plugins in the same repo as my .vimrc) – skinp Jul 27 '09 at 07:08
14

Use git. I have my .vim and .vimrc files in a git repo, and I branch them for different systems. So i have on branch for lappy, one branch for debian-based , one for RH based etc.

I fire the repos up onto all my servers, and merge changes around as I see fit. Then, when i lose one, any of the others will serve. .vim/.vimrc are an excellent examples of files that should be in a DVCS.

chiggsy
  • 8,153
  • 5
  • 33
  • 43
  • 4
    Why are you saying "use git" and not simply "use your favorite revision control system"? Is there some advantage to git over, say cvs, svn, Perforce...? – StackedCrooked Jun 25 '09 at 19:22
  • 5
    Why branch them for different systems? That just seems like a pain when you want to make common changes that might not merge especially well down the road after you've made hugely divergent changes. You can test the system in your .vimrc and put all your settings in one, which is far handier when going to a new system, since you only have to bring along one .vimrc that will probably work. (And even better than testing system is testing capabilities) – Nick Bastin Jul 26 '09 at 16:01
4

What works best for me is to put the following in my .vimrc file:

set nocompatible
let $localcloudpath = $MYVIMRC . '_cloud'
let $cloudurl = '!curl https://bitbucket.org/<USERNAME>/vimrc/raw/master/global -o '. $localcloudpath
silent execute $cloudurl
source $localcloudpath

This way, every time I run vim, it downloads and uses the latest .vimrc file from my BitBucket repository. It will use the last downloaded .vimrc if connection to the internet doesn't exist.

The only requirement (apart from an active internet connection) is you need CURL installed.


If you don't want to download the latest .vimrc every time, then just comment out the curl line:

" let $cloudurl = '!curl https://bitbucket.org/<USERNAME>/vimrc/raw/master/global -o '. $localcloudpath

BitBucket is also a personal preference because I can easily edit the file online without having to commit anything but you can host your .vimrc file anywhere with a publicly accessible URL (Dropbox, Google Drive, GitHub, etc.)


UPDATE (16/10/2017)

Using the below updated curl command will always get fresh .vimrc from bitbucket. It will also timeout and use the last downloaded .vimrc_cloud if you are offline or on a slow connection.

let $cloudurl = '!curl -H "Cache-Control: no-cache" --max-time 10 https://bitbucket.org/<USERNAME>/vimrc/raw/master/global -o '. $localcloudpath
FanManPro
  • 1,076
  • 1
  • 13
  • 31
3

Like others have said: use a version control system.

Here is such a project, easy to fork and extend: http://github.com/ryanb/dotfiles

It does not only handle vim.rc, but all kind of configuration and comes with a setup script.

blueyed
  • 27,102
  • 4
  • 75
  • 71
2


There is also a very nice way to install plugins using Version Control, Since most of the VIM plugin are available on GITHUB it also help. Please see this Article which tells you how to keep your .VIM file synchronized using GIT, and load plugin as a sub module with the help of PATHOGEN plugin.

Use GIT for Syncing VI plugins

In short of what is mentioned in the vimcast and i am quoting from the Blog.

  1. Keep your dotfiles in git
  2. Install plugins as submodules using this commands
    git submodule add http://github.com/tpope/vim-fugitive.git bundle/fugitive
1

If you are using vundle you can do it this way. Git keeps vimrc and all other settings in sync and vundle keeps track of your plugins/scripts.

Synchronizing vim with vundle and git

Srinivas
  • 727
  • 4
  • 14
0

I keep a copy of my dot-files on google docs.

Nifle
  • 11,745
  • 10
  • 75
  • 100