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

Re: saving and setting option

Expand Messages
  • Matt Wozniski
    ... Or, more safely: let old_lz = &lazyredraw try do some stuff finally let &lz = old_lz endif This method guarantees that the setting gets restored, even if
    Message 1 of 3 , Mar 10, 2010
      On Wed, Mar 10, 2010 at 7:07 AM, Jürgen Krämer <jottkaerr@...> wrote:
      >
      > Hi,
      >
      > J.Hofmann@... wrote:
      >>
      >> I d like to do the following:
      >>
      >> - remember the current value of an option, i.e. 'enc'  , into a variable by
      >> one vim script
      >>
      >> - Doing some stuff, which changes the option
      >>
      >> - re-set the option with the remembered value by another vim script.
      >>
      >> What would be the syntax for this remembering and setting?
      >
      > you can access options as "variables" by prefixing them with an ampersand,
      > e.g.,
      >
      >  let old_enc = &enc
      >  " do some stuff
      >  let &enc = old_enc

      Or, more safely:

      let old_lz = &lazyredraw
      try
      " do some stuff
      finally
      let &lz = old_lz
      endif

      This method guarantees that the setting gets restored, even if the
      code in between exits abnormally through an exception or some such.

      Also, please note that it's not a good idea to change 'enc' once vim
      has started. See the note right above :help 45.4 among other places
      in the help for explanations about why. Historically, changing 'enc'
      in a running vim has been able to trigger crashes, and even now it's
      very likely to break plugins, etc

      ~Matt

      --
      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.