diff options
| author | Gregory Anders <8965202+gpanders@users.noreply.github.com> | 2023-09-14 08:23:01 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-14 08:23:01 -0500 |
| commit | 2e92065686f62851318150a315591c30b8306a4b (patch) | |
| tree | 3d4d216f7b031cd2e966380f9b32d1aae472d32f /runtime/doc | |
| parent | 9fc321c9768d1a18893e14f46b0ebacef1be1db4 (diff) | |
| download | rneovim-2e92065686f62851318150a315591c30b8306a4b.tar.gz rneovim-2e92065686f62851318150a315591c30b8306a4b.tar.bz2 rneovim-2e92065686f62851318150a315591c30b8306a4b.zip | |
docs: replace <pre> with ``` (#25136)
Diffstat (limited to 'runtime/doc')
| -rw-r--r-- | runtime/doc/api.txt | 75 | ||||
| -rw-r--r-- | runtime/doc/develop.txt | 7 | ||||
| -rw-r--r-- | runtime/doc/diagnostic.txt | 18 | ||||
| -rw-r--r-- | runtime/doc/lsp.txt | 147 | ||||
| -rw-r--r-- | runtime/doc/lua.txt | 751 | ||||
| -rw-r--r-- | runtime/doc/options.txt | 2 | ||||
| -rw-r--r-- | runtime/doc/treesitter.txt | 71 |
7 files changed, 498 insertions, 573 deletions
diff --git a/runtime/doc/api.txt b/runtime/doc/api.txt index 34e2aedabf..ffd90ec3d7 100644 --- a/runtime/doc/api.txt +++ b/runtime/doc/api.txt @@ -1791,9 +1791,9 @@ nvim_create_user_command({name}, {command}, {*opts}) For Lua usage see |lua-guide-commands-create|. Example: >vim - :call nvim_create_user_command('SayHello', 'echo "Hello world!"', {'bang': v:true}) - :SayHello - Hello world! + :call nvim_create_user_command('SayHello', 'echo "Hello world!"', {'bang': v:true}) + :SayHello + Hello world! < Parameters: ~ @@ -2041,10 +2041,14 @@ whether a buffer is loaded. nvim_buf_attach({buffer}, {send_buffer}, {opts}) *nvim_buf_attach()* Activates buffer-update events on a channel, or as Lua callbacks. - Example (Lua): capture buffer updates in a global `events` variable (use "vim.print(events)" to see its contents): >lua - events = {} - vim.api.nvim_buf_attach(0, false, { - on_lines=function(...) table.insert(events, {...}) end}) + Example (Lua): capture buffer updates in a global `events` variable (use + "vim.print(events)" to see its contents): >lua + events = {} + vim.api.nvim_buf_attach(0, false, { + on_lines = function(...) + table.insert(events, {...}) + end, + }) < Parameters: ~ @@ -2553,8 +2557,8 @@ nvim_buf_get_extmarks({buffer}, {ns_id}, {start}, {end}, {*opts}) Region can be given as (row,col) tuples, or valid extmark ids (whose positions define the bounds). 0 and -1 are understood as (0,0) and (-1,-1) respectively, thus the following are equivalent: >lua - vim.api.nvim_buf_get_extmarks(0, my_ns, 0, -1, {}) - vim.api.nvim_buf_get_extmarks(0, my_ns, {0,0}, {-1,-1}, {}) + vim.api.nvim_buf_get_extmarks(0, my_ns, 0, -1, {}) + vim.api.nvim_buf_get_extmarks(0, my_ns, {0,0}, {-1,-1}, {}) < If `end` is less than `start`, traversal works backwards. (Useful with @@ -2565,18 +2569,18 @@ nvim_buf_get_extmarks({buffer}, {ns_id}, {start}, {end}, {*opts}) an extmark will be considered. Example: >lua - local api = vim.api - local pos = api.nvim_win_get_cursor(0) - local ns = api.nvim_create_namespace('my-plugin') - -- Create new extmark at line 1, column 1. - local m1 = api.nvim_buf_set_extmark(0, ns, 0, 0, {}) - -- Create new extmark at line 3, column 1. - local m2 = api.nvim_buf_set_extmark(0, ns, 2, 0, {}) - -- Get extmarks only from line 3. - local ms = api.nvim_buf_get_extmarks(0, ns, {2,0}, {2,0}, {}) - -- Get all marks in this buffer + namespace. - local all = api.nvim_buf_get_extmarks(0, ns, 0, -1, {}) - vim.print(ms) + local api = vim.api + local pos = api.nvim_win_get_cursor(0) + local ns = api.nvim_create_namespace('my-plugin') + -- Create new extmark at line 1, column 1. + local m1 = api.nvim_buf_set_extmark(0, ns, 0, 0, {}) + -- Create new extmark at line 3, column 1. + local m2 = api.nvim_buf_set_extmark(0, ns, 2, 0, {}) + -- Get extmarks only from line 3. + local ms = api.nvim_buf_get_extmarks(0, ns, {2,0}, {2,0}, {}) + -- Get all marks in this buffer + namespace. + local all = api.nvim_buf_get_extmarks(0, ns, 0, -1, {}) + vim.print(ms) < Parameters: ~ @@ -3062,6 +3066,7 @@ nvim_open_win({buffer}, {enter}, {*config}) *nvim_open_win()* Example (Lua): buffer-relative float (travels as buffer is scrolled) >lua vim.api.nvim_open_win(0, false, {relative='win', width=12, height=3, bufpos={100,10}}) + }) < Attributes: ~ @@ -3340,9 +3345,9 @@ nvim_create_autocmd({event}, {*opts}) *nvim_create_autocmd()* }) < - Note: `pattern` is NOT automatically expanded (unlike with |:autocmd|), thus names like - "$HOME" and "~" must be expanded explicitly: >lua - pattern = vim.fn.expand("~") .. "/some/path/*.py" + Note: `pattern` is NOT automatically expanded (unlike with |:autocmd|), + thus names like "$HOME" and "~" must be expanded explicitly: >lua + pattern = vim.fn.expand("~") .. "/some/path/*.py" < Parameters: ~ @@ -3447,17 +3452,17 @@ nvim_get_autocmds({*opts}) *nvim_get_autocmds()* Get all autocommands that match the corresponding {opts}. These examples will get autocommands matching ALL the given criteria: >lua - -- Matches all criteria - autocommands = vim.api.nvim_get_autocmds({ - group = "MyGroup", - event = {"BufEnter", "BufWinEnter"}, - pattern = {"*.c", "*.h"} - }) - - -- All commands from one group - autocommands = vim.api.nvim_get_autocmds({ - group = "MyGroup", - }) + -- Matches all criteria + autocommands = vim.api.nvim_get_autocmds({ + group = "MyGroup", + event = {"BufEnter", "BufWinEnter"}, + pattern = {"*.c", "*.h"} + }) + + -- All commands from one group + autocommands = vim.api.nvim_get_autocmds({ + group = "MyGroup", + }) < NOTE: When multiple patterns or events are provided, it will find all the diff --git a/runtime/doc/develop.txt b/runtime/doc/develop.txt index 0ed537c248..71c16659eb 100644 --- a/runtime/doc/develop.txt +++ b/runtime/doc/develop.txt @@ -238,7 +238,7 @@ Docstring format: `---@see`, `---@param`, `---@returns` - Limited markdown is supported. - List-items start with `-` (useful to nest or "indent") -- Use `<pre>` for code samples. +- Use ``` for code samples. Code samples can be annotated as `vim` or `lua` - Use `@nodoc` to prevent documentation generation. - Files which has `@meta` are only used for typing and documentation. @@ -250,12 +250,13 @@ vim.paste in runtime/lua/vim/_editor.lua like this: > --- (such as the |TUI|) pastes text into the editor. --- --- Example: To remove ANSI color codes when pasting: - --- <pre>lua + --- + --- ```lua --- vim.paste = (function() --- local overridden = vim.paste --- ... --- end)() - --- </pre> + --- ``` --- ---@see |paste| --- diff --git a/runtime/doc/diagnostic.txt b/runtime/doc/diagnostic.txt index 866c32722a..e9ca9ee347 100644 --- a/runtime/doc/diagnostic.txt +++ b/runtime/doc/diagnostic.txt @@ -359,13 +359,11 @@ config({opts}, {namespace}) *vim.diagnostic.config()* followed by namespace configuration, and finally global configuration. For example, if a user enables virtual text globally with >lua - - vim.diagnostic.config({ virtual_text = true }) + vim.diagnostic.config({ virtual_text = true }) < and a diagnostic producer sets diagnostics with >lua - - vim.diagnostic.set(ns, 0, diagnostics, { virtual_text = false }) + vim.diagnostic.set(ns, 0, diagnostics, { virtual_text = false }) < then virtual text will not be enabled for those diagnostics. @@ -608,16 +606,14 @@ match({str}, {pat}, {groups}, {severity_map}, {defaults}) Parse a diagnostic from a string. For example, consider a line of output from a linter: > - - WARNING filename:27:3: Variable 'foo' does not exist + WARNING filename:27:3: Variable 'foo' does not exist < This can be parsed into a diagnostic |diagnostic-structure| with: >lua - - local s = "WARNING filename:27:3: Variable 'foo' does not exist" - local pattern = "^(%w+) %w+:(%d+):(%d+): (.+)$" - local groups = { "severity", "lnum", "col", "message" } - vim.diagnostic.match(s, pattern, groups, { WARNING = vim.diagnostic.WARN }) + local s = "WARNING filename:27:3: Variable 'foo' does not exist" + local pattern = "^(%w+) %w+:(%d+):(%d+): (.+)$" + local groups = { "severity", "lnum", "col", "message" } + vim.diagnostic.match(s, pattern, groups, { WARNING = vim.diagnostic.WARN }) < Parameters: ~ diff --git a/runtime/doc/lsp.txt b/runtime/doc/lsp.txt index 29c08fb32d..5103cc223f 100644 --- a/runtime/doc/lsp.txt +++ b/runtime/doc/lsp.txt @@ -901,12 +901,11 @@ start({config}, {opts}) *vim.lsp.start()* the current buffer to the client. Example: >lua - - vim.lsp.start({ - name = 'my-server-name', - cmd = {'name-of-language-server-executable'}, - root_dir = vim.fs.dirname(vim.fs.find({'pyproject.toml', 'setup.py'}, { upward = true })[1]), - }) + vim.lsp.start({ + name = 'my-server-name', + cmd = {'name-of-language-server-executable'}, + root_dir = vim.fs.dirname(vim.fs.find({'pyproject.toml', 'setup.py'}, { upward = true })[1]), + }) < See |vim.lsp.start_client()| for all available options. The most important @@ -1078,9 +1077,9 @@ status() *vim.lsp.status()* stop_client({client_id}, {force}) *vim.lsp.stop_client()* Stops a client(s). - You can also use the `stop()` function on a |vim.lsp.client| object. To stop all clients: >lua - - vim.lsp.stop_client(vim.lsp.get_clients()) + You can also use the `stop()` function on a |vim.lsp.client| object. To + stop all clients: >lua + vim.lsp.stop_client(vim.lsp.get_clients()) < By default asks the server to shutdown, unless stop was requested already @@ -1196,10 +1195,10 @@ definition({options}) *vim.lsp.buf.definition()* document_highlight() *vim.lsp.buf.document_highlight()* Send request to the server to resolve document highlights for the current text document position. This request can be triggered by a key mapping or - by events such as `CursorHold` , e.g.: >vim - autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight() - autocmd CursorHoldI <buffer> lua vim.lsp.buf.document_highlight() - autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references() + by events such as `CursorHold`, e.g.: >vim + autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight() + autocmd CursorHoldI <buffer> lua vim.lsp.buf.document_highlight() + autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references() < Note: Usage of |vim.lsp.buf.document_highlight()| requires the following @@ -1242,12 +1241,12 @@ format({options}) *vim.lsp.buf.format()* buffer (0). • filter (function|nil): Predicate used to filter clients. Receives a client as argument and must return a boolean. - Clients matching the predicate are included. Example: • >lua + Clients matching the predicate are included. Example: >lua - -- Never request typescript-language-server for formatting - vim.lsp.buf.format { - filter = function(client) return client.name ~= "tsserver" end - } + -- Never request typescript-language-server for formatting + vim.lsp.buf.format { + filter = function(client) return client.name ~= "tsserver" end + } < • async boolean|nil If true the method won't block. Defaults to false. Editing the buffer while formatting @@ -1366,24 +1365,23 @@ on_diagnostic({_}, {result}, {ctx}, {config}) See |vim.diagnostic.config()| for configuration options. Handler-specific configuration can be set using |vim.lsp.with()|: >lua - - vim.lsp.handlers["textDocument/diagnostic"] = vim.lsp.with( - vim.lsp.diagnostic.on_diagnostic, { - -- Enable underline, use default values - underline = true, - -- Enable virtual text, override spacing to 4 - virtual_text = { - spacing = 4, - }, - -- Use a function to dynamically turn signs off - -- and on, using buffer local variables - signs = function(namespace, bufnr) - return vim.b[bufnr].show_signs == true - end, - -- Disable a feature - update_in_insert = false, - } - ) + vim.lsp.handlers["textDocument/diagnostic"] = vim.lsp.with( + vim.lsp.diagnostic.on_diagnostic, { + -- Enable underline, use default values + underline = true, + -- Enable virtual text, override spacing to 4 + virtual_text = { + spacing = 4, + }, + -- Use a function to dynamically turn signs off + -- and on, using buffer local variables + signs = function(namespace, bufnr) + return vim.b[bufnr].show_signs == true + end, + -- Disable a feature + update_in_insert = false, + } + ) < Parameters: ~ @@ -1395,24 +1393,23 @@ on_publish_diagnostics({_}, {result}, {ctx}, {config}) See |vim.diagnostic.config()| for configuration options. Handler-specific configuration can be set using |vim.lsp.with()|: >lua - - vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with( - vim.lsp.diagnostic.on_publish_diagnostics, { - -- Enable underline, use default values - underline = true, - -- Enable virtual text, override spacing to 4 - virtual_text = { - spacing = 4, - }, - -- Use a function to dynamically turn signs off - -- and on, using buffer local variables - signs = function(namespace, bufnr) - return vim.b[bufnr].show_signs == true - end, - -- Disable a feature - update_in_insert = false, - } - ) + vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with( + vim.lsp.diagnostic.on_publish_diagnostics, { + -- Enable underline, use default values + underline = true, + -- Enable virtual text, override spacing to 4 + virtual_text = { + spacing = 4, + }, + -- Use a function to dynamically turn signs off + -- and on, using buffer local variables + signs = function(namespace, bufnr) + return vim.b[bufnr].show_signs == true + end, + -- Disable a feature + update_in_insert = false, + } + ) < Parameters: ~ @@ -1457,7 +1454,7 @@ refresh() *vim.lsp.codelens.refresh()* It is recommended to trigger this using an autocmd or via keymap. Example: >vim - autocmd BufEnter,CursorHold,InsertLeave <buffer> lua vim.lsp.codelens.refresh() + autocmd BufEnter,CursorHold,InsertLeave <buffer> lua vim.lsp.codelens.refresh() < run() *vim.lsp.codelens.run()* @@ -1534,8 +1531,7 @@ start({bufnr}, {client_id}, {opts}) *vim.lsp.semantic_tokens.start()* server that supports it, you can delete the semanticTokensProvider table from the {server_capabilities} of your client in your |LspAttach| callback or your configuration's `on_attach` callback: >lua - - client.server_capabilities.semanticTokensProvider = nil + client.server_capabilities.semanticTokensProvider = nil < Parameters: ~ @@ -1565,15 +1561,14 @@ Lua module: vim.lsp.handlers *lsp-handlers* hover({_}, {result}, {ctx}, {config}) *vim.lsp.handlers.hover()* |lsp-handler| for the method "textDocument/hover" >lua - - vim.lsp.handlers["textDocument/hover"] = vim.lsp.with( - vim.lsp.handlers.hover, { - -- Use a sharp border with `FloatBorder` highlights - border = "single", - -- add the title in hover float window - title = "hover" - } - ) + vim.lsp.handlers["textDocument/hover"] = vim.lsp.with( + vim.lsp.handlers.hover, { + -- Use a sharp border with `FloatBorder` highlights + border = "single", + -- add the title in hover float window + title = "hover" + } + ) < Parameters: ~ @@ -1585,18 +1580,20 @@ hover({_}, {result}, {ctx}, {config}) *vim.lsp.handlers.hover()* *vim.lsp.handlers.signature_help()* signature_help({_}, {result}, {ctx}, {config}) - |lsp-handler| for the method "textDocument/signatureHelp". The active - parameter is highlighted with |hl-LspSignatureActiveParameter|. >lua - - vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with( - vim.lsp.handlers.signature_help, { - -- Use a sharp border with `FloatBorder` highlights - border = "single" - } - ) + |lsp-handler| for the method "textDocument/signatureHelp". + + The active parameter is highlighted with |hl-LspSignatureActiveParameter|. >lua + vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with( + vim.lsp.handlers.signature_help, { + -- Use a sharp border with `FloatBorder` highlights + border = "single" + } + ) < Parameters: ~ + • {result} (table) Response from the language server + • {ctx} (table) Client context • {config} (table) Configuration table. • border: (default=nil) • Add borders to the floating window diff --git a/runtime/doc/lua.txt b/runtime/doc/lua.txt index c7f5a292e7..6cfec45523 100644 --- a/runtime/doc/lua.txt +++ b/runtime/doc/lua.txt @@ -582,17 +582,20 @@ VIM.HIGHLIGHT *vim.highlight* Nvim includes a function for highlighting a selection on yank. -To enable it, add the following to your `init.vim` : >vim +To enable it, add the following to your `init.vim`: >vim au TextYankPost * silent! lua vim.highlight.on_yank() + < You can customize the highlight group and the duration of the highlight via: >vim au TextYankPost * silent! lua vim.highlight.on_yank {higroup="IncSearch", timeout=150} + < If you want to exclude visual selections from highlighting on yank, use: >vim au TextYankPost * silent! lua vim.highlight.on_yank {on_visual=false} + < vim.highlight.on_yank({opts}) *vim.highlight.on_yank()* @@ -688,19 +691,18 @@ vim.diff({a}, {b}, {opts}) *vim.diff()* either directly or via callback arguments, are 1-based. Examples: >lua + vim.diff('a\n', 'b\nc\n') + -- => + -- @@ -1 +1,2 @@ + -- -a + -- +b + -- +c - vim.diff('a\n', 'b\nc\n') - -- => - -- @ -1 +1,2 @ - -- -a - -- +b - -- +c - - vim.diff('a\n', 'b\nc\n', {result_type = 'indices'}) - -- => - -- { - -- {1, 1, 1, 2} - -- } + vim.diff('a\n', 'b\nc\n', {result_type = 'indices'}) + -- => + -- { + -- {1, 1, 1, 2} + -- } < Parameters: ~ @@ -781,16 +783,18 @@ vim.json.decode({str}, {opts}) *vim.json.decode()* • Decodes empty array as `{}` (empty Lua table). Example: >lua - - :lua vim.print(vim.json.decode('{"bar":[],"foo":{},"zub":null}')) - --> { bar = {}, foo = vim.empty_dict(), zub = vim.NIL } - - < Parameters: ~ • {str} Stringified JSON data. • {opts} Options map keys: • - luanil: { object: bool, array: bool } • `luanil.object=true` converts `null` in JSON objects to Lua `nil` instead of `vim.NIL` . • `luanil.array=true` converts `null` in JSON arrays to Lua `nil` instead of `vim.NIL` . + vim.print(vim.json.decode('{"bar":[],"foo":{},"zub":null}')) + -- { bar = {}, foo = vim.empty_dict(), zub = vim.NIL } +< Parameters: ~ - • {str} (string) - • {opts} table<string,|nil any> + • {str} (string) Stringified JSON data. + • {opts} table<string,any>|nil Options table with keys: + • luanil: (table) Table with keys: + • object: (boolean) When true, converts `null` in JSON + objects to Lua `nil` instead of |vim.NIL|. + • array: (boolean) When true, converts `null` in JSON arrays + to Lua `nil` instead of |vim.NIL|. Return: ~ any @@ -817,12 +821,11 @@ vim.spell.check({str}) *vim.spell.check()* the buffer. Consider calling this with |nvim_buf_call()|. Example: >lua - - vim.spell.check("the quik brown fox") - -- => - -- { - -- {'quik', 'bad', 5} - -- } + vim.spell.check("the quik brown fox") + -- => + -- { + -- {'quik', 'bad', 5} + -- } < Parameters: ~ @@ -978,14 +981,13 @@ vim.str_utf_end({str}, {index}) *vim.str_utf_end()* (character) that {index} points to. Examples: >lua + -- The character 'æ' is stored as the bytes '\xc3\xa6' (using UTF-8) - -- The character 'æ' is stored as the bytes '\xc3\xa6' (using UTF-8) - - -- Returns 0 because the index is pointing at the last byte of a character - vim.str_utf_end('æ', 2) + -- Returns 0 because the index is pointing at the last byte of a character + vim.str_utf_end('æ', 2) - -- Returns 1 because the index is pointing at the penultimate byte of a character - vim.str_utf_end('æ', 1) + -- Returns 1 because the index is pointing at the penultimate byte of a character + vim.str_utf_end('æ', 1) < Parameters: ~ @@ -1015,14 +1017,13 @@ vim.str_utf_start({str}, {index}) *vim.str_utf_start()* character. Examples: >lua + -- The character 'æ' is stored as the bytes '\xc3\xa6' (using UTF-8) - -- The character 'æ' is stored as the bytes '\xc3\xa6' (using UTF-8) + -- Returns 0 because the index is pointing at the first byte of a character + vim.str_utf_start('æ', 1) - -- Returns 0 because the index is pointing at the first byte of a character - vim.str_utf_start('æ', 1) - - -- Returns -1 because the index is pointing at the second byte of a character - vim.str_utf_start('æ', 2) + -- Returns -1 because the index is pointing at the second byte of a character + vim.str_utf_start('æ', 2) < Parameters: ~ @@ -1080,20 +1081,19 @@ vim.ui_attach({ns}, {options}, {callback}) *vim.ui_attach()* likewise experimental). Example (stub for a |ui-popupmenu| implementation): >lua - - ns = vim.api.nvim_create_namespace('my_fancy_pum') - - vim.ui_attach(ns, {ext_popupmenu=true}, function(event, ...) - if event == "popupmenu_show" then - local items, selected, row, col, grid = ... - print("display pum ", #items) - elseif event == "popupmenu_select" then - local selected = ... - print("selected", selected) - elseif event == "popupmenu_hide" then - print("FIN") - end - end) + ns = vim.api.nvim_create_namespace('my_fancy_pum') + + vim.ui_attach(ns, {ext_popupmenu=true}, function(event, ...) + if event == "popupmenu_show" then + local items, selected, row, col, grid = ... + print("display pum ", #items) + elseif event == "popupmenu_select" then + local selected = ... + print("selected", selected) + elseif event == "popupmenu_hide" then + print("FIN") + end + end) < Parameters: ~ @@ -1116,27 +1116,26 @@ vim.wait({time}, {callback}, {interval}, {fast_only}) *vim.wait()* time. Examples: >lua + --- + -- Wait for 100 ms, allowing other events to process + vim.wait(100, function() end) - --- - -- Wait for 100 ms, allowing other events to process - vim.wait(100, function() end) + --- + -- Wait for 100 ms or until global variable set. + vim.wait(100, function() return vim.g.waiting_for_var end) - --- - -- Wait for 100 ms or until global variable set. - vim.wait(100, function() return vim.g.waiting_for_var end) + --- + -- Wait for 1 second or until global variable set, checking every ~500 ms + vim.wait(1000, function() return vim.g.waiting_for_var end, 500) - --- - -- Wait for 1 second or until global variable set, checking every ~500 ms - vim.wait(1000, function() return vim.g.waiting_for_var end, 500) + --- + -- Schedule a function to set a value in 100ms + vim.defer_fn(function() vim.g.timer_result = true end, 100) - --- - -- Schedule a function to set a value in 100ms - vim.defer_fn(function() vim.g.timer_result = true end, 100) - - -- Would wait ten seconds if results blocked. Actually only waits 100 ms - if vim.wait(10000, function() return vim.g.timer_result end) then - print('Only waiting a little bit of time!') - end + -- Would wait ten seconds if results blocked. Actually only waits 100 ms + if vim.wait(10000, function() return vim.g.timer_result end) then + print('Only waiting a little bit of time!') + end < Parameters: ~ @@ -1171,6 +1170,7 @@ Lua list: >lua local list = { 1, 2, 3 } vim.fn.remove(list, 0) vim.print(list) --> "{ 1, 2, 3 }" + < vim.call({func}, {...}) *vim.call()* @@ -1430,13 +1430,12 @@ vim.bo *vim.bo* print(vim.bo.baz) -- error: invalid key < - Parameters: ~ - • {bufnr} (integer|nil) - vim.env *vim.env* Environment variables defined in the editor session. See |expand-env| and |:let-environment| for the Vimscript behavior. Invalid or unset key - returns `nil` . Example: >lua + returns `nil`. + + Example: >lua vim.env.FOO = 'bar' print(vim.env.TERM) < @@ -1497,31 +1496,30 @@ vim.cmd *vim.cmd()* callable function to the command. Example: >lua + vim.cmd('echo 42') + vim.cmd([[ + augroup My_group + autocmd! + autocmd FileType c setlocal cindent + augroup END + ]]) - vim.cmd('echo 42') - vim.cmd([[ - augroup My_group - autocmd! - autocmd FileType c setlocal cindent - augroup END - ]]) + -- Ex command :echo "foo" + -- Note string literals need to be double quoted. + vim.cmd('echo "foo"') + vim.cmd { cmd = 'echo', args = { '"foo"' } } + vim.cmd.echo({ args = { '"foo"' } }) + vim.cmd.echo('"foo"') - -- Ex command :echo "foo" - -- Note string literals need to be double quoted. - vim.cmd('echo "foo"') - vim.cmd { cmd = 'echo', args = { '"foo"' } } - vim.cmd.echo({ args = { '"foo"' } }) - vim.cmd.echo('"foo"') + -- Ex command :write! myfile.txt + vim.cmd('write! myfile.txt') + vim.cmd { cmd = 'write', args = { "myfile.txt" }, bang = true } + vim.cmd.write { args = { "myfile.txt" }, bang = true } + vim.cmd.write { "myfile.txt", bang = true } - -- Ex command :write! myfile.txt - vim.cmd('write! myfile.txt') - vim.cmd { cmd = 'write', args = { "myfile.txt" }, bang = true } - vim.cmd.write { args = { "myfile.txt" }, bang = true } - vim.cmd.write { "myfile.txt", bang = true } - - -- Ex command :colorscheme blue - vim.cmd('colorscheme blue') - vim.cmd.colorscheme('blue') + -- Ex command :colorscheme blue + vim.cmd('colorscheme blue') + vim.cmd.colorscheme('blue') < Parameters: ~ @@ -1579,9 +1577,8 @@ vim.keycode({str}) *vim.keycode()* Translate keycodes. Example: >lua - - local k = vim.keycode - vim.g.mapleader = k'<bs>' + local k = vim.keycode + vim.g.mapleader = k'<bs>' < Parameters: ~ @@ -1653,16 +1650,15 @@ vim.paste({lines}, {phase}) *vim.paste()* |TUI|) pastes text into the editor. Example: To remove ANSI color codes when pasting: >lua - - vim.paste = (function(overridden) - return function(lines, phase) - for i,line in ipairs(lines) do - -- Scrub ANSI color codes from paste input. - lines[i] = line:gsub('\27%[[0-9;mK]+', '') - end - overridden(lines, phase) - end - end)(vim.paste) + vim.paste = (function(overridden) + return function(lines, phase) + for i,line in ipairs(lines) do + -- Scrub ANSI color codes from paste input. + lines[i] = line:gsub('\27%[[0-9;mK]+', '') + end + overridden(lines, phase) + end + end)(vim.paste) < Parameters: ~ @@ -1684,8 +1680,7 @@ vim.print({...}) *vim.print()* "Pretty prints" the given arguments and returns them unmodified. Example: >lua - - local hl_normal = vim.print(vim.api.nvim_get_hl_by_name('Normal', true)) + local hl_normal = vim.print(vim.api.nvim_get_hl_by_name('Normal', true)) < Return: ~ @@ -1737,20 +1732,19 @@ vim.system({cmd}, {opts}, {on_exit}) *vim.system()* Run a system command Examples: >lua + local on_exit = function(obj) + print(obj.code) + print(obj.signal) + print(obj.stdout) + print(obj.stderr) + end - local on_exit = function(obj) - print(obj.code) - print(obj.signal) - print(obj.stdout) - print(obj.stderr) - end - - -- Run asynchronously - vim.system({'echo', 'hello'}, { text = true }, on_exit) + -- Run asynchronously + vim.system({'echo', 'hello'}, { text = true }, on_exit) - -- Run synchronously - local obj = vim.system({'echo', 'hello'}, { text = true }):wait() - -- { code = 0, signal = 0, stdout = 'hello', stderr = '' } + -- Run synchronously + local obj = vim.system({'echo', 'hello'}, { text = true }):wait() + -- { code = 0, signal = 0, stdout = 'hello', stderr = '' } < See |uv.spawn()| for more details. @@ -1894,12 +1888,9 @@ vim.defaulttable({create}) *vim.defaulttable()* If {create} is `nil`, this will create a defaulttable whose constructor function is this function, effectively allowing to create nested tables on - the fly: - - >lua - - local a = vim.defaulttable() - a.b.c = 1 + the fly: >lua + local a = vim.defaulttable() + a.b.c = 1 < Parameters: ~ @@ -1924,18 +1915,16 @@ vim.gsplit({s}, {sep}, {opts}) *vim.gsplit()* in "lazy" fashion (as opposed to |vim.split()| which is "eager"). Example: >lua - - for s in vim.gsplit(':aa::b:', ':', {plain=true}) do - print(s) - end + for s in vim.gsplit(':aa::b:', ':', {plain=true}) do + print(s) + end < If you want to also inspect the separator itself (instead of discarding it), use |string.gmatch()|. Example: >lua - - for word, num in ('foo111bar222'):gmatch('([^0-9]*)(d*)') do - print(('word: s num: s'):format(word, num)) - end + for word, num in ('foo111bar222'):gmatch('([^0-9]*)(%d*)') do + print(('word: %s num: %s'):format(word, num)) + end < Parameters: ~ @@ -2021,22 +2010,20 @@ vim.pesc({s}) *vim.pesc()* vim.ringbuf({size}) *vim.ringbuf()* Create a ring buffer limited to a maximal number of items. Once the buffer - is full, adding a new entry overrides the oldest entry. -> - - local ringbuf = vim.ringbuf(4) - ringbuf:push("a") - ringbuf:push("b") - ringbuf:push("c") - ringbuf:push("d") - ringbuf:push("e") -- overrides "a" - print(ringbuf:pop()) -- returns "b" - print(ringbuf:pop()) -- returns "c" - - -- Can be used as iterator. Pops remaining items: - for val in ringbuf do - print(val) - end + is full, adding a new entry overrides the oldest entry. >lua + local ringbuf = vim.ringbuf(4) + ringbuf:push("a") + ringbuf:push("b") + ringbuf:push("c") + ringbuf:push("d") + ringbuf:push("e") -- overrides "a" + print(ringbuf:pop()) -- returns "b" + print(ringbuf:pop()) -- returns "c" + + -- Can be used as iterator. Pops remaining items: + for val in ringbuf do + print(val) + end < Returns a Ringbuf instance with the following methods: @@ -2090,11 +2077,10 @@ vim.split({s}, {sep}, {opts}) *vim.split()* a table (unlike |vim.gsplit()|). Examples: >lua - - split(":aa::b:", ":") --> {'','aa','','b',''} - split("axaby", "ab?") --> {'','x','y'} - split("x*yz*o", "*", {plain=true}) --> {'x','yz','o'} - split("|x|y|z|", "|", {trimempty=true}) --> {'x', 'y', 'z'} + split(":aa::b:", ":") --> {'','aa','','b',''} + split("axaby", "ab?") --> {'','x','y'} + split("x*yz*o", "*", {plain=true}) --> {'x','yz','o'} + split("|x|y|z|", "|", {trimempty=true}) --> {'x', 'y', 'z'} < Parameters: ~ @@ -2137,11 +2123,10 @@ vim.tbl_contains({t}, {value}, {opts}) *vim.tbl_contains()* a predicate that is checked for each value. Example: >lua - - vim.tbl_contains({ 'a', { 'b', 'c' } }, function(v) - return vim.deep_equal(v, { 'b', 'c' }) - end, { predicate = true }) - -- true + vim.tbl_contains({ 'a', { 'b', 'c' } }, function(v) + return vim.deep_equal(v, { 'b', 'c' }) + end, { predicate = true }) + -- true < Parameters: ~ @@ -2158,12 +2143,9 @@ vim.tbl_contains({t}, {value}, {opts}) *vim.tbl_contains()* • |vim.list_contains()| for checking values in list-like tables vim.tbl_count({t}) *vim.tbl_count()* - Counts the number of non-nil values in table `t`. - - >lua - - vim.tbl_count({ a=1, b=2 }) --> 2 - vim.tbl_count({ 1, 2 }) --> 2 + Counts the number of non-nil values in table `t`. >lua + vim.tbl_count({ a=1, b=2 }) --> 2 + vim.tbl_count({ 1, 2 }) --> 2 < Parameters: ~ @@ -2237,9 +2219,8 @@ vim.tbl_get({o}, {...}) *vim.tbl_get()* arguments. Return `nil` if the key does not exist. Examples: >lua - - vim.tbl_get({ key = { nested_key = true }}, 'key', 'nested_key') == true - vim.tbl_get({ key = {}}, 'key', 'nested_key') == nil + vim.tbl_get({ key = { nested_key = true }}, 'key', 'nested_key') == true + vim.tbl_get({ key = {}}, 'key', 'nested_key') == nil < Parameters: ~ @@ -2340,36 +2321,33 @@ vim.validate({opt}) *vim.validate()* Validates a parameter specification (types and values). Usage example: >lua - - function user.new(name, age, hobbies) - vim.validate{ - name={name, 'string'}, - age={age, 'number'}, - hobbies={hobbies, 'table'}, - } - ... - end + function user.new(name, age, hobbies) + vim.validate{ + name={name, 'string'}, + age={age, 'number'}, + hobbies={hobbies, 'table'}, + } + ... + end < Examples with explicit argument values (can be run directly): >lua + vim.validate{arg1={{'foo'}, 'table'}, arg2={'foo', 'string'}} + --> NOP (success) - vim.validate{arg1={{'foo'}, 'table'}, arg2={'foo', 'string'}} - --> NOP (success) - - vim.validate{arg1={1, 'table'}} - --> error('arg1: expected table, got number') + vim.validate{arg1={1, 'table'}} + --> error('arg1: expected table, got number') - vim.validate{arg1={3, function(a) return (a % 2) == 0 end, 'even number'}} - --> error('arg1: expected even number, got 3') + vim.validate{arg1={3, function(a) return (a % 2) == 0 end, 'even number'}} + --> error('arg1: expected even number, got 3') < If multiple types are valid they can be given as a list. >lua + vim.validate{arg1={{'foo'}, {'table', 'string'}}, arg2={'foo', {'table', 'string'}}} + -- NOP (success) - vim.validate{arg1={{'foo'}, {'table', 'string'}}, arg2={'foo', {'table', 'string'}}} - --> NOP (success) - - vim.validate{arg1={1, {'string', 'table'}}} - --> error('arg1: expected string|table, got number') + vim.validate{arg1={1, {'string', 'table'}}} + -- error('arg1: expected string|table, got number') < Parameters: ~ @@ -2506,10 +2484,9 @@ vim.ui.input({opts}, {on_confirm}) *vim.ui.input()* work until `on_confirm`. Example: >lua - - vim.ui.input({ prompt = 'Enter value for shiftwidth: ' }, function(input) - vim.o.shiftwidth = tonumber(input) - end) + vim.ui.input({ prompt = 'Enter value for shiftwidth: ' }, function(input) + vim.o.shiftwidth = tonumber(input) + end) < Parameters: ~ @@ -2535,10 +2512,9 @@ vim.ui.open({path}) *vim.ui.open()* Expands "~/" and environment variables in filesystem paths. Examples: >lua - - vim.ui.open("https://neovim.io/") - vim.ui.open("~/path/to/file") - vim.ui.open("$VIMRUNTIME") + vim.ui.open("https://neovim.io/") + vim.ui.open("~/path/to/file") + vim.ui.open("$VIMRUNTIME") < Parameters: ~ @@ -2556,19 +2532,18 @@ vim.ui.select({items}, {opts}, {on_choice}) *vim.ui.select()* (potentially asynchronous) work until `on_choice`. Example: >lua - - vim.ui.select({ 'tabs', 'spaces' }, { - prompt = 'Select tabs or spaces:', - format_item = function(item) - return "I'd like to choose " .. item - end, - }, function(choice) - if choice == 'spaces' then - vim.o.expandtab = true - else - vim.o.expandtab = false - end - end) + vim.ui.select({ 'tabs', 'spaces' }, { + prompt = 'Select tabs or spaces:', + format_item = function(item) + return "I'd like to choose " .. item + end, + }, function(choice) + if choice == 'spaces' then + vim.o.expandtab = true + else + vim.o.expandtab = false + end + end) < Parameters: ~ @@ -2620,58 +2595,56 @@ vim.filetype.add({filetypes}) *vim.filetype.add()* See $VIMRUNTIME/lua/vim/filetype.lua for more examples. Example: >lua - - vim.filetype.add({ - extension = { - foo = 'fooscript', - bar = function(path, bufnr) - if some_condition() then - return 'barscript', function(bufnr) - -- Set a buffer variable - vim.b[bufnr].barscript_version = 2 + vim.filetype.add({ + extension = { + foo = 'fooscript', + bar = function(path, bufnr) + if some_condition() then + return 'barscript', function(bufnr) + -- Set a buffer variable + vim.b[bufnr].barscript_version = 2 + end end - end - return 'bar' - end, - }, - filename = { - ['.foorc'] = 'toml', - ['/etc/foo/config'] = 'toml', - }, - pattern = { - ['.*/etc/foo/.*'] = 'fooscript', - -- Using an optional priority - ['.*/etc/foo/.*%.conf'] = { 'dosini', { priority = 10 } }, - -- A pattern containing an environment variable - ['${XDG_CONFIG_HOME}/foo/git'] = 'git', - ['README.(a+)$'] = function(path, bufnr, ext) - if ext == 'md' then - return 'markdown' - elseif ext == 'rst' then - return 'rst' - end - end, - }, - }) + return 'bar' + end, + }, + filename = { + ['.foorc'] = 'toml', + ['/etc/foo/config'] = 'toml', + }, + pattern = { + ['.*‍/etc/foo/.*'] = 'fooscript', + -- Using an optional priority + ['.*‍/etc/foo/.*%.conf'] = { 'dosini', { priority = 10 } }, + -- A pattern containing an environment variable + ['${XDG_CONFIG_HOME}/foo/git'] = 'git', + ['README.(%a+)$'] = function(path, bufnr, ext) + if ext == 'md' then + return 'markdown' + elseif ext == 'rst' then + return 'rst' + end + end, + }, + }) < To add a fallback match on contents, use >lua - - vim.filetype.add { - pattern = { - ['.*'] = { - priority = -math.huge, - function(path, bufnr) - local content = vim.api.nvim_buf_get_lines(bufnr, 0, 1, false)[1] or '' - if vim.regex([[^#!.*\<mine\>]]):match_str(content) ~= nil then - return 'mine' - elseif vim.regex([[\<drawing\>]]):match_str(content) ~= nil then - return 'drawing' - end - end, - }, - }, - } + vim.filetype.add { + pattern = { + ['.*'] = { + priority = -math.huge, + function(path, bufnr) + local content = vim.api.nvim_buf_get_lines(bufnr, 0, 1, false)[1] or '' + if vim.regex([[^#!.*\\<mine\\>]]):match_str(content) ~= nil then + return 'mine' + elseif vim.regex([[\\<drawing\\>]]):match_str(content) ~= nil then + return 'drawing' + end + end, + }, + }, + } < Parameters: ~ @@ -2687,8 +2660,7 @@ vim.filetype.get_option({filetype}, {option}) files. Example: >lua - - vim.filetype.get_option('vim', 'commentstring') + vim.filetype.get_option('vim', 'commentstring') < Note: this uses |nvim_get_option_value()| but caches the result. This @@ -2717,21 +2689,18 @@ vim.filetype.match({args}) *vim.filetype.match()* the filetype. Each of the three options is specified using a key to the single argument - of this function. Example: + of this function. Example: >lua + -- Using a buffer number + vim.filetype.match({ buf = 42 }) - >lua + -- Override the filename of the given buffer + vim.filetype.match({ buf = 42, filename = 'foo.c' }) - -- Using a buffer number - vim.filetype.match({ buf = 42 }) + -- Using a filename without a buffer + vim.filetype.match({ filename = 'main.lua' }) - -- Override the filename of the given buffer - vim.filetype.match({ buf = 42, filename = 'foo.c' }) - - -- Using a filename without a buffer - vim.filetype.match({ filename = 'main.lua' }) - - -- Using file contents - vim.filetype.match({ contents = {'#!/usr/bin/env bash'} }) + -- Using file contents + vim.filetype.match({ contents = {'#!/usr/bin/env bash'} }) < Parameters: ~ @@ -2762,10 +2731,9 @@ Lua module: vim.keymap *vim.keymap* vim.keymap.del({modes}, {lhs}, {opts}) *vim.keymap.del()* Remove an existing mapping. Examples: >lua + vim.keymap.del('n', 'lhs') - vim.keymap.del('n', 'lhs') - - vim.keymap.del({'n', 'i', 'v'}, '<leader>w', { buffer = 5 }) + vim.keymap.del({'n', 'i', 'v'}, '<leader>w', { buffer = 5 }) < Parameters: ~ @@ -2778,19 +2746,18 @@ vim.keymap.del({modes}, {lhs}, {opts}) *vim.keymap.del()* vim.keymap.set({mode}, {lhs}, {rhs}, {opts}) *vim.keymap.set()* Adds a new |mapping|. Examples: >lua - - -- Map to a Lua function: - vim.keymap.set('n', 'lhs', function() print("real lua function") end) - -- Map to multiple modes: - vim.keymap.set({'n', 'v'}, '<leader>lr', vim.lsp.buf.references, { buffer = true }) - -- Buffer-local mapping: - vim.keymap.set('n', '<leader>w', "<cmd>w<cr>", { silent = true, buffer = 5 }) - -- Expr mapping: - vim.keymap.set('i', '<Tab>', function() - return vim.fn.pumvisible() == 1 and "<C-n>" or "<Tab>" - end, { expr = true }) - -- <Plug> mapping: - vim.keymap.set('n', '[%', '<Plug>(MatchitNormalMultiBackward)') + -- Map to a Lua function: + vim.keymap.set('n', 'lhs', function() print("real lua function") end) + -- Map to multiple modes: + vim.keymap.set({'n', 'v'}, '<leader>lr', vim.lsp.buf.references, { buffer = true }) + -- Buffer-local mapping: + vim.keymap.set('n', '<leader>w', "<cmd>w<cr>", { silent = true, buffer = 5 }) + -- Expr mapping: + vim.keymap.set('i', '<Tab>', function() + return vim.fn.pumvisible() == 1 and "<C-n>" or "<Tab>" + end, { expr = true }) + -- <Plug> mapping: + vim.keymap.set('n', '[%%', '<Plug>(MatchitNormalMultiBackward)') < Parameters: ~ @@ -2871,24 +2838,23 @@ vim.fs.find({names}, {opts}) *vim.fs.find()* narrow the search to find only that type. Examples: >lua + -- location of Cargo.toml from the current buffer's path + local cargo = vim.fs.find('Cargo.toml', { + upward = true, + stop = vim.uv.os_homedir(), + path = vim.fs.dirname(vim.api.nvim_buf_get_name(0)), + }) - -- location of Cargo.toml from the current buffer's path - local cargo = vim.fs.find('Cargo.toml', { - upward = true, - stop = vim.uv.os_homedir(), - path = vim.fs.dirname(vim.api.nvim_buf_get_name(0)), - }) + -- list all test directories under the runtime directory + local test_dirs = vim.fs.find( + {'test', 'tst', 'testdir'}, + {limit = math.huge, type = 'directory', path = './runtime/'} + ) - -- list all test directories under the runtime directory - local test_dirs = vim.fs.find( - {'test', 'tst', 'testdir'}, - {limit = math.huge, type = 'directory', path = './runtime/'} - ) - - -- get all files ending with .cpp or .hpp inside lib/ - local cpp_hpp = vim.fs.find(function(name, path) - return name:match('.*%.[ch]pp$') and path:match('[/\\]lib$') - end, {limit = math.huge, type = 'file'}) + -- get all files ending with .cpp or .hpp inside lib/ + local cpp_hpp = vim.fs.find(function(name, path) + return name:match('.*%.[ch]pp$') and path:match('[/\\\\]lib$') + end, {limit = math.huge, type = 'file'}) < Parameters: ~ @@ -2934,15 +2900,14 @@ vim.fs.normalize({path}, {opts}) *vim.fs.normalize()* variables are also expanded. Examples: >lua + vim.fs.normalize('C:\\\\Users\\\\jdoe') + -- 'C:/Users/jdoe' - vim.fs.normalize('C:\\Users\\jdoe') - --> 'C:/Users/jdoe' - - vim.fs.normalize('~/src/neovim') - --> '/home/jdoe/src/neovim' + vim.fs.normalize('~/src/neovim') + -- '/home/jdoe/src/neovim' - vim.fs.normalize('$XDG_CONFIG_HOME/nvim/init.vim') - --> '/Users/jdoe/.config/nvim/init.vim' + vim.fs.normalize('$XDG_CONFIG_HOME/nvim/init.vim') + -- '/Users/jdoe/.config/nvim/init.vim' < Parameters: ~ @@ -2958,18 +2923,17 @@ vim.fs.parents({start}) *vim.fs.parents()* Iterate over all the parents of the given path. Example: >lua + local root_dir + for dir in vim.fs.parents(vim.api.nvim_buf_get_name(0)) do + if vim.fn.isdirectory(dir .. "/.git") == 1 then + root_dir = dir + break + end + end - local root_dir - for dir in vim.fs.parents(vim.api.nvim_buf_get_name(0)) do - if vim.fn.isdirectory(dir .. "/.git") == 1 then - root_dir = dir - break - end - end - - if root_dir then - print("Found git repository at", root_dir) - end + if root_dir then + print("Found git repository at", root_dir) + end < Parameters: ~ @@ -3033,11 +2997,10 @@ spec. Plugins, and plugin managers, can use this to check available tools and dependencies on the current system. Example: >lua - - local v = vim.version.parse(vim.fn.system({'tmux', '-V'}), {strict=false}) - if vim.version.gt(v, {3, 2, 0}) then - -- ... - end + local v = vim.version.parse(vim.fn.system({'tmux', '-V'}), {strict=false}) + if vim.version.gt(v, {3, 2, 0}) then + -- ... + end < @@ -3050,34 +3013,33 @@ tested against a version, using |vim.version.range()|. Supported range specs are shown in the following table. Note: suffixed versions (1.2.3-rc1) are not matched. > - - 1.2.3 is 1.2.3 - =1.2.3 is 1.2.3 - >1.2.3 greater than 1.2.3 - <1.2.3 before 1.2.3 - >=1.2.3 at least 1.2.3 - ~1.2.3 is >=1.2.3 <1.3.0 "reasonably close to 1.2.3" - ^1.2.3 is >=1.2.3 <2.0.0 "compatible with 1.2.3" - ^0.2.3 is >=0.2.3 <0.3.0 (0.x.x is special) - ^0.0.1 is =0.0.1 (0.0.x is special) - ^1.2 is >=1.2.0 <2.0.0 (like ^1.2.0) - ~1.2 is >=1.2.0 <1.3.0 (like ~1.2.0) - ^1 is >=1.0.0 <2.0.0 "compatible with 1" - ~1 same "reasonably close to 1" - 1.x same - 1.* same - 1 same - * any version - x same - - 1.2.3 - 2.3.4 is >=1.2.3 <=2.3.4 - - Partial right: missing pieces treated as x (2.3 => 2.3.x). - 1.2.3 - 2.3 is >=1.2.3 <2.4.0 - 1.2.3 - 2 is >=1.2.3 <3.0.0 - - Partial left: missing pieces treated as 0 (1.2 => 1.2.0). - 1.2 - 2.3.0 is 1.2.0 - 2.3.0 + 1.2.3 is 1.2.3 + =1.2.3 is 1.2.3 + >1.2.3 greater than 1.2.3 + <1.2.3 before 1.2.3 + >=1.2.3 at least 1.2.3 + ~1.2.3 is >=1.2.3 <1.3.0 "reasonably close to 1.2.3" + ^1.2.3 is >=1.2.3 <2.0.0 "compatible with 1.2.3" + ^0.2.3 is >=0.2.3 <0.3.0 (0.x.x is special) + ^0.0.1 is =0.0.1 (0.0.x is special) + ^1.2 is >=1.2.0 <2.0.0 (like ^1.2.0) + ~1.2 is >=1.2.0 <1.3.0 (like ~1.2.0) + ^1 is >=1.0.0 <2.0.0 "compatible with 1" + ~1 same "reasonably close to 1" + 1.x same + 1.* same + 1 same + * any version + x same + + 1.2.3 - 2.3.4 is >=1.2.3 <=2.3.4 + + Partial right: missing pieces treated as x (2.3 => 2.3.x). + 1.2.3 - 2.3 is >=1.2.3 <2.4.0 + 1.2.3 - 2 is >=1.2.3 <3.0.0 + + Partial left: missing pieces treated as 0 (1.2 => 1.2.0). + 1.2 - 2.3.0 is 1.2.0 - 2.3.0 < @@ -3087,15 +3049,14 @@ vim.version.cmp({v1}, {v2}) *vim.version.cmp()* tuple, e.g. `{1, 0, 3}`). Example: >lua - - if vim.version.cmp({1,0,3}, {0,2,1}) == 0 then - -- ... - end - local v1 = vim.version.parse('1.0.3-pre') - local v2 = vim.version.parse('0.2.1') - if vim.version.cmp(v1, v2) == 0 then - -- ... - end + if vim.version.cmp({1,0,3}, {0,2,1}) == 0 then + -- ... + end + local v1 = vim.version.parse('1.0.3-pre') + local v2 = vim.version.parse('0.2.1') + if vim.version.cmp(v1, v2) == 0 then + -- ... + end < Note: ~ @@ -3150,9 +3111,9 @@ vim.version.lt({v1}, {v2}) *vim.version.lt()* vim.version.parse({version}, {opts}) *vim.version.parse()* Parses a semantic version string and returns a version object which can be - used with other `vim.version` functions. For example "1.0.1-rc1+build.2" returns: > - - { major = 1, minor = 0, patch = 1, prerelease = "rc1", build = "build.2" } + used with other `vim.version` functions. For example "1.0.1-rc1+build.2" + returns: > + { major = 1, minor = 0, patch = 1, prerelease = "rc1", build = "build.2" } < Parameters: ~ @@ -3171,29 +3132,26 @@ vim.version.parse({version}, {opts}) *vim.version.parse()* vim.version.range({spec}) *vim.version.range()* Parses a semver |version-range| "spec" and returns a range object: > - - { - from: Version - to: Version - has(v: string|Version) - } + { + from: Version + to: Version + has(v: string|Version) + } < `:has()` checks if a version is in the range (inclusive `from`, exclusive `to`). Example: >lua - - local r = vim.version.range('1.0.0 - 2.0.0') - print(r:has('1.9.9')) -- true - print(r:has('2.0.0')) -- false - print(r:has(vim.version())) -- check against current Nvim version + local r = vim.version.range('1.0.0 - 2.0.0') + print(r:has('1.9.9')) -- true + print(r:has('2.0.0')) -- false + print(r:has(vim.version())) -- check against current Nvim version < Or use cmp(), eq(), lt(), and gt() to compare `.to` and `.from` directly: >lua - - local r = vim.version.range('1.0.0 - 2.0.0') - print(vim.version.gt({1,0,3}, r.from) and vim.version.lt({1,0,3}, r.to)) + local r = vim.version.range('1.0.0 - 2.0.0') + print(vim.version.gt({1,0,3}, r.from) and vim.version.lt({1,0,3}, r.to)) < Parameters: ~ @@ -3228,7 +3186,6 @@ iterator runs out of values (for function iterators, this means that the first value returned by the function is nil). Examples: >lua - local it = vim.iter({ 1, 2, 3, 4, 5 }) it:map(function(v) return v * 3 @@ -3275,7 +3232,6 @@ filter({f}, {src}, {...}) *vim.iter.filter()* Filter a table or iterator. This is a convenience function that performs: >lua - vim.iter(src):filter(f):totable() < @@ -3325,19 +3281,16 @@ Iter:enumerate() *Iter:enumerate()* the iterator value. For list tables, prefer >lua - vim.iter(ipairs(t)) < over >lua - vim.iter(t):enumerate() < as the former is faster. Example: >lua - local it = vim.iter(vim.gsplit('abc', '')):enumerate() it:next() -- 1 'a' @@ -3354,7 +3307,6 @@ Iter:filter({f}) *Iter:filter()* Add a filter step to the iterator pipeline. Example: >lua - local bufs = vim.iter(vim.api.nvim_list_bufs()):filter(vim.api.nvim_buf_is_loaded) < @@ -3373,7 +3325,6 @@ Iter:find({f}) *Iter:find()* found. Examples: >lua - local it = vim.iter({ 3, 6, 9, 12 }) it:find(12) -- 12 @@ -3394,7 +3345,6 @@ Iter:fold({init}, {f}) *Iter:fold()* Fold ("reduce") an iterator or table into a single value. Examples: >lua - -- Create a new table with only even values local t = { a = 1, b = 2, c = 3, d = 4 } local it = vim.iter(t) @@ -3419,7 +3369,6 @@ Iter:last() *Iter:last()* Drains the iterator. Example: >lua - local it = vim.iter(vim.gsplit('abcdefg', '')) it:last() -- 'g' @@ -3438,7 +3387,6 @@ Iter:map({f}) *Iter:map()* If the map function returns nil, the value is filtered from the iterator. Example: >lua - local it = vim.iter({ 1, 2, 3, 4 }):map(function(v) if v % 2 == 0 then return v * 3 @@ -3461,7 +3409,6 @@ Iter:next() *Iter:next()* Return the next value from the iterator. Example: >lua - local it = vim.iter(string.gmatch('1 2 3', '%d+')):map(tonumber) it:next() -- 1 @@ -3480,7 +3427,6 @@ Iter:nextback() *Iter:nextback()* Only supported for iterators on list-like tables. Example: >lua - local it = vim.iter({1, 2, 3, 4}) it:nextback() -- 4 @@ -3497,7 +3443,6 @@ Iter:nth({n}) *Iter:nth()* This function advances the iterator. Example: >lua - local it = vim.iter({ 3, 6, 9, 12 }) it:nth(2) -- 6 @@ -3519,7 +3464,6 @@ Iter:nthback({n}) *Iter:nthback()* Only supported for iterators on list-like tables. Example: >lua - local it = vim.iter({ 3, 6, 9, 12 }) it:nthback(2) -- 9 @@ -3539,7 +3483,6 @@ Iter:peek() *Iter:peek()* Only supported for iterators on list-like tables. Example: >lua - local it = vim.iter({ 3, 6, 9, 12 }) it:peek() -- 3 @@ -3558,7 +3501,6 @@ Iter:peekback() *Iter:peekback()* Only supported for iterators on list-like tables. Example: >lua - local it = vim.iter({1, 2, 3, 4}) it:peekback() -- 4 @@ -3577,7 +3519,6 @@ Iter:rev() *Iter:rev()* Only supported for iterators on list-like tables. Example: >lua - local it = vim.iter({ 3, 6, 9, 12 }):rev() it:totable() -- { 12, 9, 6, 3 } @@ -3596,7 +3537,6 @@ Iter:rfind({f}) *Iter:rfind()* Only supported for iterators on list-like tables. Examples: >lua - local it = vim.iter({ 1, 2, 3, 2, 1 }):enumerate() it:rfind(1) -- 5 1 @@ -3614,7 +3554,6 @@ Iter:skip({n}) *Iter:skip()* Skip values in the iterator. Example: >lua - local it = vim.iter({ 3, 6, 9, 12 }):skip(2) it:next() -- 9 @@ -3632,7 +3571,6 @@ Iter:skipback({n}) *Iter:skipback()* Only supported for iterators on list-like tables. Example: >lua - local it = vim.iter({ 1, 2, 3, 4, 5 }):skipback(2) it:next() -- 1 @@ -3669,7 +3607,6 @@ Iter:totable() *Iter:totable()* the iterator pipeline, each value will be included in a table. Examples: >lua - vim.iter(string.gmatch('100 20 50', '%d+')):map(tonumber):totable() -- { 100, 20, 50 } @@ -3691,7 +3628,6 @@ map({f}, {src}, {...}) *vim.iter.map()* Map and filter a table or iterator. This is a convenience function that performs: >lua - vim.iter(src):map(f):totable() < @@ -3711,7 +3647,6 @@ totable({f}, {...}) *vim.iter.totable()* Collect an iterator into a table. This is a convenience function that performs: >lua - vim.iter(f):totable() < diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index f758782f09..e1518c58bb 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -945,7 +945,7 @@ A jump table for the options with a short description can be found at |Q_op|. backups if you don't care about losing the file. Note that environment variables are not expanded. If you want to use - $HOME you must expand it explicitly, e.g.: > + $HOME you must expand it explicitly, e.g.: >vim :let &backupskip = escape(expand('$HOME'), '\') .. '/tmp/*' < Note that the default also makes sure that "crontab -e" works (when a diff --git a/runtime/doc/treesitter.txt b/runtime/doc/treesitter.txt index 9d07aee290..c62e210be1 100644 --- a/runtime/doc/treesitter.txt +++ b/runtime/doc/treesitter.txt @@ -551,8 +551,7 @@ Lua module: vim.treesitter *lua-treesitter-core* foldexpr({lnum}) *vim.treesitter.foldexpr()* Returns the fold level for {lnum} in the current buffer. Can be set directly to 'foldexpr': >lua - - vim.wo.foldexpr = 'v:lua.vim.treesitter.foldexpr()' + vim.wo.foldexpr = 'v:lua.vim.treesitter.foldexpr()' < Parameters: ~ @@ -746,13 +745,12 @@ start({bufnr}, {lang}) *vim.treesitter.start()* the call to `start`. Example: >lua - - vim.api.nvim_create_autocmd( 'FileType', { pattern = 'tex', - callback = function(args) - vim.treesitter.start(args.buf, 'latex') - vim.bo[args.buf].syntax = 'on' -- only if additional legacy syntax is needed - end - }) + vim.api.nvim_create_autocmd( 'FileType', { pattern = 'tex', + callback = function(args) + vim.treesitter.start(args.buf, 'latex') + vim.bo[args.buf].syntax = 'on' -- only if additional legacy syntax is needed + end + }) < Parameters: ~ @@ -922,7 +920,7 @@ omnifunc({findstart}, {base}) *vim.treesitter.query.omnifunc()* Omnifunc for completing node names and predicates in treesitter queries. Use via >lua - vim.bo.omnifunc = 'v:lua.vim.treesitter.query.omnifunc' + vim.bo.omnifunc = 'v:lua.vim.treesitter.query.omnifunc' < parse({lang}, {query}) *vim.treesitter.query.parse()* @@ -958,14 +956,13 @@ Query:iter_captures({node}, {source}, {start}, {stop}) The iterator returns three values: a numeric id identifying the capture, the captured node, and metadata from any directives processing the match. The following example shows how to get captures by name: >lua - - for id, node, metadata in query:iter_captures(tree:root(), bufnr, first, last) do - local name = query.captures[id] -- name of the capture in the query - -- typically useful info about the node: - local type = node:type() -- type of the captured node - local row1, col1, row2, col2 = node:range() -- range of the capture - -- ... use the info here ... - end + for id, node, metadata in query:iter_captures(tree:root(), bufnr, first, last) do + local name = query.captures[id] -- name of the capture in the query + -- typically useful info about the node: + local type = node:type() -- type of the captured node + local row1, col1, row2, col2 = node:range() -- range of the capture + -- ... use the info here ... + end < Parameters: ~ @@ -988,18 +985,18 @@ Query:iter_matches({node}, {source}, {start}, {stop}, {opts}) (1-based) index of the pattern in the query, a table mapping capture indices to nodes, and metadata from any directives processing the match. If the query has more than one pattern, the capture table might be sparse - and e.g. `pairs()` method should be used over `ipairs` . Here is an example iterating over all captures in every match: >lua - - for pattern, match, metadata in cquery:iter_matches(tree:root(), bufnr, first, last) do - for id, node in pairs(match) do - local name = query.captures[id] - -- `node` was captured by the `name` capture in the match - - local node_data = metadata[id] -- Node level metadata - - -- ... use the info here ... - end - end + and e.g. `pairs()` method should be used over `ipairs`. Here is an example + iterating over all captures in every match: >lua + for pattern, match, metadata in cquery:iter_matches(tree:root(), bufnr, first, last) do + for id, node in pairs(match) do + local name = query.captures[id] + -- `node` was captured by the `name` capture in the match + + local node_data = metadata[id] -- Node level metadata + + -- ... use the info here ... + end + end < Parameters: ~ @@ -1039,11 +1036,8 @@ inject other languages, recursively. For example a Lua buffer containing some Vimscript commands needs multiple parsers to fully understand its contents. -To create a LanguageTree (parser object) for a given buffer and language, use: - ->lua - - local parser = vim.treesitter.get_parser(bufnr, lang) +To create a LanguageTree (parser object) for a given buffer and language, use: >lua + local parser = vim.treesitter.get_parser(bufnr, lang) < @@ -1052,11 +1046,8 @@ Note: currently the parser is retained for the lifetime of a buffer but this may change; a plugin should keep a reference to the parser object if it wants incremental updates. -Whenever you need to access the current syntax tree, parse the buffer: - ->lua - - local tree = parser:parse({ start_row, end_row }) +Whenever you need to access the current syntax tree, parse the buffer: >lua + local tree = parser:parse({ start_row, end_row }) < |