handling filename arguments with spaces

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

handling filename arguments with spaces

Steve Hall-4

Hi all,

Is there anyway to get Vim to understand filename arguments
differently than as separated by spaces or to have it expand these
arguments to real file names before opening them as buffers?

On Windows, one can change the default application for .txt files to
Vim by editing the MIME open action to something like:

  "C:\PROGRA~1\vim\vim63\gvim.exe" %1

The problem is, Windows profiles (and resultant home location) are
stored by default in a path with spaces like:

  C:\Documents and Settings\user.DOMAIN\Desktop\

Therefore, the first command's argument %1 ends up being interpreted
by Vim as "C:\Documents". If we change the command to:

  "C:\PROGRA~1\vim\vim63\gvim.exe" "%*"

You then end up with three buffers:

  "C:\Documents"
  "and"
  "Settings\user.DOMAIN\Desktop\"

The only hack I've found to fix this is:

  "C:\PROGRA~1\vim\vim63\gvim.exe" "%1 %2 %3 %4 %5 %6 %7 %8 %9"

but then if you only open one file, the buffer name is:

  "myfile.txt       "

with trailing spaces. Vim is obviously understanding the correct name
in this last case because

  :echo fnamemodify(expand("%"), ":p")

looks correct, but why is the buffer name wrong? Is there a way to
force Vim to expand and authenticate the filename arguments rather
than assuming they are just random buffer names not tied to a file?


--
Steve Hall  [ digitect mindspring com ]



Reply | Threaded
Open this post in threaded view
|

Re: handling filename arguments with spaces

Tim Chase-2
> The only hack I've found to fix this is:
>
>   "C:\PROGRA~1\vim\vim63\gvim.exe" "%1 %2 %3 %4 %5 %6 %7 %8 %9"
>
> but then if you only open one file, the buffer name is:
>
>   "myfile.txt       "

A simple modification of your above hack, to be something like

"c:\path\to\gvim.exe" "%1" "%2" "%3" "%4" ...

might do the trick.  However, this hack may be limited to nine files.

-tim







Reply | Threaded
Open this post in threaded view
|

Re: handling filename arguments with spaces

Hari Krishna Dara
In reply to this post by Steve Hall-4

On Thu, 23 Jun 2005 at 5:36pm, Steve Hall wrote:

>
> Hi all,
>
> Is there anyway to get Vim to understand filename arguments
> differently than as separated by spaces or to have it expand these
> arguments to real file names before opening them as buffers?
>
> On Windows, one can change the default application for .txt files to
> Vim by editing the MIME open action to something like:
>
>   "C:\PROGRA~1\vim\vim63\gvim.exe" %1
>
> The problem is, Windows profiles (and resultant home location) are
> stored by default in a path with spaces like:
>
>   C:\Documents and Settings\user.DOMAIN\Desktop\
>
> Therefore, the first command's argument %1 ends up being interpreted
> by Vim as "C:\Documents". If we change the command to:
>
>   "C:\PROGRA~1\vim\vim63\gvim.exe" "%*"
>
> You then end up with three buffers:
>
>   "C:\Documents"
>   "and"
>   "Settings\user.DOMAIN\Desktop\"
>
> The only hack I've found to fix this is:
>
>   "C:\PROGRA~1\vim\vim63\gvim.exe" "%1 %2 %3 %4 %5 %6 %7 %8 %9"
>
> but then if you only open one file, the buffer name is:
>
>   "myfile.txt       "
>
> with trailing spaces. Vim is obviously understanding the correct name
> in this last case because
>
>   :echo fnamemodify(expand("%"), ":p")
>
> looks correct, but why is the buffer name wrong? Is there a way to
> force Vim to expand and authenticate the filename arguments rather
> than assuming they are just random buffer names not tied to a file?
>

I don't know if Tim's modification does the trick, but I use the below
vbscript code to handle spaces in the files when you choose "View
Source" in IE. The same should work for shell actions too.

'--- gVimViewSourceInIE.vbs
----------------------------------------------------
'function: Start gvim, combining multiple arguments to single file argument.
'changes:  20010905: Quoted 'oWShell.Run' filename argument, allowing spaces.
'          20010518: Created.
'author:   Freddy Vulto <[hidden email]>

  ' Making variable declaration mandatory
option explicit

dim oWShell, sArg, sFile

  ' Create script object
set oWShell = CreateObject("wscript.shell")
  ' Loop through arguments
for each sArg in wscript.arguments
    ' Add argument to filename
  sFile = sFile & sArg & " "
next
  ' Remove excess space
