Overview
In environments where users utilize a tool to securely SSH into remote systems (such as teleport), admins can often feel homesick and miss their preferred editor configs. At least for me, this was enough to try to find a workaround to get my vimrc file usable on systems without forcing every other admin to use my preferred config.
NOTE: It may be best to check if this is permitted in your environment first. While there are no immediate security concerns configuring vim to behave how you want, some companies may have stricter policies around remote systems than others.
Finding the Username
Most remote login tools have a concept of passing the caller’s username to the target system. In Teleport the username is passed as $TELEPORT_USERNAME, assuming that the teleport PAM plugin is installed.
For this example, I will use Teleport as it is fairly well adopted.
You will need to expect your environment on the remote system and determine what variable contains your username, if any. If none exist, Teleport may not be using its PAM module and therefore not passing any of your environment variables to the target. If this is the case, you may be able to discuss this with your department and see if you are able to pass this information along (there are several logging benefeits of being able to have this information available on the remote system anyways).
Once you locate the variable, we can move on to configuring vim.
Dynamic vimrc stub
We need to add a few lines to the shared user’s .vimrc file in order to configure it to load a special file per-user.
- open up the shared user’s
.vimrcfile - Add the following:
if !empty($TELEPORT_USERNAME)
let s:custom_vimrc = expand('~/.vimrc.' . $TELEPORT_USERNAME)
if filereadable(s:custom_vimrc)
execute 'source' s:custom_vimrc
else
source /usr/share/vim/vim90/defaults.vim
endif
else
source /usr/share/vim/vim90/defaults.vim
endif
NOTE: In some places we use pretty old versions of vim, your shared “default” vimrc file may be different.
- Copy your
.vimrcfile to.vimrc.ameyer(in my case)
Now when you open vim it should look for the presence of your personal vimrc file and source it automatically.