Vim tip: Platform specific settings in your vimrc

If you use Vim on multiple platforms like I do, you may find it convenient to know that you can detect the platform your installation Vim was compiled for in Vimscript. With this functionality you can put all your settings for all your systems in a single vimrc file. Below is a part of my vimrc file, when in Windows I have a different backup and temp dir for Vim than I have in Linux and UNIX. Additionally I use PuTTY’s SCP and SFTP executables (as Windows doesn’t have such commands available).

if has('win16') || has('win32') || has('win64') || has('win95')
  " Windows specific settings
  " Backup and swap file directories
  set bdir=~/vimbackups
  set dir=~/Temp
  " Use PuTTY SSH programs (Must be installed separately)
  let g:netrw_scp_cmd = 'pscp.exe -q -batch -agent'
  let g:netrw_sftp_cmd= 'psftp.exe'
  " When using SCP ensure that you don't get prompting DOS windows
  let g:netrw_silent= 1
  " *nix specific settings
  " Backup and swap file directories
  set bdir=~/.vimbackups
  set dir=~/.vimtmp

Happy Vimming!

%d bloggers like this: