How to bring .vimrc around when I SSH?

Solution 1:

Instead of bringing .vimrc to each server you need to work on, why not edit the remote files from your local vim:

In vim/gvim, run:

:e scp://[email protected]//path/to/document

or start vim like this:

vim scp://[email protected]//path/to/document

This opens the file seamingly in place (it actually copies the file locally), and when you save, it sends the edited file back to the server for you.

It asks for an ssh password, but this can be streamlined via ssh keys.

As others have mentioned the only drawback of this method is that you don't get path/file competion as you would when working directly on the machine.

For more info, check out the following tutorial.

Solution 2:

I feel your pain. I have all my ~/.*rc files under version control (Subversion), has worked great since I started in 1998, using CVS. One way to do it, is to check out all your rc files like this when you stand in your home directory:

svn co svn+ssh://user@host/path/to/repo/trunk/home/user .
A    .signature
A    .vimrc
A    .bashrc
A    .screenrc
A    .psqlrc
Checked out revision 7645.

This way the config files will also be synced and updated across the various computers when you run svn update.

Solution 3:

You could make a bash script to copy it automatically every time you log in, like this:

#!/usr/bin/env bash

scp ~/.vimrc $1:
ssh $1

You can call it ssh_vim, for instance. It's not an ideal solution but will solve your problem.

You can improve it to check first if there is already there. If you are not always running ssh from the same machine, you could change the script to get the file from scp from another machine.


On a related note, you could also mount the remote machine's filesystem with sshfs. That way you benefit from your environment and tools (not only .vimrc) and you have shell completion (which you don't have using scp://).


I just found out that you can source your .vimrc file using scp://, like this:

:source scp://you@your_computer//yourpath/.vimrc

This works from the vim command line but at the moment I don't know how to automate it. It doesn't seem to work either with the '-u' switch nor in the .vimrc nor with $VIMINIT.


I found it! You can do this to start vim with a .vimrc taken from your host of reference:

vim -c ':source scp://you@your_computer//yourpath/.vimrc'

Option '-c' executes the command right after launching vim.

You can create an alias in your shell of choice to avoid typing. In bash it would be like this:

alias vim="vim -c ':source scp://you@your_computer//yourpath/.vimrc'"

Solution 4:

If you're using public-key authentication, you can use this in your ~/.ssh/config:

Host *
   PermitLocalCommand yes
   LocalCommand bash -c 'scp -P %p %d/.vimrc %u@%n: &>/dev/null &'

I like it better than the script trick suggested above since it doesn't mess the invocation of the ssh command (when specifying extra parameters, etc.)

Solution 5:

A couple of solutions:

1) Create an NFS share for your home folder and map it in multiple locations.

2) Create a small script to push your .vimrc to the server you are connecting to with an identity/key file. It could look something like this (pseudocode):

connectString = arg0  #username@ipaddress

scp -i ~/.ssh/indentity connectString:~/ ~/.vimrc
ssh -i ~/.ssh/indentity connectString