在Windows上设置gVim

时间:2012-05-16 05:09:40

标签: vim windows-7 permissions

我正在尝试让gVim在Windows 7机器上运行,并且遇到以下问题:

  • 每当我尝试更改_vimrc文件时,都会收到一条消息,说我无权保存在此位置。这是在我的家用电脑上。

  • 我似乎无法更改保存我编辑的文件的目录。目前他们都被保存到我的桌面。我尝试过:将dir = path设置为我要保存的位置......但没有成功。

我想通过vimtutor;但是,每当我将vimtutor键入cmd时,vim会打开一秒然后关闭。

如何更改_vimrc文件以及如何设置已编辑文件的目标?

2 个答案:

答案 0 :(得分:11)

我发现很多人以不同的方式做到这一点。以下是我在Windows上组织配置的方法。

  • 首先请注意,我不相信我的vim配置与stock vim安装混合。因此,我不会在%PROGRAMFILES%%PROGRAMFILES(x86)%中编写或修改文件。
  • 我的vim配置适用于不同的平台(OS X,linux,windows)。我将它们整理成.vim文件夹和.vimrc文件。
  • 我的一些Windows机器有cygwin而其他机器没有。在没有cygwin的那些文件中,我将.vim文件夹和我的_vimrc文件放在%USERPROFILE%中。在使用cygwin的那些文件中,我将.vim文件夹和我的_vimrc文件放在我的cygwin用户的主目录中。
  • 在Windows OOTB上没有定义
  • %HOME%,所以我定义它。我觉得setx.exe很容易......
    • 示例:setx HOME %USERPROFILE%setx HOME d:\cygwin\home\myname
    • 或者,您可以通过控制面板添加环境变量。
  • 注意,您可以在.vim中复制/存储_vimrc文件夹和%HOME%文件。但是我喜欢把它们放在我机器上其他地方的git repo中并链接到它们。在Windows上,我使用mlink /d %HOME%\.vim location_of_vim_folder链接.vim文件夹。并mlink /h %HOME%\_vimrc location_of_dot_vimrc_file.vimrc_vimrc文件相关联。
  • 请注意,您应该对上面定义的%HOME%文件夹具有写入权限...所以这应该可以解决您的权限问题。 (您需要成为管理员才能写信至%PROGRAMFILES%%PROGRAMFILES(x86)%
  • 在我的vimrc中,我有一些用于Windows的锅炉板材:

    "g:my_vim_dir is used elsewhere in my vim configurations
    let g:my_vim_dir=expand("$HOME/.vim")
    
    "$HOME/.vim and $HOME/.vim/after are in the &rtp on unix
    "But on windows, they need to be added.
    if has("win16") || has("win32") || has("win64")
      "add g:my_vim_dir to the front of the runtimepath
       execute "set rtp^=".g:my_vim_dir
      "add g:my_vim_dir\after to the end of the runtimepath
      execute "set rtp+=".g:my_vim_dir."\\after"
      "Note, pathogen#infect() looks for the 'bundle' folder in each path
      "of the &rtp, where the last dir in the '&rtp path' is not 'after'. The
      "<path>\bundle\*\after folders will be added if and only if
      "the corresponding <path>\after folder is in the &rtp before
      "pathogen#infect() is called.  So it is very important to add the above
      "'after' folder.
      "(This applies to vim plugins such as snipmate, tabularize, etc.. that
      " are loaded by pathogen (and perhaps vundle too.))
    
      " Not necessary, but I like to cleanup &rtp to use \ instead of /
      " when on windows machines
      let &rtp=substitute(&rtp,"[/]","\\","g")
    
      "On windows, if called from cygwin or msys, the shell needs to be changed 
      "to cmd.exe to work with certain plugins that expect cmd.exe on windows versions   
      "of vim.
      if &shell=~#'bash$'
        set shell=$COMSPEC " sets shell to correct path for cmd.exe
      endif
    endif
    
    "Then I load pathogen... (Or if you prefer, you could load vundle bundles here if you wish )
    

答案 1 :(得分:2)

  

我似乎无法更改保存我编辑的文件的目录。目前他们都被保存到我的桌面。我尝试过:将dir = path设置为我要保存的位置......但没有成功。

dir交换文件的位置,它是Vim在运行时使用的特殊后备文件。

您想要的是更改当前目录的cdlcd。在Vim中输入:help cd以获取更多信息。

  

如何更改_vimrc文件以及如何设置已编辑文件的目的地?

我的Vim文件夹($ VIM)中有_vimrc,所以当我想将Vim放在新的Windows机器上时,我只需复制整个文件夹。

相关问题