aboutsummaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'runtime')
-rw-r--r--runtime/doc/lua.txt37
-rw-r--r--runtime/doc/map.txt19
-rw-r--r--runtime/doc/options.txt20
-rw-r--r--runtime/lua/vim/filetype.lua10
4 files changed, 66 insertions, 20 deletions
diff --git a/runtime/doc/lua.txt b/runtime/doc/lua.txt
index 9cc17ffa34..42f3a5e432 100644
--- a/runtime/doc/lua.txt
+++ b/runtime/doc/lua.txt
@@ -1238,41 +1238,54 @@ vim.go :setglobal set -
vim.o *vim.o*
Get or set editor options, like |:set|. Invalid key is an error.
+
Example: >
vim.o.cmdheight = 4
print(vim.o.columns)
+ print(vim.o.foo) -- error: invalid key
<
vim.go *vim.go*
Get or set an |option|. Invalid key is an error.
- This is a wrapper around |nvim_set_option()| and |nvim_get_option()|.
+ This is a wrapper around |nvim_set_option_value()| and
+ |nvim_get_option_value()|.
- NOTE: This is different than |vim.o| because this ONLY sets the global
+ NOTE: This is different from |vim.o| because this ONLY sets the global
option, which generally produces confusing behavior for options with
|global-local| values.
Example: >
vim.go.cmdheight = 4
+ print(vim.go.columns)
+ print(vim.go.bar) -- error: invalid key
<
-vim.bo *vim.bo*
- Get or set buffer-scoped |local-options|. Invalid key is an error.
+vim.bo[{bufnr}] *vim.bo*
+ Get or set buffer-scoped |local-options| for the buffer with number {bufnr}.
+ If [{bufnr}] is omitted, use the current buffer. Invalid {bufnr} or key is
+ an error.
- This is a wrapper around |nvim_buf_set_option()| and
- |nvim_buf_get_option()|.
+ This is a wrapper around |nvim_set_option_value()| and
+ |nvim_get_option_value()| with `opts = {scope = local, buf = bufnr}` .
Example: >
- vim.bo.buflisted = true
+ local bufnr = vim.api.nvim_get_current_buf()
+ vim.bo[bufnr].buflisted = true -- same as vim.bo.buflisted = true
print(vim.bo.comments)
+ print(vim.bo.baz) -- error: invalid key
<
-vim.wo *vim.wo*
- Get or set window-scoped |local-options|. Invalid key is an error.
+vim.wo[{winid}] *vim.wo*
+ Get or set window-scoped |local-options| for the window with handle {winid}.
+ If [{winid}] is omitted, use the current window. Invalid {winid} or key
+ is an error.
- This is a wrapper around |nvim_win_set_option()| and
- |nvim_win_get_option()|.
+ This is a wrapper around |nvim_set_option_value()| and
+ |nvim_get_option_value()| with `opts = {scope = local, win = winid}` .
Example: >
- vim.wo.cursorcolumn = true
+ local winid = vim.api.nvim_get_current_win()
+ vim.wo[winid].number = true -- same as vim.wo.number = true
print(vim.wo.foldmarker)
+ print(vim.wo.quux) -- error: invalid key
<
==============================================================================
Lua module: vim *lua-vim*
diff --git a/runtime/doc/map.txt b/runtime/doc/map.txt
index 00e5cc6e27..ca1ddaabd4 100644
--- a/runtime/doc/map.txt
+++ b/runtime/doc/map.txt
@@ -905,6 +905,17 @@ or `unnamedplus`.
The `mode()` function will return the state as it will be after applying the
operator.
+Here is an example for using a lambda function to create a normal-mode
+operator to add quotes around text in the current line: >
+
+ nnoremap <F4> <Cmd>let &opfunc='{t ->
+ \ getline(".")
+ \ ->split("\\zs")
+ \ ->insert("\"", col("'']"))
+ \ ->insert("\"", col("''[") - 1)
+ \ ->join("")
+ \ ->setline(".")}'<CR>g@
+
==============================================================================
2. Abbreviations *abbreviations* *Abbreviations*
@@ -1466,10 +1477,10 @@ results (for "inccommand=split", or nil for "inccommand=nosplit").
Your command preview routine must implement this protocol:
-1. Modify the current buffer as required for the preview (see
+1. Modify the target buffers as required for the preview (see
|nvim_buf_set_text()| and |nvim_buf_set_lines()|).
2. If preview buffer is provided, add necessary text to the preview buffer.
-3. Add required highlights to the current buffer. If preview buffer is
+3. Add required highlights to the target buffers. If preview buffer is
provided, add required highlights to the preview buffer as well. All
highlights must be added to the preview namespace which is provided as an
argument to the preview callback (see |nvim_buf_add_highlight()| and
@@ -1480,8 +1491,8 @@ Your command preview routine must implement this protocol:
2: Preview is shown and preview window is opened (if "inccommand=split").
For "inccommand=nosplit" this is the same as 1.
-After preview ends, Nvim discards all changes to the buffer and all highlights
-in the preview namespace.
+After preview ends, Nvim discards all changes to all buffers made during the
+preview and clears all highlights in the preview namespace.
Here's an example of a command to trim trailing whitespace from lines that
supports incremental command preview:
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
index a1f2eac5ed..27aa06e18b 100644
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -312,6 +312,17 @@ Note: In the future more global options can be made |global-local|. Using
":setlocal" on a global option might work differently then.
+ *option-value-function*
+Some options ('completefunc', 'imactivatefunc', 'imstatusfunc', 'omnifunc',
+'operatorfunc', 'quickfixtextfunc' and 'tagfunc') are set to a function name
+or a function reference or a lambda function. Examples:
+>
+ set opfunc=MyOpFunc
+ set opfunc=function("MyOpFunc")
+ set opfunc=funcref("MyOpFunc")
+ set opfunc={t\ ->\ MyOpFunc(t)}
+<
+
Setting the filetype
:setf[iletype] [FALLBACK] {filetype} *:setf* *:setfiletype*
@@ -4402,7 +4413,9 @@ A jump table for the options with a short description can be found at |Q_op|.
'operatorfunc' 'opfunc' string (default: empty)
global
This option specifies a function to be called by the |g@| operator.
- See |:map-operator| for more info and an example.
+ See |:map-operator| for more info and an example. The value can be
+ the name of a function, a |lambda| or a |Funcref|. See
+ |option-value-function| for more information.
This option cannot be set from a |modeline| or in the |sandbox|, for
security reasons.
@@ -4696,8 +4709,9 @@ A jump table for the options with a short description can be found at |Q_op|.
customize the information displayed in the quickfix or location window
for each entry in the corresponding quickfix or location list. See
|quickfix-window-function| for an explanation of how to write the
- function and an example. The value can be the name of a function or a
- lambda.
+ function and an example. The value can be the name of a function, a
+ |lambda| or a |Funcref|. See |option-value-function| for more
+ information.
This option cannot be set from a |modeline| or in the |sandbox|, for
security reasons.
diff --git a/runtime/lua/vim/filetype.lua b/runtime/lua/vim/filetype.lua
index 872106b20d..99c98764dd 100644
--- a/runtime/lua/vim/filetype.lua
+++ b/runtime/lua/vim/filetype.lua
@@ -2489,7 +2489,15 @@ function M.match(args)
-- Finally, check file contents
if contents or bufnr then
- contents = contents or M.getlines(bufnr)
+ if contents == nil then
+ if api.nvim_buf_line_count(bufnr) > 101 then
+ -- only need first 100 and last line for current checks
+ contents = M.getlines(bufnr, 1, 100)
+ contents[#contents + 1] = M.getlines(bufnr, -1)
+ else
+ contents = M.getlines(bufnr)
+ end
+ end
-- If name is nil, catch any errors from the contents filetype detection function.
-- If the function tries to use the filename that is nil then it will fail,
-- but this enables checks which do not need a filename to still work.