Merge branch 'master' into add_Chiese_version

pull/106/head
Samuel 2 years ago committed by GitHub
commit af2532be7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -648,15 +648,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
@ -959,13 +959,14 @@ vim.api.nvim_buf_del_keymap(0, 'i', '<Tab>')
Neovim provides API functions for user-defined commands:
- Global user commands:
- [`vim.api.nvim_add_user_command()`](<https://neovim.io/doc/user/api.html#nvim_add_user_command()>)
- [`vim.api.nvim_del_user_command()`](<https://neovim.io/doc/user/api.html#nvim_del_user_command()>)
- Buffer-local user commands:
- [`vim.api.nvim_buf_add_user_command()`](<https://neovim.io/doc/user/api.html#nvim_buf_add_user_command()>)
- [`vim.api.nvim_buf_del_user_command()`](<https://neovim.io/doc/user/api.html#nvim_buf_del_user_command()>)
Let's start with `vim.api.nvim_add_user_command()`
Let's start with `vim.api.nvim_create_user_command()`
The first argument passed to this function is the name of the command (which must start with an uppercase letter).
@ -974,7 +975,7 @@ The second argument is the code to execute when invoking said command. It can ei
A string (in which case it will be executed as Vimscript). You can use escape sequences like `<q-args>`, `<range>`, etc. like you would with `:command`
```lua
vim.api.nvim_add_user_command('Upper', 'echo toupper(<q-args>)', { nargs = 1 })
vim.api.nvim_create_user_command('Upper', 'echo toupper(<q-args>)', { nargs = 1 })
-- :command! -nargs=1 Upper echo toupper(<q-args>)
vim.cmd('Upper hello world') -- prints "HELLO WORLD"
@ -983,7 +984,7 @@ vim.cmd('Upper hello world') -- prints "HELLO WORLD"
Or a Lua function. It receives a dictionary-like table that contains the data normally provided by escape sequences (see [`:help nvim_add_user_command()`](<https://neovim.io/doc/user/api.html#nvim_add_user_command()>) for a list of available keys)
```lua
vim.api.nvim_add_user_command(
vim.api.nvim_create_user_command(
'Upper',
function(opts)
print(string.upper(opts.args))
@ -992,7 +993,7 @@ vim.api.nvim_add_user_command(
)
```
The third argument lets you pass command attributes as a table (see [`:help command-attributes`](https://neovim.io/doc/user/map.html#command-attributes)). Since you can already define buffer-local user commands with `vim.api.nvim_buf_add_user_command()`, `-buffer` is not a valid attribute.
The third argument lets you pass command attributes as a table (see [`:help command-attributes`](https://neovim.io/doc/user/map.html#command-attributes)). Since you can already define buffer-local user commands with `vim.api.nvim_buf_create_user_command()`, `-buffer` is not a valid attribute.
Two additional attributes are available:
@ -1002,7 +1003,7 @@ Two additional attributes are available:
The `-complete` attribute can take a Lua function in addition to the attributes listed in [`:help :command-complete`](https://neovim.io/doc/user/map.html#:command-complete).
```lua
vim.api.nvim_add_user_command('Upper', function() end, {
vim.api.nvim_create_user_command('Upper', function() end, {
nargs = 1,
complete = function(ArgLead, CmdLine, CursorPos)
-- return completion candidates as a list-like table
@ -1014,7 +1015,7 @@ vim.api.nvim_add_user_command('Upper', function() end, {
Buffer-local user commands also take a buffer number as their first argument. This is an advantage over `-buffer` which can only define a command for the current buffer.
```lua
vim.api.nvim_buf_add_user_command(4, 'Upper', function() end, {})
vim.api.nvim_buf_create_user_command(4, 'Upper', function() end, {})
```
`vim.api.nvim_del_user_command()` takes a command name.
@ -1033,8 +1034,6 @@ vim.api.nvim_buf_del_user_command(4, 'Upper')
See also:
- [`:help nvim_add_user_command()`](<https://neovim.io/doc/user/api.html#nvim_add_user_command()>)
- [`:help 40.2`](https://neovim.io/doc/user/usr_40.html#40.2)
- [`:help command-attributes`](https://neovim.io/doc/user/map.html#command-attributes)
### Caveats
@ -1056,7 +1055,7 @@ command! -nargs=1 -complete=custom,s:completion_function Test echo <q-args>
Passing a Lua function to `complete` makes it behave like `customlist` which leaves filtering up to the user:
```lua
vim.api.nvim_add_user_command('Test', function() end, {
vim.api.nvim_create_user_command('Test', function() end, {
nargs = 1,
complete = function(ArgLead, CmdLine, CursorPos)
return {
@ -1297,10 +1296,13 @@ Probably one of the most well-known transpilers for Lua. Adds a lots of convenie
A lisp that compiles to Lua. You can write configuration and plugins for Neovim in Fennel with the [Olical/aniseed](https://github.com/Olical/aniseed) or the [Hotpot](https://github.com/rktjmp/hotpot.nvim) plugin. Additionally, the [Olical/conjure](https://github.com/Olical/conjure) plugin provides an interactive development environment that supports Fennel (among other languages).
- [Teal](https://github.com/teal-language/tl)
The name Teal comes from pronouncing TL (typed lua). This is exactly what it tries to do - add strong typing to lua while otherwise remaining close to standard lua syntax. The [nvim-teal-maker](https://github.com/svermeulen/nvim-teal-maker) plugin can be used to write Neovim plugins or configuration files directly in Teal
Other interesting projects:
- [TypeScriptToLua/TypeScriptToLua](https://github.com/TypeScriptToLua/TypeScriptToLua)
- [teal-language/tl](https://github.com/teal-language/tl)
- [Haxe](https://haxe.org/)
- [SwadicalRag/wasm2lua](https://github.com/SwadicalRag/wasm2lua)
- [hengestone/lua-languages](https://github.com/hengestone/lua-languages)

@ -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
@ -1150,13 +1151,13 @@ in Neovim 0.7.0+
Neovim provides API functions for user-defined commands:
- Global user commands:
- |nvim_add_user_command()|
- |nvim_create_user_command()|
- |nvim_del_user_command()|
- Buffer-local user commands:
- |nvim_buf_add_user_command()|
- |nvim_buf_create_user_command()|
- |nvim_buf_del_user_command()|
Let's start with `vim.api.nvim_add_user_command()`
Let's start with `vim.api.nvim_create_user_command()`
The first argument passed to this function is the name of the command
(which must start with an uppercase letter).
@ -1168,17 +1169,18 @@ A string (in which case it will be executed as Vimscript). You can use
escape sequences like `<q-args>`, `<range>`, etc. like you would with
`:command`
>
vim.api.nvim_add_user_command('Upper', 'echo toupper(<q-args>)', {
nargs = 1 })
vim.api.nvim_create_user_command('Upper', 'echo toupper(<q-args>)',
{ nargs = 1 })
-- :command! -nargs=1 Upper echo toupper(<q-args>)
vim.cmd('Upper hello world') -- prints "HELLO WORLD"
<
Or a Lua function. It receives a dictionary-like table that contains the
data normally provided by escape sequences (see |nvim_add_user_command()|
Or a Lua function. It receives a dictionary-like table that
contains the data normally provided by escape sequences (see
|nvim_create_user_command()|
>
vim.api.nvim_add_user_command(
vim.api.nvim_create_user_command(
'Upper',
function(opts)
print(string.upper(opts.args))
@ -1188,7 +1190,8 @@ data normally provided by escape sequences (see |nvim_add_user_command()|
<
The third argument lets you pass command attributes as a table (see
|command-attributes|, `-buffer` is not a valid attribute.
|command-attributes|`. Since you can already define buffer-local user commands
with |nvim_buf_create_user_command()|, `-buffer` is not a valid attribute.
Two additional attributes are available:
- `desc` allows you to control what gets displayed when you run `:command
@ -1201,7 +1204,7 @@ The `-complete` attribute can take a Lua function in addition to the
attributes listed in |:command-complete|.
>
vim.api.nvim_add_user_command('Upper', function() end, {
vim.api.nvim_create_user_command('Upper', function() end, {
nargs = 1,
complete = function(ArgLead, CmdLine, CursorPos)
-- return completion candidates as a list-like table
@ -1215,7 +1218,7 @@ argument. This is an advantage over `-buffer` which can only define a
command for the current buffer.
>
vim.api.nvim_buf_add_user_command(4, 'Upper', function() end, {})
vim.api.nvim_buf_create_user_command(4, 'Upper', function() end, {})
<
`vim.api.nvim_del_user_command()` takes a command name.
@ -1233,7 +1236,7 @@ its first argument, with `0` representing the current buffer.
<
See also:
- |nvim_add_user_command()|
- |nvim_create_user_command()|
- |40.2|
- |command-attributes|
@ -1260,7 +1263,7 @@ Passing a Lua function to `complete` makes it behave like `customlist`
which leaves filtering up to the user:
>
vim.api.nvim_add_user_command('Test', function() end, {
vim.api.nvim_create_user_command('Test', function() end, {
nargs = 1,
complete = function(ArgLead, CmdLine, CursorPos)
return {
@ -1279,27 +1282,25 @@ which leaves filtering up to the user:
DEFINING AUTOCOMMANDS
*luaguide-defining-autocommands*
Augroups and autocommands do not have an interface yet but it is being
worked on:
(this section is a work in progress)
Neovim 0.7.0 has API functions for autocommands. See `:help api-autocmd`
for details
- Pull request #12378: https://github.com/neovim/neovim/pull/12378
- Pull request #14661: https://github.com/neovim/neovim/pull/14661 lua:
autocmds take 2
In the meantime, you can either create autocommands in
Vimscript or use this wrapper from norcalli/nvim_utils:
https://github.com/norcalli/nvim_utils/blob/master/lua/nvim_utils.lua#L554-L567
==============================================================================
DEFINING SYNTAX/HIGHLIGHTS
*luaguide-defining-syntax-highlights*
DEFINING HIGHLIGHTS
*luaguide-defining-highlights*
The syntax API is still a work in progress. Here are a couple of pointers:
(this section is a work in progress)
- Issue #9876: https://github.com/neovim/neovim/issues/9876
- tjdevries/colorbuddy.vim, a library for creating colorschemes in Lua:
https://github.com/tjdevries/colorbuddy.vim
- |lua-treesitter|
Neovim 0.7.0 has API functions for highlight groups. See also:
- |nvim_set_hl()|
- |nvim_get_hl_by_id()|
- |nvim_get_hl_by_name()|
==============================================================================
GENERAL TIPS AND RECOMMENDATIONS
@ -1573,10 +1574,17 @@ Olical/conjure: https://github.com/Olical/conjure plugin provides an
interactive development environment that supports Fennel among other
languages .
- Teal: https://github.com/teal-language/tl
The name Teal comes from pronouncing TL typed lua . This is exactly
what it tries to do - add strong typing to lua while otherwise
remaining close to standard lua syntax. The nvim-teal-maker:
https://github.com/svermeulen/nvim-teal-maker plugin can be used to
write Neovim plugins or configuration files directly in Teal
Other interesting projects:
- TypeScriptToLua/TypeScriptToLua:
https://github.com/TypeScriptToLua/TypeScriptToLua
- teal-language/tl: https://github.com/teal-language/tl
- Haxe: https://haxe.org/
- SwadicalRag/wasm2lua: https://github.com/SwadicalRag/wasm2lua
- hengestone/lua-languages: https://github.com/hengestone/lua-languages

Loading…
Cancel
Save