Search code examples
vimcygwin

How to edit file name under cursor in Vim/Gvim, when it starts with /cygdrive/ in Windows


With cygwin64 installed, and a separate Gvim 8.0.2 installation. I can open a file on the bash prompt like this:

gvim /cygdrive/c/Temp/foo.txt

it works because my script uses cygpath -w /cygdrive/c/Temp/foo.txt to convert the path into its windows form, finally calling gvim.exe C:\Temp\foo.txt.

However in Gvim, when my cursor is on a line like this:

/cygdrive/c/Temp/foo.txt

and I type <Ctrl-W> f, I get this error text in Gvim:

E447: Can't find file "/cygdrive/c/Temp/foo.txt" in path

What must I do to get this working in a standard installation of Gvim under Windows?


Solution

  • You can use 'includeexpr' to modify the path found:

    set includeexpr=substitute(v:fname,'/cygdrive/c','C:/','')
    

    This will open C:/Temp/foo.txt instead.

    See :help gf, :help 'includeexpr'