1

:h local-options says:

for each buffer-local option there also is a global value, which is used for
new buffers.  With ":set" both the local and global value is changed.  With
"setlocal" only the local value is changed, thus this value is not used when
editing a new buffer.

:h global-local says:

For some global options it's useful to sometimes have a different local value.
You can set the local value with ":setlocal".  That buffer or window will then
use the local value, while other buffers and windows continue using the global
value.

I am confused by how these are different. It sounds to me like if I say :setlocal on a buffer-local or a global-local option, the setting is set for that particular buffer (assuming the global-local in this case is a "Global or local to buffer" and not a "Global or local to window" option). And if I say :setglobal, the global setting (default for all buffers) is set, and :set sets both global and local options.

The only possible difference I can find in the documentation (and maybe this is the answer?) is that there is special documentation around :set< or :setlocal= for global-local options that lets you erase the local value and fall back to the current global setting. There's no documentation that indicates that buffer-local settings can be unset / fall back to a global value. Is that true? And is that the essence of the difference in these two options?

1

The difference is whether changing the global option will affect existing buffers other than the current one.

With a regular buffer-local option, the local option is set to match the global option when the buffer is created. When you use a :set command, it sets both the global and the buffer-local option (for the current buffer) to the same value.

But since the buffer-local option is always set, changing the global option will only affect new buffers, since existing ones will preserve the existing setting in their buffer-local option.

On the other hand, global-local options will track whether the local option is set or not and will use the global setting if it's not. The local option is only set explicitly with :setlocal, using :set will only affect the global option.

Since by default the local option will be unset, changing the global option will typically affect existing buffers, at least all those which haven't had a local option explicitly set, which is not necessarily all of them, but expected to be the typical case for global-local options.

Yes, using :setlocal with < (for boolean and numeric options) is somewhat special, in that they get unset (stop overriding the global option) rather than copying the global value into the buffer-local variable. Setting string local options to empty is also special in the same way. The documentation might not be too explicit, but this is the way to go back to tracking the global options, using :setlocal with < for boolean and number options, and :setlocal to an empty value for string options.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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