sFile = Trim(sFile)
  ' Run Vim with file argument.  Additional arguments:
  ' -R: View file readonly
  ' -c "set syntax=html": Use HTML syntax-highlighting
  '    NOTE: Use "-c ""set ft=html""" to make it work for Vim v6.
oWShell.Run _
  """c:\apps\Vim\gvim.exe """ & _
  "-R """ & sFile & """ " & _
  "-c ""set syntax=html"""

  ' Destroy script object
set oWShell = NOTHING

--
HTH,
Hari


               
____________________________________________________
Yahoo! Sports
Rekindle the Rivalries. Sign up for Fantasy Football
http://football.fantasysports.yahoo.com
Reply | Threaded
Open this post in threaded view
|

Re: handling filename arguments with spaces

Steve Hall-4
On Thu, 2005-06-23 at 18:19 -0700, Hari Krishna Dara wrote:
> On Thu, 23 Jun 2005 at 5:36pm, Steve Hall wrote:
> >
> > Is there anyway to get Vim to understand filename arguments
> > differently than as separated by spaces or to have it expand these
> > arguments to real file names before opening them as buffers?
[...]
>
> I don't know if Tim's modification does the trick, but I use the
> below vbscript code to handle spaces in the files when you choose
> "View Source" in IE. The same should work for shell actions too.
[...]

Help me understand how this is used, would I leave it as OpenInVim.vbs
somewhere and then point the MIME action to it? Is it basically an
intermediate argument parser?


--
Steve Hall  [ digitect mindspring com ]


Reply | Threaded
Open this post in threaded view
|

Re: handling filename arguments with spaces

Hari Krishna Dara
In reply to this post by Steve Hall-4

On Thu, 23 Jun 2005 at 10:05pm, Steve Hall wrote:

> On Thu, 2005-06-23 at 18:19 -0700, Hari Krishna Dara wrote:
> > On Thu, 23 Jun 2005 at 5:36pm, Steve Hall wrote:
> > >
> > > Is there anyway to get Vim to understand filename arguments
> > > differently than as separated by spaces or to have it expand these
> > > arguments to real file names before opening them as buffers?
> [...]
> >
> > I don't know if Tim's modification does the trick, but I use the
> > below vbscript code to handle spaces in the files when you choose
> > "View Source" in IE. The same should work for shell actions too.
> [...]
>
> Help me understand how this is used, would I leave it as OpenInVim.vbs
> somewhere and then point the MIME action to it? Is it basically an
> intermediate argument parser?

Yes, that is what it is exactly. You specify this as the program instead
of the gvim.exe.

--
HTH,
Hari


               
__________________________________
Do you Yahoo!?
Read only the mail you want - Yahoo! Mail SpamGuard.
http://promotions.yahoo.com/new_mail 
Reply | Threaded
Open this post in threaded view
|

Re: handling filename arguments with spaces

Steve Hall-4
In reply to this post by Steve Hall-4
From: Hari Krishna Dara, Jun 24, 2005 12:40 AM
> On Thu, 23 Jun 2005 at 10:05pm, Steve Hall wrote:
> >
> > Help me understand how this is used, would I leave it as OpenInVim.vbs
> > somewhere and then point the MIME action to it? Is it basically an
> > intermediate argument parser?
>
> Yes, that is what it is exactly. You specify this as the program
> instead of the gvim.exe.

Windows XP does not accept .vbs files for a MIME action. Am I missing
something?

--
Steve Hall  [ digitect mindspring com ]



Reply | Threaded
Open this post in threaded view
|

Re: handling filename arguments with spaces

Hari Krishna Dara
In reply to this post by Steve Hall-4

On Fri, 24 Jun 2005 at 1:34pm, Steve Hall wrote:

> From: Hari Krishna Dara, Jun 24, 2005 12:40 AM
> > On Thu, 23 Jun 2005 at 10:05pm, Steve Hall wrote:
> > >
> > > Help me understand how this is used, would I leave it as OpenInVim.vbs
> > > somewhere and then point the MIME action to it? Is it basically an
> > > intermediate argument parser?
> >
> > Yes, that is what it is exactly. You specify this as the program
> > instead of the gvim.exe.
>
> Windows XP does not accept .vbs files for a MIME action. Am I missing
> something?

I didn't know that. In my case, I am using this as IE's View Source
editor, which is done by directly modifying a key in the registry. You
could do the same if you are familiar with the registry settings for
this, but that might not still work. How about pointing to cscript.exe
with this .vbs as an argument instead of using the .vbs itself as a
program?

--
HTH,
Hari


               
__________________________________
Do you Yahoo!?
Yahoo! Mail - Helps protect you from nasty viruses.
http://promotions.yahoo.com/new_mail