/
using_a_remote_configuration_file.html
69 lines (53 loc) · 2.99 KB
/
using_a_remote_configuration_file.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<h3>Using a Remote Configuration Time</h3>
<h4>Problem</h4>
<p>You want to store your <tt>vimrc</tt> on a remote server, and have Vim use it
automatically.</p>
<p>For example, you regularly work on different computers and want to keep your
configuration synchronised between them.</p>
<h4>Solution</h4>
<p>Upload your <tt>vimrc</tt> to a server (such as a web server).</p>
<p>You can start Vim with the <tt>-S</tt> flag, e.g. <tt>vim -S <var>url</var></tt>.</p>
<p>This is cumbersome, though. Easier is to use the following minimal
<tt>vimrc</tt> on all of your machines:</p>
<pre><code>
runtime plugin/netrwPlugin.vim
silent source <var>url</var>
</code></pre>
<p>This acts as a bootstrap config file. Vim loads your local <tt>vimrc</tt>
first, activates the plugin needed to fetch files over the network
(<i>netrw</i>), fetches the given URL, then 'sources' it as a set of Vim
commands.</p>
<div class="warning">
<b>Warning</b>: You should only source <tt>vimrc</tt> files that you've
vetted. They should not be hosted from a shared directory unless you implicitly
trust all users with access to it.
</div>
<h4>Discussion</h4>
<p>Given how configurable Vim is, it's understandable that users want to use
their handcrafted configuration regardless of what machine they use.</p>
<p>The solution above is simple but does have some drawbacks. One is that every
time you invoke Vim the remote <tt>vimrc</tt> is downloaded again. If you
mainly use one Vim instance for long periods of time, perhaps using tabs to
manage multiple files, this may not be a problem, but if you're regularly
starting and quitting Vim instances, you may notice a lag in start-up time.
Another drawback is that if you're working on a machine without Internet
access, your configuration won't be loaded.</p>
<p>One alternative is to periodically fetch your remote <tt>vimrc</tt> and save
it as <tt>~/.vimrc</tt> <span class="todo">x-platform caveat</span>.
Unix/Linux users could do this with a <tt>wget <var>url</var> -O
<var>vimrc-path</var></tt> line in their <tt>crontab</tt>. This avoids the
startup lag, and means that if you lose Internet access Vim will use the last
<tt>vimrc</tt> it managed to download.</p>
<p>Another is to keep your configuration in a version control system, such as
Git, Subversion, Bazaar, then check out the repository on each machine you
use. This is a more complete solution which allows you to synchronise all of
your configuration files over multiple machines; not just Vim's. A VCS also
makes it easier for multiple people to contribute to the configuration, which
can be especially useful if you're working on a team.</p>
<div class="tip">
A search for <i>Vim</i> on <a href="http://github.com/">GitHub.com</a> will yield
a large selection of Vim configurations kept in version control. You can use
one as a base for your own configuration by "cloning" it to your local machine
then making changes. Having done this, you may want to host the repository on
GitHub, too, so it will be available when you work on a new machine.
</div>