How to use "gf" on filenames containing spaces in gVim?
Asked Answered
F

3

10

In gVim if the cursor is over a filename (like "C:\Program Files\Vim\vim71\README.txt" ) which contains spaces then using 'gf' fails.

I found the isfname option but the documentation says one should avoid using spaces.

Is there I can make gVim open files under these circumstances ?

Fromenty answered 29/10, 2009 at 11:13 Comment(0)
S
13

Select the text in visual mode, then do a gf on it. That gets around the problem to some extent.

Sporangium answered 29/10, 2009 at 11:17 Comment(1)
this works somewhat, but gF is even better when you have a fil/path:44 (followed by a line number. How can I do that?Camelback
H
0

Another option is to use Windows' "8dot3" filenames. I've tested it out in Windows 7 + GVIM succesfully.

Find out the short filename by using the /X flag in the CMD prompt. You want to CD to the parent folder to that which has spaces in it. I'm not sure how to get the whole path at once in "8dot3" form.

Typing "cd " and then dragging from the Explorer's address bar to the CMD window can be easier than typing out the path:

> cd "C:\Users\Fabrice\Documents"
> dir /X

Then use it in Vim, eg:

C:\Users\Fabrice\Documents\MYGAME~1\Skyrim\SkyrimPrefs.ini

If using a folder instead of a file name, the path appears properly expanded in the Netrw listing (:Ex file list).

Hirst answered 1/12, 2011 at 17:30 Comment(0)
P
0

I am using LunarVim (a config layer for NeoVim), not gVim, but I believe this should also work for gVim. You can add <space> to isfname variable by doing:

:set isfname+=32

32 is the ASCII keycode for space.

The other way to do it in NeoVim, is by using Lua:

:lua vim.opt.isfname:append({ '32' })

However, the help page :help 'isfname' warns against adding space to this option.

Projective answered 21/8 at 12:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.