Loading ...
Sorry, an error occurred while loading the content.
 

Re: vim -S

Expand Messages
  • mwoehlke
    ... 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
    Message 1 of 7 , Jul 31, 2006
      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
    • Yakov Lerner
      ... I think it s reasonable, taking into account that #! is illegal comand-come command (:# does not take !). Yakov
      Message 2 of 7 , Aug 1, 2006
        On 7/31/06, mwoehlke <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...

        I think it's reasonable, taking into account that
        #! is illegal comand-come command (:# does not take !).

        Yakov
      • Matthew Winn
        On Mon, 31 Jul 2006 16:19:28 -0300, Rodolfo Borges ... One way is to create a file that is both a valid shell script and a valid Vim script by starting the
        Message 3 of 7 , Aug 1, 2006
          On Mon, 31 Jul 2006 16:19:28 -0300, "Rodolfo Borges"
          <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?

          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
        • mwoehlke
          (On the list, please?) ... Probably because - as Tony noted (above) - # itself is potentially a valid command? (But I still say this is a reasonable
          Message 4 of 7 , Aug 1, 2006
            (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
          Your message has been successfully submitted and would be delivered to recipients shortly.