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

Re: What do I need to read to understand g: and s: VIM variable prefixes?

Expand Messages
  • Tony Mechelynck
    ... In Vimscript, an interpreted language, there are no declarations : any command needs to be executed in order to have an effect. It is when flow control
    Message 1 of 15 , Nov 1, 2012
    • 0 Attachment
      On 31/10/12 21:02, Dotan Cohen wrote:
      > On Wed, Oct 31, 2012 at 9:52 PM, donothing successfully
      > <donothingsuccessfully@...> wrote:
      >> On 31 October 2012 19:15, Dotan Cohen <dotancohen@...> wrote:
      >>> […]
      >>> #include <stdio.h>
      >>> int foo();
      >>>
      >>> int main() {
      >>> int x = 42;
      >>> printf("%d", x);
      >>> foo();
      >>> return 0;
      >>> }
      >>>
      >>> int foo() {
      >>> printf("%d", x);
      >>> }
      >>> […]
      >> Here x is a local variable of the function *main*.
      >> I think the "global" keyword is more of a weirdism of PHP than
      >> standard practise.
      >> http://en.wikipedia.org/wiki/Global_variable#C_and_C.2B.2B
      >>
      >
      > Exactly. However, there is no flow control outside of main(), so I
      > don't account for variables declared outside of main(). If someone is
      > declaring a variable in an area of the program with no flow control,
      > then they are explicitly declaring their intentions that the variable
      > will be global. In other words, it is not a surprise or a gotcha when
      > the variable is available in a different scope.
      >
      >

      In Vimscript, an interpreted language, there are no "declarations": any
      command needs to be "executed" in order to have an effect. It is when
      flow control goes through the :au, :map, :abbrev, :function or :command
      command, for instance, that the autocommand, mapping, abbreviation,
      function definition or user-command definition are stored in interpreter
      memory; before that, Vim doesn't "know" anything about them. Similarly,
      the type of a variable is set by the latest :let command affecting that
      variable, you cannot "declare" a variable except by giving that variable
      a value (possibly an empty value such as "", [] or {}).


      Best regards,
      Tony.
      --
      Vote for ME -- I'm well-tapered, half-cocked, ill-conceived and
      TAX-DEFERRED!

      --
      You received this message from the "vim_use" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php
    • Ben Fritz
      ... If somebody declares a variable with a g: prefix in Vim, they are explicitly declaring their intentions that the variable will be global. In other words,
      Message 2 of 15 , Nov 1, 2012
      • 0 Attachment
        On Wednesday, October 31, 2012 3:02:30 PM UTC-5, dotancohen wrote:
        >
        > Exactly. However, there is no flow control outside of main(), so I
        > don't account for variables declared outside of main(). If someone is
        > declaring a variable in an area of the program with no flow control,
        > then they are explicitly declaring their intentions that the variable
        > will be global. In other words, it is not a surprise or a gotcha when
        > the variable is available in a different scope.
        >

        If somebody declares a variable with a g: prefix in Vim, they are explicitly declaring their intentions that the variable will be global. In other words, it is not a surprise or gotcha when the variable is available in a different scope. Am I misunderstanding your complaint?

        --
        You received this message from the "vim_use" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php
      • Dotan Cohen
        On Thu, Nov 1, 2012 at 9:09 AM, Tony Mechelynck ... I realize that. I just stated that Vimscript is different than other environments that I am familiar with,
        Message 3 of 15 , Nov 4, 2012
        • 0 Attachment
          On Thu, Nov 1, 2012 at 9:09 AM, Tony Mechelynck
          <antoine.mechelynck@...> wrote:
          > In Vimscript, an interpreted language, there are no "declarations": any
          > command needs to be "executed" in order to have an effect. It is when flow
          > control goes through the :au, :map, :abbrev, :function or :command command,
          > for instance, that the autocommand, mapping, abbreviation, function
          > definition or user-command definition are stored in interpreter memory;
          > before that, Vim doesn't "know" anything about them. Similarly, the type of
          > a variable is set by the latest :let command affecting that variable, you
          > cannot "declare" a variable except by giving that variable a value (possibly
          > an empty value such as "", [] or {}).
          >

          I realize that. I just stated that Vimscript is different than other
          environments that I am familiar with, and that it was good of you to
          point out an important difference.

          --
          Dotan Cohen

          http://gibberish.co.il
          http://what-is-what.com

          --
          You received this message from the "vim_use" maillist.
          Do not top-post! Type your reply below the text you are replying to.
          For more information, visit http://www.vim.org/maillist.php
        • Dotan Cohen
          ... I have no complaint. I just mentioned that Vimscript differs from other environments. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- You
          Message 4 of 15 , Nov 4, 2012
          • 0 Attachment
            On Thu, Nov 1, 2012 at 4:38 PM, Ben Fritz <fritzophrenic@...> wrote:
            > If somebody declares a variable with a g: prefix in Vim, they are explicitly declaring their intentions that the variable will be global. In other words, it is not a surprise or gotcha when the variable is available in a different scope. Am I misunderstanding your complaint?
            >

            I have no complaint. I just mentioned that Vimscript differs from
            other environments.


            --
            Dotan Cohen

            http://gibberish.co.il
            http://what-is-what.com

            --
            You received this message from the "vim_use" maillist.
            Do not top-post! Type your reply below the text you are replying to.
            For more information, visit http://www.vim.org/maillist.php
          Your message has been successfully submitted and would be delivered to recipients shortly.