5

我试图让 gVim 在 Windows 7 机器上工作,但遇到以下问题:

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

  • 我似乎无法更改保存我编辑的文件的目录。目前它们都被保存到我的桌面上。我试过 :set dir=path to where I want to save ...没有成功。

我想通过 vimtutor 运行;但是,每当我在 cmd 中键入 vimtutor 时,vim 都会闪烁打开一秒钟然后关闭。

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

4

2 回答 2

11

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

  • 首先请注意,我不相信将我的 vim 配置与股票 vim 安装混合。所以我不会在%PROGRAMFILES%or中编写或修改文件%PROGRAMFILES(x86)%
  • 我的 vim 配置适用于不同的平台(OS X、linux、windows)。我将它们组织在一个.vim文件夹和一个.vimrc文件中。
  • 我的一些 Windows 机器有 cygwin,而另一些没有。在没有 cygwin 的那些上,我将.vim文件夹和_vimrc文件放在%USERPROFILE%. 在使用 cygwin 的那些上,我将我的.vim文件夹和_vimrc文件放在我的 cygwin 用户的主目录中。
  • %HOME%Windows OOTB 上没有定义,所以我定义它。我发现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 )
    
于 2012-05-16T15:48:11.210 回答
2

我似乎无法更改保存我编辑的文件的目录。目前它们都被保存到我的桌面上。我试过 :set dir=path to where I want to save ...没有成功。

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

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

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

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

于 2012-05-16T17:14:29.517 回答