Re: vim -S

2006-08-01 Thread Matthew Winn
On Mon, 31 Jul 2006 16:19:28 -0300, Rodolfo Borges
[EMAIL PROTECTED] wrote:

 I made a file with vim commands, starting with
 #!/usr/bin/vim -S
 so I can execute the file directly, instead of using vim -S file.
 The problem is that vim tries to execute this first line too.
 
 Can we have a workaround on this?
 Like, ignoring #! at the start of a command, instead of giving the
 no ! allowed error?
 Or am I having it all wrong?

One way is to create a file that is both a valid shell script and
a valid Vim script by starting the file with the following line:

exec vim -S $0 $@
[vim commands go here]

(That's a dollar-zero after the -S, not dollar-capital-O.)  When the
shell runs this file it sees the exec command and runs Vim.  Because
$0 is the name of the script Vim opens the script and executes it,
but it ignores the first line because it sees it as a comment.

-- 
Matthew Winn


Re: vim -S

2006-08-01 Thread mwoehlke

(On the list, please?)

Rodolfo Borges wrote:

mwoehlke wrote:

A.J.Mechelynck wrote:

Rodolfo Borges wrote:

I made a file with vim commands, starting with
#!/usr/bin/vim -S
so I can execute the file directly, instead of using vim -S file.
The problem is that vim tries to execute this first line too.

Can we have a workaround on this?
Like, ignoring #! at the start of a command, instead of giving the
no ! allowed error?
Or am I having it all wrong?



Method I:
-8- foo (or whatever)
#!/bin/bash
vim -S foo.vim
-8-
then put the rest in foo.vim and do chmod a+x foo or chmod 0755 foo.

Method II: add to one of your shell startup scripts (~/.bashrc or 
whatever):


alias foo='vim -S ~/foo.vim'

Commentary:
In a vim script, the first line has no special meaning. Empty lines, 
blank lines (i.e. consisting only of spaces and/or tabs) and lines 
starting with zero or more spaces or tabs plus a double quote are 
comments; the rest are ex-commands (which don't have to start with a 
colon). :# is synonymous with :number so Vim tries to execute your 
first line as the command :number!/usr/bin/vim -S. Now the :number 
command doesn't accept a bang (there is no :number! command), so you 
get an error.


So... if it's an error, and we know it's an error, and will always be an 
error (at least at the present)... is in unreasonable to make '#!.*', as 
the first line of a '-S' script, be ignored?


*I* thought it was a reasonable suggestion...


That was my first thought.

Now, why does Vim use  instead of # for comments is a mistery to me..


Probably because - as Tony noted (above) - '#' itself is potentially a 
valid command? (But I still say this is a reasonable exception.)


--
Matthew
This is not the list you're looking for. -- Perversion of Obi Wan



Re: vim -S

2006-07-31 Thread Nikolai Weibull

On 8/1/06, A.J.Mechelynck [EMAIL PROTECTED] wrote:

Rodolfo Borges wrote:
 I made a file with vim commands, starting with
 #!/usr/bin/vim -S
 so I can execute the file directly, instead of using vim -S file.
 The problem is that vim tries to execute this first line too.



Method I:
-8- foo (or whatever)
#!/bin/bash
vim -S foo.vim
-8-


And you can of course make it more general by parameterizing the
script name and create additional scripts that delegate to this one.

Another solution is to use Zsh:

#! /bin/zsh
exec vim -S =('EOS'
echoerr 'hello'
EOS
)


Method II: add to one of your shell startup scripts (~/.bashrc or whatever):



   alias foo='vim -S ~/foo.vim'


And again, another one for Zsh:

 alias -s vim='vim -S'

Finally, it wouldn't be impossible to make the source command be a bit
more flexible in this regard, disregarding a she-bang line if one is
found.

 nikolai


Re: vim -S

2006-07-31 Thread mwoehlke

A.J.Mechelynck wrote:

Rodolfo Borges wrote:

I made a file with vim commands, starting with
#!/usr/bin/vim -S
so I can execute the file directly, instead of using vim -S file.
The problem is that vim tries to execute this first line too.

Can we have a workaround on this?
Like, ignoring #! at the start of a command, instead of giving the
no ! allowed error?
Or am I having it all wrong?



Method I:
-8- foo (or whatever)
#!/bin/bash
vim -S foo.vim
-8-
then put the rest in foo.vim and do chmod a+x foo or chmod 0755 foo.

Method II: add to one of your shell startup scripts (~/.bashrc or 
whatever):


alias foo='vim -S ~/foo.vim'

Commentary:
In a vim script, the first line has no special meaning. Empty lines, 
blank lines (i.e. consisting only of spaces and/or tabs) and lines 
starting with zero or more spaces or tabs plus a double quote are 
comments; the rest are ex-commands (which don't have to start with a 
colon). :# is synonymous with :number so Vim tries to execute your 
first line as the command :number!/usr/bin/vim -S. Now the :number 
command doesn't accept a bang (there is no :number! command), so you 
get an error.


So... if it's an error, and we know it's an error, and will always be an 
error (at least at the present)... is in unreasonable to make '#!.*', as 
the first line of a '-S' script, be ignored?


*I* thought it was a reasonable suggestion...

--
Matthew
DOS Attack: See America Online -- my college room mate