Home Explore Blog CI



neovim

4th chunk of `runtime/doc/options.txt`
4243d53c17ffd806cfca64d7d3b32a9cbd0e2fa61409fb9a0000000100000fa4
 or buffer
has its own copy of this option, thus each can have its own value.  This
allows you to set 'list' in one window but not in another.  And set
'shiftwidth' to 3 in one buffer and 4 in another.

The following explains what happens to these local options in specific
situations.  You don't really need to know all of this, since Vim mostly uses
the option values you would expect.  Unfortunately, doing what the user
expects is a bit complicated...

When splitting a window, the local options are copied to the new window.  Thus
right after the split the contents of the two windows look the same.

When editing a new buffer, its local option values must be initialized.  Since
the local options of the current buffer might be specifically for that buffer,
these are not used.  Instead, 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.

When editing a buffer that has been edited before, the options from the window
that was last closed are used again.  If this buffer has been edited in this
window, the values from back then are used.  Otherwise the values from the
last closed window where the buffer was edited last are used.

It's possible to set a local window option specifically for a type of buffer.
When you edit another buffer in the same window, you don't want to keep
using these local window options.  Therefore Vim keeps a global value of the
local window options, which is used when editing another buffer.  Each window
has its own copy of these values.  Thus these are local to the window, but
global to all buffers in the window.  With this you can do: >
	:e one
	:set list
	:e two
Now the 'list' option will also be set in "two", since with the ":set list"
command you have also set the global value. >
	:set nolist
	:e one
	:setlocal list
	:e two
Now the 'list' option is not set, because ":set nolist" resets the global
value, ":setlocal list" only changes the local value and ":e two" gets the
global value.  Note that if you do this next: >
	:e one
You will get back the 'list' value as it was the last time you edited "one".
The options local to a window are remembered for each buffer.  This also
happens when the buffer is not loaded, but they are lost when the buffer is
wiped out |:bwipe|.

Special local window options			*local-noglobal*

The following local window options won't be copied over when new windows are
created, thus they behave slightly differently:

	Option		Reason	~
	'previewwindow'	there can only be a single one
	'scroll'	specific to existing window
	'winfixbuf'	specific to existing window
	'winfixheight'	specific to existing window
	'winfixwidth'	specific to existing window

Special local buffer options

The following local buffer options won't be copied over when new buffers are
created, thus they behave slightly differently:

	Option		Reason	~
	'filetype'	explicitly set by autocommands
	'syntax'	explicitly set by autocommands
	'bufhidden'	denote |special-buffers|
	'buftype'	denote |special-buffers|
	'readonly'	will be detected automatically
	'modified'	will be detected automatically

							*:setl* *:setlocal*
:setl[ocal][!] ...	Like ":set" but set only the value local to the
			current buffer or window.  Not all options have a
			local value.  If the option does not have a local
			value the global value is set.
			With the "all" argument: display local values for all
			local options.
			Without argument: Display local values for all local
			options which are different from the default.
			When displaying a specific local option, show the
			local value.  For a global/local boolean option, when
			the global value is being used, "--" is displayed
			before the option name.
			For a global option the global value is
			shown (but that might change in the future).

:se[t] {option}<	Set the effective value of {option}

Title: Detailed Behavior of Local Options in Vim
Summary
This section delves into the specifics of how local options function in Vim, detailing their behavior when splitting windows, editing new buffers, and re-editing existing buffers. It explains the concept of global values for buffer-local options, used for initializing new buffers, and how ':set' and ':setlocal' commands affect these values. It also describes how Vim remembers window-local options for each buffer and mentions special local window and buffer options that behave differently. Lastly, it explains the `:setlocal` command and its usage.