开发者

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="winf开发者_StackOverflowilepath 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


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.


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


Okay I finally had time to fix this issue! To find a ./_(g)vimrc, (g)vim first looks in the $HOME directory. If it can't find a _/.(g)vimrc in it then it looks in the $VIM directory.

Since cygwin sets the $HOME environment variable, my win-gvim was trying to open the simlink in my home directory. So to load the right rc file, I need to set the $HOME variable correctly. I ended up with this new function:

#
# Compute windows file path and launch command in argument
#
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
}

#######
# Launching VIM
#######
winvim () {
  # HOME env var management
  myhomebak=$HOME
  export HOME="/cygdrive/d/Program\ Files/Vim"
  # Extract command
  cmd="$1"
  shift
  winfilepath $cmd "$@"
  export HOME=$myhomebak
}

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

Combined with the solution of Bryan Ross, I can now share my config! Thanks for your help.

Now I need to fix this white space issue......

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