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

Function with argument!?

Expand Messages
  • kbosau@web.de
    Hi, ... call Init(60) does not work. What s wrong? Thanks in advance! Klaus
    Message 1 of 4 , Oct 30, 2002
    • 0 Attachment
      Hi,

      I got a problem when defining a function:


      :function Init(columns)
      : set tw=a:columns
      :endfunction

      call Init(60)


      does not work. What's wrong?

      Thanks in advance!

      Klaus
    • Naveen Chandra
      ... You should use let instead of set ... see :help let -ncr
      Message 2 of 4 , Oct 30, 2002
      • 0 Attachment
        > I got a problem when defining a function:
        >
        >
        > :function Init(columns)
        > : set tw=a:columns
        > :endfunction
        >
        > call Init(60)
        >

        You should use 'let' instead of 'set'
        :function Init(columns)
        : let &tw=a:columns
        :endfunction

        see :help let

        -ncr
      • kbosau@web.de
        ... Thanks! I didn t know this operator... :-) Klaus
        Message 3 of 4 , Oct 30, 2002
        • 0 Attachment
          On 30 Oct 2002 at 17:25, Naveen Chandra wrote:

          >
          > > I got a problem when defining a function:
          > >
          > >
          > > :function Init(columns)
          > > : set tw=a:columns
          > > :endfunction
          > >
          > > call Init(60)
          > >
          >
          > You should use 'let' instead of 'set'
          > :function Init(columns)
          > : let &tw=a:columns
          > :endfunction
          >
          > see :help let

          Thanks! I didn't know this operator... :-)

          Klaus
        • Thomas Köhler
          ... Oh well. Or exec. ... The original function just doesn t work because vim tries to set tw to a:columns instead of the contents of the variable a:columns.
          Message 4 of 4 , Oct 30, 2002
          • 0 Attachment
            Naveen Chandra wrote [2002/10/30 13:02]:
            > > I got a problem when defining a function:
            > >
            > >
            > > :function Init(columns)
            > > : set tw=a:columns
            > > :endfunction
            > >
            > > call Init(60)
            >
            > You should use 'let' instead of 'set'
            > :function Init(columns)
            > : let &tw=a:columns
            > :endfunction
            >
            > see :help let

            Oh well. Or exec.

            :function Init(columns)
            : exec "set tw=" . a:columns
            :endfunction

            :help :exec

            The original function just doesn't work because vim tries to set
            tw to "a:columns" instead of the contents of the variable
            a:columns.
            So, any solution that evaluates a:columns first should do the
            trick. Both :let and :exec should work fine.

            Ciao,
            Thomas

            --
            Thomas Köhler Email: jean-luc@... | LCARS - Linux
            <>< WWW: http://jeanluc-picard.de | for Computers
            IRC: jeanluc | on All Real
            PGP public key available from Homepage! | Starships
          Your message has been successfully submitted and would be delivered to recipients shortly.