How do I run Windows vim from a function within my .bashrc?

1

I have installed windows vim and added the following function to my .bashrc:

function winvim() {
    local win_vim_path='/cygdrive/c/Program\ Files\ \(x86\)/Vim/vim73/vim.exe'
    #local win_vim_args=`cygpath -w -a "$*"`
    "$win_vim_path"
}

When I type winvim I am informed that there is 'No such file or directory'. However, if I type the path explicitly in cygwin vim runs as expected.

What is wrong here?

lovelyzoo

Posted 2013-06-04T19:14:43.473

Reputation: 11

the \\ are going to be lost. you need to double-escape – None – 2013-06-04T19:16:08.307

2@MarcB sure? IMHO he dont't need the \ because the path is in single quotes... – jm666 – 2013-06-04T19:20:32.260

but without the escapes the command will be seen as /cygdrive/c/Program with arguments Files and (x86)/Vim/vim73/vim.exe. – None – 2013-06-04T19:21:26.610

2@MarcB Not if you quote the expansion of win_vim_path. – chepner – 2013-06-04T19:29:49.580

Answers

4

When setting the value of win_vim_path, you need either single quotes or the backslashes to escape the spaces/parantheses, but not both.

local win_vim_path=/cygdrive/c/Program\ Files\ \(x86\)/Vim/vim73/vim.exe

or

local win_vim_path='/cygdrive/c/Program Files (x86)/Vim/vim73/vim.exe'

The quoted version is preferred as easier to read and type.

chepner

Posted 2013-06-04T19:14:43.473

Reputation: 5 645

3

From memory:

local win_vim_path="$(cygpath -u "$PROGRAMFILES")/Vim/vim73/vim.exe"

glenn jackman

Posted 2013-06-04T19:14:43.473

Reputation: 18 546