5

On my desktop I use the hbrid color scheme in vim, with the preferred colors set for my consoles 16-color palette (as described in the README).

However, on my laptop, I use the solarized color scheme, so when I SSH into my desktop from my laptop and open VIM it will look funny using the hybrid colors.

Is there any way I can 'forward' a vim configuration to set the colors when SSHing into a different machine? (Assume the colorscheme file is already installed, and all that needs to be done is call colorscheme solarized)

6

You can access environment variables in your vimrc using $NAME. ssh sets the environment variable SSH_CONNECTION within an SSH session to non-empty metadata about the connection. You can combine these two to run configuration code based on whether you're accessing vim over SSH or not:

if $SSH_CONNECTION
    colorscheme solarized
endif

The body of the if runs when SSH_CONNECTION is non-empty, so if you put this into your desktop's .vimrc then you'll get the solarized theme over SSH, and whatever you configured earlier the rest of the time.

4
  • Thanks Michael! Good solution, this works well for when I only have two color configurations. But lets say I have another machine that uses a different terminal color scheme that I want to enable when SSHing into my desktop. I see the SSH_CONNECTION identifies the client. But only the local IP. perhaps there is a way to pass some kind of identifying information with the SSH connection? Jul 15 '14 at 8:05
  • I could enable AcceptEnv in sshd on my desktop. But I was hoping to be able to use this kind of setup for other machines where I may not be able to configure /etc/ssh/sshd_config Jul 15 '14 at 8:11
  • There is a -o SendEnv=VARNAME option you can use to pass a local variable to the destination, which must be enabled on the server. Alternatively, ssh -t hostname env VAR=value bash -i will set the VAR variable and run a login shell. TERM is also passed through by default, but it takes some work to store something useful there. Jul 15 '14 at 8:13
  • Brilliant! Solves a problem that's annoyed me for a while Jun 14 '19 at 13:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.