Thursday, August 1, 2019

Re: setglobal, setlocal, set confusion

On Thu, Aug 1, 2019 at 2:49 PM Kai Weber <kai.weber@glorybox.de> wrote:
>
> I found out about 'setglobal' and read the documentation. It seems I am
> still confused and think that 'set' is more global than 'setglobal'
> despite the name suggests.
>
> I tried to set my spelllang with setglobal
>
> setglobal spelllang=en,de
>
> But I found that the spelling in my buffer did not checked for german
> spelling problems.
>
> :verbose set spellang
> spellang=en
>
> But
>
> :verbose setglobal spellang
> spelllang=en,de
> Last set from ~/.vim/plugin/settings.vim line 34
>
> So, I have to use 'set' instead of 'setglobal' to set spelllang
> globally? What is a reasonable use case to use 'setglobal'?
>
> Kai

- ":setlocal option=value" sets only the local value of an option (for
the current buffer or window) without messing with the global default
- ":setglobal option=value" sets only the global default without
messing with any local value, not even the one in the current buffer
or window
- ":set option=value" sets both.

When displaying the existing setting, ":setglobal option?" displays
the global default, ":set option?" and ":setlocal option?" _both_
display the actual setting in the current buffer or window.

However, for global settings, :set, :setlocal and :setglobal all set
(or display) the global (and only) setting, with no error.

One setting I use in my vimrc is "setglobal fenc=utf-8 bomb" to set
'fileencoding' and 'bomb' to UTF-8 with BOM for new files. My new
files are usually HTML files and that setting suits me, it might be
unsuitable for some other people, for whom "setglobal fenc=utf-8
nobomb" might be better. The idea of using :setglobal is in order to
set the option only for future files for which the same options are
not set by some other mechanism (e.g., on existing files, the
'fileencodings' [plural] heuristic sets 'fileencoding' [singular] to
what it thinks is the file's charset, and it sets 'bomb' or 'nobomb'
for Unicode files depending on what was found at the very beginning of
the file, bypassing any global default). :setglobal does nothing to
already open files and that is what I want.

Best regards,
Tony.

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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CAJkCKXv1_mEGJVFk-2s7yB8Z1nX8_7Cf_uS6FKXU9D%3D5%3DNzu-w%40mail.gmail.com.

No comments:

Post a Comment