Open a text file in cygwin's VIM

10,380

Solution 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.

Solution 2

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".

Solution 3

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\""

Solution 4

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

Solution 5

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%')"
Share:
10,380
dotancohen
Author by

dotancohen

Updated on September 18, 2022

Comments

  • dotancohen
    dotancohen over 1 year

    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
    dotancohen about 12 years
    Thank you, that does work. However it opens in a CMD-like window with no access to the Cygwin shell. Is there any way to have it start in a new or existing Cygwin instance?
  • Heptite
    Heptite about 12 years
    That gets trickier, and I don't know if it's possible at all. I suspect that if it is, it would require directly modifying the registry to change the command for the .txt filetype, and I'm not that talented with Windows (it has never been my primary OS).
  • dotancohen
    dotancohen about 12 years
    Thank you Dorian. I did find the path to Cygwin's VIM from Heptite's answer. However it opens in a Windows-environment terminal, not in the Sygwin-environment terminal. Do you know how to open the program in the Cygwin terminal? Thanks!
  • Dorian Patterson
    Dorian Patterson about 12 years
    Off the top of my head, running the command in Cygwin terminal should work. Otherwise you can do a somewhat complicated invocation of the shell that you use in Cygwin (probaly bash).
  • dotancohen
    dotancohen about 12 years
    Thanks. I suppose that I could start browsing the Windows directories in Cygwin. I was hoping for a bridge from Windows Explorer (the Windows file manager).
  • dotancohen
    dotancohen about 12 years
    For posterity, and my future self: Use cygwin shell.
  • dotancohen
    dotancohen over 9 years
    Thank you very much! I don't have a cygwin environment to test in right now (happily at home in Linux) but as soon as I have to fight with another Windows machine I will try this. +1 in the meantime. Thanks!