1

When working with options that often have complex or calculated string values (e.g. formatprg, which might have additional parameters, separated by whitespace), it's often easier to use let to set them, i.e. let &option='complex stuff' rather than set option=complex\ stuff.

However, for options which are buffer or window-local, is there is a let equivalent which only sets the local value? setlocal does always, if the option supports a local value. However, the & prefix for options used with let does not appear to. The docs for let say:

For an option local to a window or buffer the effect
is just like using the |:set| command: both the local
value and the global value are changed.

2 Answers 2

4

Yes.

For a local buffer/window option, you can use:

let &l:option = 'complex value'

And you can also be explicit about a global option, with:

let &g:option = 'complex value'

See :help :let-option, which includes:

:let &l:{option-name} = {expr1}

Like above, but only set the local value of an option (if there is one). Works like :setlocal.

:let &g:{option-name} = {expr1}

Like above, but only set the global value of an option (if there is one). Works like :setglobal.

4

Sorry, but I very quickly answered my own question, hadn't read far enough down in the docs! let &l:option='value' will set the local value, with let &g:option='value' explicitly setting the global value.

1
  • 2
    For variables: b: for buffer, w: for window scope
    – D. Ben Knoble
    Commented May 19, 2020 at 18:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.