你如何在 Windows 中运行 Vim?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10049316/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 09:25:09  来源:igfitidea点击:

How do you run Vim in Windows?

windowsshellvim

提问by Mr Prolog

I just installed gVim, and tried using the usual "vim myfile.java" technique that usually works for linux to open up a file and edit it. But unfortunately, this doesn't seem to work. I've also tried "gvim myfile.java", but that doesn't work either.

我刚刚安装了 gVim,并尝试使用通常适用于 linux 的常用“vim myfile.java”技术来打开文件并对其进行编辑。但不幸的是,这似乎不起作用。我也试过“gvim myfile.java”,但这也不起作用。

Does anyone know how to open up vim (and use it like you do in linux) using Windows Powershell, or some other technique?

有谁知道如何使用 Windows Powershell 或其他一些技术打开 vim(并像在 linux 中一样使用它)?

回答by kev

When you install gVim:
Please make sure [?] Create .bat files for command line useis checked.
It'll create several .batfiles in C:\Windows\:

安装时gVim
请确保[?] Create .bat files for command line use已选中。
它将在以下位置创建几个.bat文件C:\Windows\

C:\>cd %windir%
C:\WINDOWS>dir /b *.bat
evim.bat
gview.bat
gvim.bat
gvimdiff.bat
view.bat
vim.bat
vimdiff.bat
vimtutor.bat

Notice that: C:\WINDOWSis already in the PATHenvironment variable.
When you type vimin command line, C:\WINDOWS\vim.batwill be launched.
If you leave the checkbox mentioned above unchecked, you need to modify PATHmanually.

请注意:C:\WINDOWS已经在PATH环境变量中。
当您vim在命令行中键入时,C:\WINDOWS\vim.bat将启动。
如果您不选中上面提到的复选框,则需要PATH手动修改。

回答by ruffin

Just to supplement, I'm on a fairly highly controlled Windows workstation right now, and don't have access to much. Downloading the "executable installer" that I usually use did not create the batfiles nor, for some reason, vim.exe, though gvim.exewas installed in the vim74dir for me and worked fine. So though I also needed to set the PATH, that there was no batfile in C:\WiNDOWSnor any command line executable in my VIm runtime folder to call meant that callingvimfrom the command line (or Powershell) didn't work.

补充一下,我现在在一个相当严格控制的 Windows 工作站上,并且没有太多访问权限。下载我通常使用的“可执行安装程序”并没有创建bat文件,也没有因为某种原因vim.exe,虽然为我gvim.exe安装在vim74目录中并且工作正常。因此,尽管我还需要设置PATH,我的 VIm 运行时文件夹中没有bat文件,C:\WiNDOWS也没有任何命令行可执行文件可供调用,这意味着vim从命令行(或 Powershell)调用不起作用。

I'm guessing some portion of the install that's creating the command-line related stuff, apparently including vim.exe, isn't recovering gracefully when you don't have admin permissions.

我猜vim.exe,当您没有管理员权限时,创建命令行相关内容的安装的某些部分(显然包括)不会正常恢复。

Either way, the "right" thing to do appears to be to set your PATHto your vim executable folder as usual (note that this might be a little more difficult than usual if you don't have admin privs), then download the "Win32 console executable" from the usual download pagethat matches the version of gvimthat you've already installed, dig vim.exeout of that zip you just downloaded, and place that into the same folder as gvim.exe.

无论哪种方式,“正确”的做法似乎是PATH像往常一样将您的 vim 可执行文件夹设置为您的 vim 可执行文件夹(请注意,如果您没有 admin privs,这可能比平时更难),然后下载“Win32控制台可执行文件”从与您已经安装的版本相匹配的常用下载页面gvim,挖出vim.exe您刚刚下载的 zip,并将其放入与gvim.exe.

Looking on another box where the executable installer did work "fully", there's some jive in the vim.bat file that wasn't installed for me about "collect the arguments in VIMARGS for Win95" and if .%OS%==.Windows_NT goto ntaction, etc etc, but not having any of that doesn't seem to be a problem on Win7, at least. ;^)

查看可执行安装程序“完全”工作的另一个盒子,vim.bat 文件中有一些没有为我安装的关于“在 VIMARGS 中为 Win95 收集参数”和if .%OS%==.Windows_NT goto ntaction等等的jive ,但没有任何至少在 Win7 上这似乎不是问题。;^)

回答by Rajat Bhatt

Windows 10 has linux subsystem for windows. So you can install bash in windows and from bash you can use vim.I found it more convenient.

Windows 10 具有适用于 Windows 的 linux 子系统。所以你可以在 windows 中安装 bash 并且从 bash 你可以使用 vim。我发现它更方便。

回答by Oudom R. Sambath

Install gVim on your window and enable ".bat" when you install gvim and click next, done. You can use vim on window.

在您的窗口上安装 gVim 并在安装 gvim 时启用“.bat”并单击下一步,完成。您可以在窗口上使用 vim。