1

Is there any way to configure Windows to open text files in Cygwin's VIM instance? I am currently using GVIM but I find it limiting for many reasons. Unfortunately, I can't just install Debian on this machine and be done with it!

dotancohen
  • 11,720

5 Answers5

3

Create cvim.bat file:

@echo off
chdir C:\cygwin\bin
start "" mintty.exe /usr/bin/vim.exe %1

Place it on your PATH and then cvim yourfile.txt or as Heptite has said: right-click on a .txt file and select "open with" you should be able to click "Browse" and go to that cvim.bat. Then you can click "Always use the selected program to open this kind of file".

dc46and2
  • 443
2

If you want to open VIM with the mintty terminal, you could use the following set-up:

First create a bash-script with the following:

#!/bin/sh
FILEPATH=$(cygpath -u "$1");
vim "$FILEPATH"

This will convert the windows filepath into a unix-style filepath for cygwin. Place this script (for example) in /bin/native-vim

In regedit (regedit.exe) you should go to HKEY_CLASSES_ROOT/*/shell. Create a new key (rightclick on shell) with as name Edit with VIM. Change the standard value to Edit with &VIM. Create a new key in Edit with VIM with the name command. Change the standard value to C:\cygwin64\bin\mintty.exe -i /Cygwin-Terminal.ico /bin/native-vim "%1" (or the path to your mintty.exe and bash-script).

The changes in your register could also be accomplished with these register-keys:

[HKEY_CLASSES_ROOT\*\shell\Edit with Vim]
@="Edit with &Vim"

[HKEY_CLASSES_ROOT\*\shell\Edit with Vim\command]
@="C:\\cygwin64\\bin\\mintty.exe -i /Cygwin-Terminal.ico /bin/native-vim \"%1\""
Snicksie
  • 121
  • 3
1

Here is the windows_gvim.bat file that I use to open text files with cygwin gvim under Windows. It works for cygwin vim too, just replace gvim with vim.

set "var=%1"
set "var=%var:\=\\%"
C:\cygwin64\bin\mintty.exe /bin/bash --login -c "gvim $(cygpath -u '%var%')"
Stoiko
  • 11
1

If you right-click on a .txt file and select "open with" you should be able to click "Browse" and go to C:\cygwin\bin\vim-nox.exe. Then you can click "Always use the selected program to open this kind of file".

However, I prefer to just have a "native" Windows Vim install and use that.

Heptite
  • 20,411
1

As long as path to the vim binary is the PATH environment variable, you should be able to run it from any command line like so:

vim filename

If you already have a running instance of vim, try:

vim --remote filename

Since you're using Cygwin, the man page was probably installed along with it. You can view all the options for invoking vim on the command line with:

man vim