clarify behavior of vim.o etc

references https://github.com/nanotee/nvim-lua-guide/issues/105
pull/106/head^2
Timothée Sterle 2 years ago
parent 18cb58e57c
commit be74c1a1aa
No known key found for this signature in database
GPG Key ID: 136D558122196ED5

@ -642,15 +642,15 @@ print(vim.api.nvim_buf_get_option(10, 'shiftwidth')) -- 4
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`](https://neovim.io/doc/user/lua.html#vim.o): behaves like `:set`
- [`vim.go`](https://neovim.io/doc/user/lua.html#vim.go): behaves like `:setglobal`
- [`vim.bo`](https://neovim.io/doc/user/lua.html#vim.bo): behaves like `:setlocal` for buffer-local options
- [`vim.wo`](https://neovim.io/doc/user/lua.html#vim.wo): behaves like `:setlocal` for window-local options
- [`vim.o`](https://neovim.io/doc/user/lua.html#vim.o): behaves like `:let &{option-name}`
- [`vim.go`](https://neovim.io/doc/user/lua.html#vim.go): behaves like `:let &g:{option-name}`
- [`vim.bo`](https://neovim.io/doc/user/lua.html#vim.bo): behaves like `:let &l:{option-name}` for buffer-local options
- [`vim.wo`](https://neovim.io/doc/user/lua.html#vim.wo): behaves like `:let &l:{option-name}` for window-local options
```lua
vim.o.smarttab = false
vim.o.smarttab = false -- let &smarttab = v:false
print(vim.o.smarttab) -- false
vim.o.isfname = vim.o.isfname .. ',@-@' -- on Linux: set isfname+=@-@
vim.o.isfname = vim.o.isfname .. ',@-@' -- on Linux: let &isfname = &isfname .. ',@-@'
print(vim.o.isfname) -- '@,48-57,/,.,-,_,+,,,#,$,%,~,=,@-@'
vim.bo.shiftwidth = 4

@ -778,15 +778,16 @@ 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|: behaves like `:set`
- |vim.go|: behaves like `:setglobal`
- |vim.bo|: behaves like `:setlocal` for buffer-local options
- |vim.wo|: behaves like `:setlocal` for window-local options
- |vim.o|: behaves like `:let &{option-name}`
- |vim.go|: behaves like `:let &g:{option-name}`
- |vim.bo|: behaves like `:let &l:{option-name}` for buffer-local options
- |vim.wo|: behaves like `:let &l:{option-name}` for window-local options
>
vim.o.smarttab = false
vim.o.smarttab = false -- let &smarttab = v:false
print(vim.o.smarttab) -- false
vim.o.isfname = vim.o.isfname .. ',@-@' -- on Linux: set isfname+=@-@
vim.o.isfname = vim.o.isfname .. ',@-@' -- on Linux: let &isfname =
&isfname .. ',@-@'
print(vim.o.isfname) -- '@,48-57,/,.,-,_,+,,,#,$,%,~,=,@-@'
vim.bo.shiftwidth = 4

Loading…
Cancel
Save