Re: Opening/creating a filename with a space using the :e command?

875 views
Skip to first unread message

Tim Chase

unread,
Dec 31, 2012, 1:36:26 PM12/31/12
to vim...@googlegroups.com, delph367
On 12/31/12 09:48, delph367 wrote:
> Do I need to do some kind of special escape sequence in order to
> open it, or is VIM just designed such that I can't do this?

I don't know which OS you're on, but you might try using a backslash
to escape the space:

:e ~/path/to/file\ with\ space

or, you can try using <tab> expansion to let Vim auto-complete the
filename.

-tkc



Ben Fritz

unread,
Dec 31, 2012, 1:40:34 PM12/31/12
to vim...@googlegroups.com, delph367
On Monday, December 31, 2012 12:36:26 PM UTC-6, Tim Chase wrote:
> On 12/31/12 09:48, delph367 wrote:
>
> > Do I need to do some kind of special escape sequence in order to
>
> > open it, or is VIM just designed such that I can't do this?
>
>
>
> I don't know which OS you're on, but you might try using a backslash
>
> to escape the space:
>
>
>
> :e ~/path/to/file\ with\ space
>

Vim handles the file path internally so this is how to do it on any system, even Windows.

sc

unread,
Dec 31, 2012, 1:46:50 PM12/31/12
to vim...@googlegroups.com
On Mon, Dec 31, 2012 at 07:48:58AM -0800, delph367 wrote:
> I've tried searching for an answer on Google, but I keep getting tons of irrelevant results that have nothing to do with this topic.

> Here's a list of what I've tried:

> :e ~/File name

> E172: Only one file name allowed

> :e "~/File name"

> E32: No file name

> :e ~/"File name"

> "~/" Illegal file name

> I've also tried all three combinations with /home/username instead of the ~/ shortcut. It seems like no matter what I try, it just won't open a file name with a space in it.

> Do I need to do some kind of special escape sequence in order to open it, or is VIM just designed such that I can't do this?

no, not special, the most common, mundane escape sequence in all of
computerland:

:e ~/File\ name

should get you what you want.

sc

stillLearningVim

unread,
Dec 31, 2012, 2:45:48 PM12/31/12
to vim...@googlegroups.com, toot...@swbell.net
> :e ~/File name
>
> E172: Only one file name allowed
The space is causing vim to think it's trying to open more than one file

> :e "~/File name"
>
> E32: No file name

" is for a comment in vimscript, so vim is ignoring the rest of the command.

> :e ~/"File name"
>
> "~/" Illegal file name

This is the same problem, vim ignores everything after the ". Since this ends in a / vim thinks it's a directory, not a file.


> Do I need to do some kind of special escape sequence in order to open it, or is VIM just designed such that I can't do this?

All the previous posts about using the \ character to escape a space should work.

delph367

unread,
Dec 31, 2012, 5:19:01 PM12/31/12
to vim...@googlegroups.com, toot...@swbell.net

Actually, I figured this out myself after looking up "escape sequences," and this was the second one I tried. First I tried using a %20 as a space, which didn't work, and then I tried proceeding the backslash with a space... and that worked perfectly.

Thanks for your post though, the explanation about VIM script was interesting because I was wondering why VIM can't understand quotes. Bash and the Windows Command Line both recognize that usage to input long file names, so I was rather confused when it didn't work here.

I'm actually using Ubuntu Linux right now, but I do use GVIM on my Windows machine as well... I've been avoiding spaces and/or renaming files to get around this limitation for a while now, and finally decided to look up how to deal with it properly.

Reply all
Reply to author
Forward
0 new messages