在 cygwin-vim 和 windows-gvim 之间共享 vim 配置并启动它的最佳方式

发布于 2024-11-30 01:30:32 字数 1545 浏览 0 评论 0原文

我正在尝试设置我的 cygwin 环境。 由于我是vim用户,我想在cygwin和windows上轻松使用它。

共享 vim 配置

我首先关心的是在两者之间共享配置(.vimrc/_vimrc 和 .vim/_vimfiles)。 事实上,我最近在 github 上托管了我的 vim 配置,并尝试通过 github 更新我的插件。

所以我做了一些谷歌搜索来找到最好的方法,但我未能找到一个“好的解决方案”(虽然不容易定义......)。 无论如何,很多人似乎都同意最好使用 windows-gvim 而不是 cygwin-gvim (由于 X 问题,我未能正确使用 cygwin-gvim,但我不想进一步了解)。 所以第一个问题:这是真的吗?

然后我尝试寻找一些基于windows-gvim的解决方案。 目前,我已经链接了win环境。在 cyg 环境中:

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

但是当我从 cygwin 打开 gvim 时,它失败了。我认为 win-gvim 无法读取 cygwin 的 simlinks。

我尝试链接 vimfiles 目录(所以是赢方),但他们 win-gvim 也找不到任何东西! 我不明白的是为什么从 cygwin 启动的 win-gvim 会查看我的 cygwin 主目录中的文件?!

我读到可以在 Windows 中声明一个 HOME 变量来帮助 win-vim ,但我担心它会产生副作用...

这就是配置配置... 有人有解决方案吗?

启动 vim

另外,为了启动 gvim,我使用了一个在 winpaths 中翻译 cigpaths 的函数的别名:

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,\" \"$@\""

这是一个好的做法吗?

谢谢您的帮助帮助:)

普洛夫

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

人生戏 2024-12-07 01:30:32

我将点文件保存在 Dropbox 中。该文件夹是 C:\Dropbox\dotfiles。为了在 windows 和 cygwin 之间使用它们,我要做的如下:

Cygwin 端:

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

负责 cygwin 中的 vim(终端 vim 和 gtk gvim)

Windows 端:

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

负责 windows vim(命令行 vim 和 windows gvim) )

这已经为我成功工作了大约两年。

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.

巴黎夜雨 2024-12-07 01:30:32

我使用 Homeshick 将我的点文件保存在 GitHub 中,而不是像 @rossipedia 确实如此,所以我更喜欢将我的 Cygwin 设置设为“权威”版本并让 Windows gVim 使用 那些。

Vim Tips Wiki 解释了如何执行此操作。在此基础上,并针对 Homeshick 进行更新,在 Windows 中创建一个 %HOMEPATH%\_vimrc 文件,其中包含以下内容:

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

或者,更一般地说,让存储库的文件优先于运行时路径中的其他文件:

let &runtimepath = $HOME . "/.homesick/repos/dotfiles/home/.vim," . &runtimepath
source $HOME/.homesick/repos/dotfiles/home/.vimrc

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
云归处 2024-12-07 01:30:32

好吧,我终于有时间解决这个问题了!
要查找 ./_(g)vimrc,(g)vim 首先查找 $HOME 目录。如果它在其中找不到 _/.(g)vimrc,那么它会在 $VIM 目录中查找。

由于 cygwin 设置了 $HOME 环境变量,因此我的 win-gvim 试图打开我的主目录中的 simlink。
因此,要加载正确的 rc 文件,我需要正确设置 $HOME 变量。我最终得到了这个新功能:

#
# 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 \"$@\""

结合 Bryan Ross 的解决方案,我现在可以分享我的配置了!
感谢您的帮助。

现在我需要解决这个空白问题......

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......

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文