A few meta-accessors are available if you want to set options in a more "idiomatic" way. They essentially wrap the above API functions and allow you to manipulate options as if they were variables:
- `vim.o.{option}`: global options
- `vim.bo.{option}`: buffer-local options
- `vim.wo.{option}`: window-local options
```lua
vim.o.smarttab = false
print(vim.o.smarttab) -- false
vim.bo.shiftwidth = 4
print(vim.bo.shiftwidth) -- 4
```
See also:
- `:help lua-vim-internal-options`
#### Caveats
If you've only ever dealt with options using the `:set` command, the behavior of some options might surprise you.
Essentially, options can either be global, local to a buffer/window, or have both a global AND a local value.
The `:setglobal` command sets the global value of an option.
The `:setlocal` command sets the local value of an option.
The `:set` command sets the global AND local value of an option.
There is no equivalent to the `:set` command in Lua, you either set an option globally or locally.
You might expect the `number` option to be global, but the documentation describes it as being "local to window". Such options are actually "sticky": if you set the option in a given window, it sets it for the current window and it becomes the value for every subsequent window you open.
So if you were to set the option from your `init.lua`, you would do it like so:
```lua
vim.wo.number = true
```
Options that are "local to buffer" like `shiftwidth`, `expandtab` or `undofile` are even more confusing. Let's say your `init.lua` contains the following code:
```lua
vim.bo.expandtab = true
```
When you launch Neovim and start editing, everything is fine: pressing `<Tab>` inserts spaces instead of a tab character. Open another buffer and you're suddenly back to tabs...
Setting it globally has the opposite problem:
```lua
vim.o.expandtab = true
```
This time, you insert tabs when you first launch Neovim. Open another buffer and pressing `<Tab>` does what you expect.
In short, options that are "local to buffer" have to be set like this if you want them to be global-local: