Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to share vim configuration between cygwin-vim and windows-gvim and launch it

I am trying to setup my cygwin environment. Since I am a vim user, I want to use it easily on cygwin and windows.

Sharing vim configuration

My first concern is to share the configuration (.vimrc/_vimrc and .vim/_vimfiles) between the two of them. Indeed, I am recently hosting my vim config on github and trying to get my plugins updated thru github too.

So I made some googling to find the best way to do it but I failed to find a 'good solution' (not easy to define though...). Anyway, lots of people seems to agree on the fact that it is best to use windows-gvim rather than cygwin-gvim (I failed to use cygwin-gvim propably because of X issues but I didn't wanted to look further). So first question : is it true?!

Then I tried to find some solutions based on windows-gvim. At the moment, I have linked the win env. in the cyg env.:

.vim -> /cygdrive/d/Program Files/Vim/vimfiles/
.vimrc -> /cygdrive/d/Program Files/Vim/_vimrc

But when I open gvim from cygwin it fails. I think that win-gvim can't read cygwin's simlinks.

I tried to link the vimfiles directory (so win side) but them win-gvim can't find anything too! What I don't understand here is why win-gvim launched from cygwin looks at the files from my cygwin home dir?!

I read it is possible to declare a HOME variable in windows to help win-vim, but I fear it can have side effects...

That's it for the config the config... Does somebody has a solution?

Launching vim

Also, to launch gvim I use an alias to a function that translates cigpaths in winpaths:

winfilepath () {
  # Extract command
  cmd="$1"
  shift
  # Computes file paths
  allfiles=""
  if [[ ! -z "$@" ]]; then
    while read f
    do
      newpath=`cygpath -w $f`
      allfiles="$allfiles $newpath"
    done < <(echo "$@" )
  fi

  # Launch command
  echo "winfilepath: "$cmd $allfiles
  $cmd $allfiles
}

alias gvim="winfilepath gvim \"$@\""
alias gvimdiff="winfilepath gvimdiff \"$@\""

# Open Windows explorer with file
alias winopen="winfilepath \"explorer.exe /select,\" \"$@\""

Is it a good pratice?

Thank you for your help :)

Plouff

like image 657
Plouff Avatar asked Aug 14 '11 13:08

Plouff


2 Answers

I keep my dotfiles in Dropbox. The folder is C:\Dropbox\dotfiles. In order to use them between windows and cygwin, here's what I do:

Cygwin side:

~ $ ln -s /cygdrive/c/Dropbox/dotfiles/.vimrc
~ $ ln -s /cygdrive/c/Dropbox/dotfiles/.gvimrc
~ $ ln -s /cygdrive/c/Dropbox/dotfiles/.vim

That takes care of vim in cygwin (both terminal vim and gtk gvim)

Windows side:

C:\Users\Bryan>mklink _vimrc C:\Dropbox\dotfiles\.vimrc
C:\Users\Bryan>mklink _gvimrc C:\Dropbox\dotfiles\.gvimrc
C:\Users\Bryan>mklink /D vimfiles C:\Dropbox\dotfiles\.vim

That takes care of windows vim (both commmand line vim and windows gvim)

This has been working for me successfully for about two years now.

like image 199
rossipedia Avatar answered Sep 23 '22 19:09

rossipedia


I use Homeshick to keep my dotfiles in GitHub, instead of using Dropbox like @rossipedia does, so I prefer to make my Cygwin setups the "authoritative" version and let Windows gVim use those.

The Vim Tips Wiki explains how to do this. Based on that, and updated for Homeshick, create a %HOMEPATH%\_vimrc file in Windows that contains the following:

set runtimepath+=c:/cygwin/home/username/.homesick/repos/dotfiles/home/.vim
source c:/cygwin/home/username/.homesick/repos/dotfiles/home/.vimrc

Or, more generically, and letting the repository's files take precedence over others in the runtime path:

let &runtimepath = $HOME . "/.homesick/repos/dotfiles/home/.vim," . &runtimepath
source $HOME/.homesick/repos/dotfiles/home/.vimrc
like image 39
Josh Kelley Avatar answered Sep 24 '22 19:09

Josh Kelley