actan
actan

Reputation: 655

how to start a windows GUI program in cygwin?

I have gVim installed in my Win7 and I am using cygwin a lot.

When I am in cygwin bashell I want to enter "vim aaa.c" and then let my Windows program gVim open aaa.c for me.

Would anyone tell me to do what configuration then this could work?

Typing "notepad" directly in cygwin shell and pressing enter works. I know "notepad" can be found in Windows' system variable "path" so it works. I have tried adding my gVim.exe's path to system variable "path" but it doesn't work.

PS: if you type "run notepad" in cygwin shell it also starts Windows notepad. But how to make my gVim recognized by cygwin just like 'notepad'? I don't want to type the full installation path to my gVim in cygwin shell every time.

Thanks!

Upvotes: 6

Views: 15027

Answers (6)

mtbiker-s
mtbiker-s

Reputation: 11

For me the command 'run' in cygwin works. It's similar to the 'open' command in OSX cli.

This is how I utilize it in my .bash_aliases file

# Location of Programs in Win10 that are stored under
# Program Files (x86)
alias x86PF='cd "/cygdrive/c/Program Files (x86)"'

# Navigating to the location of Program Files (x86)
# then switching to the Notepad++ dir
# then calling 'notepad++.exe' with the run command.
# Note the use of the && to run multiple commands in one alias assignement


alias notepad++='x86PF && cd Notepad++ && run notepad++.exe'

Don't forget to source your .bashrc after you've modified your file with the aliases

Upvotes: 0

Michael Stong
Michael Stong

Reputation: 1

Hmmm, I'm slow. On your windows machine, there is a Cygwin folder with a home folder and your username folder. Just open the file explorer and edit it with windows gvim, then do the save and run it in bash. There is no need to make this a difficult problem.

Upvotes: 0

Michael Stong
Michael Stong

Reputation: 1

I just installed Cygwin and when I examined my path (echo $PATH) I see it basically inherits whatever windows has in its path...so provided you have gvim in your windows path you have it in your Cygwin path...which means cygstart gvim will start gvim...non of the hokey path issues required...I'm sure you can pass command line args and run it in the background too...

Upvotes: 0

Xuan
Xuan

Reputation: 5629

The easiest solution is to add the following line in your .bashrc

alias vim="/cygdrive/c/Program\ Files\ \(x86\)/vim/vim73/gvim.exe"

when invoking vim do vim foo.txt &, the & ensures the process is run in the background so your shell is still usable before the process ends.

if you do not want to type the & every time, do the following alias

alias vim="cygstart /cygdrive/c/Program\ Files\ \(x86\)/vim/vim73/gvim.exe"

The best solution though is to install cygwin vim instead of using the windows version. With the windows one, you will fight with the path conversion all the time. Really you want it to work for all the followings:

vim ~/foo
vim /bar
vim $home/abc
vim /cygpath/c/def
vim "c:\ghi"

There are some complicated shell scripts which help ease the problem, but I have not come across any that does not have certain caveat.

Upvotes: 8

Ingo Karkat
Ingo Karkat

Reputation: 172510

For me, the following works:

$ PATH=/cygdrive/c/Program\ Files\ \(x86\)/vim/vim73:$PATH
$ gvim

You can add to the PATH in your ~/.profile, but adding to the Windows PATH variable (via the Control Panel) should work, too. (Just be sure to use the normal C:\... notation then.)

Upvotes: 0

einpoklum
einpoklum

Reputation: 131405

As a quick hack, try using the full pathname, cygwin-style, e.g. /cygdrive/c/Program\ Files/gVim/gVim.exe.

Upvotes: 0

Related Questions