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

Re: Pseudo options

Expand Messages
  • Stefan Karlsson
    1. I know how Vim variables work :-) 2. I really didn t say I was missing anything, I was simply curious. By the way, thanks for your effort to keep us
    Message 1 of 7 , Aug 5, 2005
    • 0 Attachment
      1. I know how Vim variables work :-)
      2. I really didn't say I was missing anything, I was simply curious.

      By the way, thanks for your effort to keep us updated with fresh,
      precompiled versions of Vim. Since I use Windows a lot I appreciate it
      very much.

      -- Stefan

      Tony Mechelynck wrote:

      > ----- Original Message ----- From: "Stefan Karlsson"
      > <stefan.74@...>
      > To: <vim@...>
      > Sent: Thursday, August 04, 2005 10:40 PM
      > Subject: Re: Pseudo options
      >
      >
      >>
      >> Nope, my question was simply if it was possible to *create* options.
      >>
      >> I mean, Vim has n-mode commands *and* a user can create his own
      >> n-mode commands. The same goes for v-mode, i-mode and :-mode
      >> commands. Vim has error messages *and* a user can create his own
      >> error messages. Vim has help pages *and* a user can create his own
      >> help pages. And so on.
      >>
      >> I was wondering if this reationale extended to options as well, but I
      >> guess it doesn't.
      >>
      >> I'm not saying it would be useful or anything :-) , I am simply curious.
      >>
      >>
      >> Best regards
      >>
      >> -- Stefan
      >
      >
      > Actually, options are just variables. There is, it is true, a
      > "special" command, namely ":set", but it is not essential. Look:
      >
      > For a boolean:
      > :set option
      > :let variable=1
      > :set nooption
      > :let variable=0
      > :set invoption
      > :set option!
      > :let variable = !variable
      > :set option?
      > :echo variable
      >
      > For a number:
      > :set option=1234
      > :let variable = 1234
      > :set option+=10
      > :let variable += 10
      > :set option^=5
      > :let variable = variable * 5
      > :set option
      > :set option?
      > :echo variable
      >
      > For a string:
      > :set option=abcd
      > :let variable = "abcd"
      > :set option=string\ with\ spaces
      > :let variable = "string with spaces"
      > :set option+=text
      > :if variable != "" | let variable .= "," | endif | let
      > variable .= "text"
      > :set option^=text
      > :if variable != "" | let variable = "," . variable | endif
      > | let variable = "text" . variable
      > :set option-=text
      > :let variable =
      > substitute(substitute(variable,'^text,\|,text,\|,text$\|^text$',",","g"),'^,\|,$',"","g")
      >
      > :set option
      > :set option?
      > :echo variable
      >
      > For a string of flags: same as above, except
      > :set option+=f
      > :set option^=f
      > :if variable !~ "f" | let variable .= "f" | endif
      > :set option-=f
      > :let variable = substitute(variable, "f", "", "g")
      >
      > For any kind:
      > :if exists("+option")
      > :if exists("variable")
      >
      > What is missing:
      > * "set to default", "set to vi default", "set to vim default";
      > however, user-created "options" wouldn't _have_ a default.
      > * Test for existence without testing for functionality (":if
      > exists('&option')"): a variable cannot exist without being functional.
      > I don't think of this as a blemish re variables.
      >
      > You can even have global variables (g:variable or, ouside of
      > functions, variable), buffer-local variables (b:variable),
      > window-local variables (w:variable), and other kinds which don't exist
      > for options. And you can create or destroy user-created variables,
      > while Vim options are either present or they are not (depending on
      > version and on config options) but they cannot be made to exist if
      > they don't, nor vice-versa. So I'd say variables are more powerful
      > than options.
      >
      > I really don't see what you're missing.
      >
      >
      > Best regards,
      > Tony.
      >
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.