(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