How do you run Vim in Windows?

2020-02-09 05:58发布

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.

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

5条回答
Root(大扎)
2楼-- · 2020-02-09 06:36

To use vim in command prompt add the vim application in the PATH variable. To do that just go to My Computer> Properties > Advanced System Settings(on the left corner) > Environment Variables There are two things: User Variable and System Variables In System variables there will be a "Path" variable, Double click on it and add the path for the vim application. For me it was:

C:\Program Files (x86)\Vim

Save it and reopen command prompt, type vim and it should work.See this image for reference

查看更多
相关推荐>>
3楼-- · 2020-02-09 06:38

When you install gVim:
Please make sure [✓] Create .bat files for command line use is checked.
It'll create several .bat files in 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:\WINDOWS is already in the PATH environment variable.
When you type vim in command line, C:\WINDOWS\vim.bat will be launched.
If you leave the checkbox mentioned above unchecked, you need to modify PATH manually.

查看更多
仙女界的扛把子
4楼-- · 2020-02-09 06:46

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 bat files nor, for some reason, vim.exe, though gvim.exe was installed in the vim74 dir for me and worked fine. So though I also needed to set the PATH, that there was no bat file in C:\WiNDOWS nor any command line executable in my VIm runtime folder to call meant that callingvim from the command line (or Powershell) didn't work.

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.

Either way, the "right" thing to do appears to be to set your PATH to 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 page that matches the version of gvim that you've already installed, dig vim.exe out of that zip you just downloaded, and place that into the same folder as 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. ;^)

查看更多
时光不老,我们不散
5楼-- · 2020-02-09 06:51

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.

查看更多
我只想做你的唯一
6楼-- · 2020-02-09 06:58

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

查看更多
登录 后发表回答