在Windows上安装gVim

5

我正在尝试在Windows 7计算机上使用gVim,并遇到以下问题:

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

  • 我似乎无法更改编辑文件保存的目录。 它们都保存在我的桌面上。 我尝试了:set dir =路径,但没有成功。

我想运行vimtutor; 但是,每当我在cmd中输入vimtutor时,vim会闪现一秒钟然后关闭。

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


1
Win7 / Vista 的好处和坏处在于,有些事情需要管理员权限才能完成。因此,您应该通过管理员权限运行编辑器(记事本)。 - Eli Y
1
你想编辑的 _vimrc 文件在哪个位置?它应该在你的用户目录中。 - romainl
@romainl:C:\Program Files (x86)\Vim - bqui56
1
将你的 _vimrc 写在你的用户目录下。 - romainl
@romainl:所有东西都应该在那个目录里吗?也就是说,我安装的时候应该将它指定为我的目标文件夹,还是只有 _vimrc 放在那里? - bqui56
不需要,只需使用默认设置安装GVim即可。您需要自己创建C:\users\username\_vimrcc:\users\username\vimfiles\文件夹。 - romainl
2个回答

11

我发现很多人对此有不同的做法。以下是我在Windows上组织配置的方法:

  • 首先要注意,我不相信将我的vim配置混合在原始的vim安装中。所以我不会在%PROGRAMFILES%%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 )

2
无法更改编辑的文件保存目录。现在所有文件都保存在我的桌面上。我尝试使用:set dir=path来设置不成功。
dir是swap文件的位置,这些文件是Vim在运行时使用的特殊后备文件。
你需要使用cd或lcd来更改当前目录。在Vim中输入:help cd以获取更多信息。
如何修改_vimrc文件并设置编辑文件的目标?
我在我的Vim文件夹($VIM)中有_vimrc文件,因此当我想在新的Windows机器上使用Vim时,我只需复制整个文件夹。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接