# Scopes

**URL:** <https://discuss.kakoune.com/t/scopes/552>\
**Category:** Manual++\
**Created:** [May 8, 2019, 2:25am UTC](https://discuss.kakoune.com/t/scopes/552 "2019-05-08T02:25:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![robertmeta](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/robertmeta/32/833_2.png) [@robertmeta](https://discuss.kakoune.com/u/robertmeta)\
**Post date:** [May 8, 2019, 2:25am UTC](https://discuss.kakoune.com/t/scopes/552/1 "2019-05-08T02:25:06Z")

</div>

# Description

Scopes are groups in which a particular Kakoune object can have  
different values depending on the group the value was declared in.

These scoped objects are:

- aliases (See [`:doc commands`](https://discuss.kakoune.com/t/commands/538))

- faces (See [`:doc faces`](https://discuss.kakoune.com/t/faces/541))

- highlighters (See [`:doc highlighters`](https://discuss.kakoune.com/t/highlighters/543))

- hooks (See [`:doc hooks`](https://discuss.kakoune.com/t/hooks/544))

- keymaps (See [`:doc mapping`](https://discuss.kakoune.com/t/mappings/547))

- options (See [`:doc options`](https://discuss.kakoune.com/t/options/549))

# Names and hierarchy

Scopes are named as follows:

**window**  
context linked to the window displaying a buffer.

```
In Kakoune, the concept of a *window* must not be confused with
the concept of a window at the OS level.
In other terms, a window is *not* a client (like a terminal or GUI)
but one of many 'views' into a buffer.

There is a N:1 relationship between windows and buffers; once a
window is linked to a buffer, the window's buffer never changes.
Windows store a set of selections and the scroll position.

```

**buffer**  
context linked directly to the buffer

**global**  
global context linked to the instance of Kakoune

The following order of priority applies to the above scopes:

```
window ]> buffer ]> global

```

The above priority line implies that objects can have individual values  
that will be resolved first in the **window** scope (highest priority),  
then in the **buffer** scope, and finally in the **global** scope  
(lowest priority).

Normally, the **buffer** scope keyword means the scope associated with  
the currently active buffer, but it’s possible to specify any existing  
buffer by adding an `=` and the value of `%val{buffile}` for that buffer  
(See  
[`:doc expansions value-expansions`](https://discuss.kakoune.com/t/expansions/540#value-expansions)). For  
example, to set the `indentwidth` option for the `/etc/fstab` buffer::

```
set-option buffer=/etc/fstab indentwidth 8

```

The `set-option` and `unset-option` commands also accept **current** as  
a valid scope name. It refers to the narrowest scope the option is set  
in.

# Uses

The scope paradigm is very useful as it allows the user to customize the  
behavior of the editor without modifying the configuration globally, as  
is the case with other editors who only have a single **global** scope  
by default.

Examples:

**filetype**  
A single buffer opened in two separate windows can have different  
filetypes declared in the **window** scope with _set-option_. (See  
[`:doc options`](https://discuss.kakoune.com/t/expansions/540))

**status line**  
All the buffers of the current session can have the same information  
displayed in the status line, except for a specific buffer (the  
_modelinefmt_ option can be declared in the **global** scope, and  
customized in the **buffer** scope with _set-option_. (See  
[`:doc options`](https://discuss.kakoune.com/t/expansions/540))

# Execution context

Some commands work in a specific context that might exclude one or  
several scopes altogether, consequently ignoring some values of a given  
object.

Example: the **window** scope is never considered when resolving the  
values of options when writing a buffer (e.g. _BOM_, _eolformat_).
