Mr Prolog
Mr Prolog

Reputation: 551

How do you run Vim in Windows?

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?

Upvotes: 47

Views: 92897

Answers (6)

Keith Hall
Keith Hall

Reputation: 1

For people with a lockdown install which won't make bat files or allow access to the path you can add this to your PowerShell profile.

New-Alias vi Vim-Launch

function Vim-Launch([string]$FILE) {
    if ($FILE) {
        $path = Join-Path $PWD $FILE
        & "C:\Program Files (x86)\vim\vim74/vim.exe" $path
    } else {
        & "C:\Program Files (x86)\vim\vim74/vim.exe"
    }
}

Upvotes: 0

Pluto
Pluto

Reputation: 3026

Because of restrictions on my workstation, I had to install my instance of vim locally to the following folder: %LocalAppData%\Vim

But just changing an environmental variable like others suggest is insufficient because the batch files aren't in the installation directory (such as vimdiff). So I figured out where these come from, and made my own batch files to add them to an environmental variable. To help you make these batch files, I've provided the list of commands below for you to run in the vim installation directory (if saving the commands to an install.bat file first, replace all % characters with %% to escape it):

echo @echo off > evim.bat
echo gvim.exe -y %* >> evim.bat

echo @echo off > view.bat
echo vim.exe -R %* >> view.bat

echo @echo off > gview.bat
echo gvim.exe -R %* >> gview.bat

echo @echo off > vimdiff.bat
echo vim.exe -d %* >> vimdiff.bat

echo @echo off > gvimdiff.bat
echo vim.exe -d %* >> gvimdiff.bat

Then you have to go to Start > Search 'Edit environment variables for your account' > Find 'Path' > Edit > Add a new subentry for %LocalAppData%\Vim\vim82. Last you may need to close and open the command prompt, or kill explorer.exe and restart it.

Upvotes: 0

Rattanakoudom Sambath
Rattanakoudom Sambath

Reputation: 514

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

Upvotes: 1

Rajat Bhatt
Rajat Bhatt

Reputation: 1545

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.

Upvotes: 3

ruffin
ruffin

Reputation: 17453

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. ;^)

Upvotes: 3

kev
kev

Reputation: 161604

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.

Upvotes: 47

Related Questions