From 9b5f58185e1ff0597c7e95b7205d9ec11be1848c Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Tue, 1 Aug 2023 09:57:52 +0100 Subject: docs(builtin): fix and annotate language blocks (#24506) --- runtime/lua/vim/_meta/vimfn.lua | 2839 +++++++++++++++++++++------------------ 1 file changed, 1544 insertions(+), 1295 deletions(-) (limited to 'runtime/lua/vim/_meta/vimfn.lua') diff --git a/runtime/lua/vim/_meta/vimfn.lua b/runtime/lua/vim/_meta/vimfn.lua index 82213324e3..8b56d8e708 100644 --- a/runtime/lua/vim/_meta/vimfn.lua +++ b/runtime/lua/vim/_meta/vimfn.lua @@ -6,16 +6,17 @@ --- a |Float| abs() returns a |Float|. When {expr} can be --- converted to a |Number| abs() returns a |Number|. Otherwise --- abs() gives an error message and returns -1. ---- Examples: > +--- Examples: >vim --- echo abs(1.456) ---- < 1.456 > +--- < 1.456 >vim --- echo abs(-5.456) ---- < 5.456 > +--- < 5.456 >vim --- echo abs(-4) --- < 4 --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- Compute()->abs() +--- < --- --- @param expr any --- @return number @@ -27,31 +28,33 @@ function vim.fn.abs(expr) end --- [-1, 1]. --- Returns NaN if {expr} is outside the range [-1, 1]. Returns --- 0.0 if {expr} is not a |Float| or a |Number|. ---- Examples: > ---- :echo acos(0) ---- < 1.570796 > ---- :echo acos(-0.5) +--- Examples: >vim +--- echo acos(0) +--- < 1.570796 >vim +--- echo acos(-0.5) --- < 2.094395 --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- Compute()->acos() +--- < --- --- @param expr any --- @return number function vim.fn.acos(expr) end --- Append the item {expr} to |List| or |Blob| {object}. Returns ---- the resulting |List| or |Blob|. Examples: > ---- :let alist = add([1, 2, 3], item) ---- :call add(mylist, "woodstock") +--- the resulting |List| or |Blob|. Examples: >vim +--- let alist = add([1, 2, 3], item) +--- call add(mylist, "woodstock") --- +--- Can also be used as a |method|: >vim --- mylist->add(val1)->add(val2) +--- < --- --- @param object any --- @param expr any @@ -61,10 +64,11 @@ function vim.fn.add(object, expr) end --- Bitwise AND on the two arguments. The arguments are converted --- to a number. A List, Dict or Float argument causes an error. --- Also see `or()` and `xor()`. ---- Example: > ---- :let flag = and(bits, 0x80) ---- ---- :let flag = bits->and(0x80) +--- Example: >vim +--- let flag = and(bits, 0x80) +--- vim +--- let flag = bits->and(0x80) +--- < --- --- @param expr any --- @param expr1 any @@ -73,8 +77,9 @@ vim.fn['and'] = function(expr, expr1) end --- Returns Dictionary of |api-metadata|. --- ---- View it in a nice human-readable format: > ---- :lua vim.print(vim.fn.api_info()) +--- View it in a nice human-readable format: >vim +--- lua vim.print(vim.fn.api_info()) +--- < --- --- @return table function vim.fn.api_info() end @@ -87,12 +92,13 @@ function vim.fn.api_info() end --- {lnum} can be zero to insert a line before the first one. --- {lnum} is used like with |getline()|. --- Returns 1 for failure ({lnum} out of range or out of memory), ---- 0 for success. Example: > ---- :let failed = append(line('$'), "# THE END") ---- :let failed = append(0, ["Chapter 1", "the beginning"]) +--- 0 for success. Example: >vim +--- let failed = append(line('$'), "# THE END") +--- let failed = append(0, ["Chapter 1", "the beginning"]) --- ---- +--- vim --- mylist->append(lnum) +--- < --- --- @param lnum integer --- @param text any @@ -114,11 +120,12 @@ function vim.fn.append(lnum, text) end --- On success 0 is returned, on failure 1 is returned. --- --- If {buf} is not a valid buffer or {lnum} is not valid, an ---- error message is given. Example: > ---- :let failed = appendbufline(13, 0, "# THE START") +--- error message is given. Example: >vim +--- let failed = appendbufline(13, 0, "# THE START") --- < ---- Can also be used as a |method| after a List: > +--- Can also be used as a |method| after a List: >vim --- mylist->appendbufline(buf, lnum) +--- < --- --- @param buf any --- @param lnum integer @@ -162,13 +169,13 @@ function vim.fn.argidx() end function vim.fn.arglistid(winnr, tabnr) end --- The result is the {nr}th file in the argument list. See ---- |arglist|. "argv(0)" is the first one. Example: > ---- :let i = 0 ---- :while i < argc() ---- : let f = escape(fnameescape(argv(i)), '.') ---- : exe 'amenu Arg.' .. f .. ' :e ' .. f .. '' ---- : let i = i + 1 ---- :endwhile +--- |arglist|. "argv(0)" is the first one. Example: >vim +--- let i = 0 +--- while i < argc() +--- let f = escape(fnameescape(argv(i)), '.') +--- exe 'amenu Arg.' .. f .. ' :e ' .. f .. '' +--- let i = i + 1 +--- endwhile --- ---- :echo asin(0.8) ---- < 0.927295 > ---- :echo asin(-0.5) +--- Examples: >vim +--- echo asin(0.8) +--- < 0.927295 >vim +--- echo asin(-0.5) --- < -0.523599 --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- Compute()->asin() --- < --- @@ -209,7 +216,7 @@ function vim.fn.asin(expr) end --- Also see |assert_fails()|, |assert_nobeep()| and --- |assert-return|. --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- GetCmd()->assert_beeps() --- < --- @@ -227,13 +234,14 @@ function vim.fn.assert_beeps(cmd) end --- from the Number 4. And the number 4 is different from the --- Float 4.0. The value of 'ignorecase' is not used here, case --- always matters. ---- Example: > +--- Example: >vim --- assert_equal('foo', 'bar') --- +--- Can also be used as a |method|: >vim --- mylist->assert_equal([1, 2, 3]) +--- < --- --- @param expected any --- @param actual any @@ -247,8 +255,9 @@ function vim.fn.assert_equal(expected, actual, msg) end --- When {fname-one} or {fname-two} does not exist the error will --- mention that. --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- GetLog()->assert_equalfile('expected.log') +--- < --- --- @return 0|1 function vim.fn.assert_equalfile() end @@ -257,7 +266,7 @@ function vim.fn.assert_equalfile() end --- message is added to |v:errors|. Also see |assert-return|. --- This can be used to assert that a command throws an exception. --- Using the error number, followed by a colon, avoids problems ---- with translations: > +--- with translations: >vim --- try --- commandthatfails --- call assert_false(1, 'command should have failed') @@ -277,16 +286,16 @@ function vim.fn.assert_exception(error, msg) end --- --- When {error} is a string it must be found literally in the --- first reported error. Most often this will be the error code, ---- including the colon, e.g. "E123:". > +--- including the colon, e.g. "E123:". >vim --- assert_fails('bad cmd', 'E987:') --- < --- When {error} is a |List| with one or two strings, these are --- used as patterns. The first pattern is matched against the ---- first reported error: > +--- first reported error: >vim --- assert_fails('cmd', ['E987:.*expected bool']) --- +--- string for the first error: >vim --- assert_fails('cmd', ['', 'E987:']) --- < --- If {msg} is empty then it is not used. Do this to get the @@ -304,8 +313,9 @@ function vim.fn.assert_exception(error, msg) end --- Note that beeping is not considered an error, and some failing --- commands only beep. Use |assert_beeps()| for those. --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- GetCmd()->assert_fails('E99:') +--- < --- --- @param cmd any --- @param error? any @@ -324,8 +334,9 @@ function vim.fn.assert_fails(cmd, error, msg, lnum, context) end --- A value is false when it is zero. When {actual} is not a --- number the assert fails. --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- GetResult()->assert_false() +--- < --- --- @param actual any --- @param msg? any @@ -359,12 +370,12 @@ function vim.fn.assert_inrange(lower, upper, actual, msg) end --- Use "^" and "$" to match with the start and end of the text. --- Use both to match the whole text. --- ---- Example: > +--- Example: >vim --- assert_match('^f.*o$', 'foobar') --- +--- Can also be used as a |method|: >vim --- getFile()->assert_match('foo.*') --- < --- @@ -378,7 +389,7 @@ function vim.fn.assert_match(pattern, actual, msg) end --- produces a beep or visual bell. --- Also see |assert_beeps()|. --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- GetCmd()->assert_nobeep() --- < --- @@ -390,9 +401,8 @@ function vim.fn.assert_nobeep(cmd) end --- |v:errors| when {expected} and {actual} are equal. --- Also see |assert-return|. --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- mylist->assert_notequal([1, 2, 3]) ---- --- < --- --- @param expected any @@ -405,7 +415,7 @@ function vim.fn.assert_notequal(expected, actual, msg) end --- |v:errors| when {pattern} matches {actual}. --- Also see |assert-return|. --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- getFile()->assert_notmatch('bar.*') --- < --- @@ -418,7 +428,7 @@ function vim.fn.assert_notmatch(pattern, actual, msg) end --- Report a test failure directly, using String {msg}. --- Always returns one. --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- GetMessage()->assert_report() --- < --- @@ -433,7 +443,7 @@ function vim.fn.assert_report(msg) end --- When {actual} is not a number or |v:true| the assert fails. --- When {msg} is given it precedes the default message. --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- GetResult()->assert_true() --- < --- @@ -446,14 +456,15 @@ function vim.fn.assert_true(actual, msg) end --- the range [-pi/2, +pi/2] radians, as a |Float|. --- {expr} must evaluate to a |Float| or a |Number|. --- Returns 0.0 if {expr} is not a |Float| or a |Number|. ---- Examples: > ---- :echo atan(100) ---- < 1.560797 > ---- :echo atan(-4.01) +--- Examples: >vim +--- echo atan(100) +--- < 1.560797 >vim +--- echo atan(-4.01) --- < -1.326405 --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- Compute()->atan() +--- < --- --- @param expr any --- @return number @@ -464,14 +475,15 @@ function vim.fn.atan(expr) end --- {expr1} and {expr2} must evaluate to a |Float| or a |Number|. --- Returns 0.0 if {expr1} or {expr2} is not a |Float| or a --- |Number|. ---- Examples: > ---- :echo atan2(-1, 1) ---- < -0.785398 > ---- :echo atan2(1, -1) +--- Examples: >vim +--- echo atan2(-1, 1) +--- < -0.785398 >vim +--- echo atan2(1, -1) --- < 2.356194 --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- Compute()->atan2(1) +--- < --- --- @param expr1 any --- @param expr2 any @@ -479,13 +491,13 @@ function vim.fn.atan(expr) end function vim.fn.atan2(expr1, expr2) end --- Return a List containing the number value of each byte in Blob ---- {blob}. Examples: > ---- blob2list(0z0102.0304) returns [1, 2, 3, 4] ---- blob2list(0z) returns [] +--- {blob}. Examples: >vim +--- blob2list(0z0102.0304) " returns [1, 2, 3, 4] +--- blob2list(0z) " returns [] --- +--- Can also be used as a |method|: >vim --- GetBlob()->blob2list() --- < --- @@ -533,13 +545,14 @@ function vim.fn.browsedir(title, initdir) end --- created buffer. When {name} is an empty string then a new --- buffer is always created. --- The buffer will not have 'buflisted' set and not be loaded ---- yet. To add some text to the buffer use this: > +--- yet. To add some text to the buffer use this: >vim --- let bufnr = bufadd('someName') --- call bufload(bufnr) --- call setbufline(bufnr, 1, ['some', 'text']) --- +--- Can also be used as a |method|: >vim --- let bufnr = 'somename'->bufadd() +--- < --- --- @param name string --- @return integer @@ -566,8 +579,9 @@ function vim.fn.bufadd(name) end --- Use "bufexists(0)" to test for the existence of an alternate --- file name. --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- let exists = 'somename'->bufexists() +--- < --- --- @param buf any --- @return 0|1 @@ -598,8 +612,9 @@ function vim.fn.buffer_number(...) end --- {buf} exists and is listed (has the 'buflisted' option set). --- The {buf} argument is used like with |bufexists()|. --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- let listed = 'somename'->buflisted() +--- < --- --- @param buf any --- @return 0|1 @@ -614,8 +629,9 @@ function vim.fn.buflisted(buf) end --- there will be no dialog, the buffer will be loaded anyway. --- The {buf} argument is used like with |bufexists()|. --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- eval 'somename'->bufload() +--- < --- --- @param buf any function vim.fn.bufload(buf) end @@ -624,8 +640,9 @@ function vim.fn.bufload(buf) end --- {buf} exists and is loaded (shown in a window or hidden). --- The {buf} argument is used like with |bufexists()|. --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- let loaded = 'somename'->bufloaded() +--- < --- --- @param buf any --- @return 0|1 @@ -651,17 +668,17 @@ function vim.fn.bufloaded(buf) end --- with a listed buffer, that one is returned. Next unlisted --- buffers are searched for. --- If the {buf} is a String, but you want to use it as a buffer ---- number, force it to be a Number by adding zero to it: > ---- :echo bufname("3" + 0) ---- +--- number, force it to be a Number by adding zero to it: >vim +--- echo bufname("3" + 0) +--- vim --- echo bufnr->bufname() --- --- ---- bufname("#") alternate buffer name ---- bufname(3) name of buffer 3 ---- bufname("%") name of current buffer ---- bufname("file2") name of buffer where "file2" matches. +--- string is returned. >vim +--- echo bufname("#") " alternate buffer name +--- echo bufname(3) " name of buffer 3 +--- echo bufname("%") " name of current buffer +--- echo bufname("file2") " name of buffer where "file2" matches. --- < --- --- @param buf? any @@ -674,15 +691,16 @@ function vim.fn.bufname(buf) end --- If the buffer doesn't exist, -1 is returned. Or, if the --- {create} argument is present and TRUE, a new, unlisted, --- buffer is created and its number is returned. ---- bufnr("$") is the last buffer: > ---- :let last_buffer = bufnr("$") +--- bufnr("$") is the last buffer: >vim +--- let last_buffer = bufnr("$") --- +--- Can also be used as a |method|: >vim --- echo bufref->bufnr() +--- < --- --- @param buf? any --- @param create? any @@ -692,15 +710,16 @@ function vim.fn.bufnr(buf, create) end --- The result is a Number, which is the |window-ID| of the first --- window associated with buffer {buf}. For the use of {buf}, --- see |bufname()| above. If buffer {buf} doesn't exist or ---- there is no such window, -1 is returned. Example: > +--- there is no such window, -1 is returned. Example: >vim --- --- echo "A window containing buffer 1 is " .. (bufwinid(1)) --- < --- Only deals with the current tab page. See |win_findbuf()| for --- finding more. --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- FindBuffer()->bufwinid() +--- < --- --- @param buf any --- @return integer @@ -709,15 +728,16 @@ function vim.fn.bufwinid(buf) end --- Like |bufwinid()| but return the window number instead of the --- |window-ID|. --- If buffer {buf} doesn't exist or there is no such window, -1 ---- is returned. Example: > +--- is returned. Example: >vim --- --- echo "A window containing buffer 1 is " .. (bufwinnr(1)) --- --- +--- Can also be used as a |method|: >vim --- FindBuffer()->bufwinnr() +--- < --- --- @param buf any --- @return integer @@ -732,8 +752,9 @@ function vim.fn.bufwinnr(buf) end --- --- Returns -1 if the {byte} value is invalid. --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- GetOffset()->byte2line() +--- < --- --- @param byte any --- @return integer @@ -755,10 +776,10 @@ function vim.fn.byte2line(byte) end --- middle of a character (e.g. in a 4-byte character), then the --- byte index of the first byte in the character is returned. --- Refer to |string-offset-encoding| for more information. ---- Example : > +--- Example : >vim --- echo matchstr(str, ".", byteidx(str, 3)) --- +--- same: >vim --- let s = strpart(str, byteidx(str, 3)) --- echo strpart(s, 0, byteidx(s, 1)) --- ---- echo byteidx('a😊😊', 2) returns 5 ---- echo byteidx('a😊😊', 2, 1) returns 1 ---- echo byteidx('a😊😊', 3, 1) returns 5 +--- Examples: >vim +--- echo byteidx('a😊😊', 2) " returns 5 +--- echo byteidx('a😊😊', 2, 1) " returns 1 +--- echo byteidx('a😊😊', 3, 1) " returns 5 --- < ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- GetName()->byteidx(idx) +--- < --- --- @param expr any --- @param nr integer @@ -783,7 +805,7 @@ function vim.fn.byte2line(byte) end function vim.fn.byteidx(expr, nr, utf16) end --- Like byteidx(), except that a composing character is counted ---- as a separate character. Example: > +--- as a separate character. Example: >vim --- let s = 'e' .. nr2char(0x301) --- echo byteidx(s, 1) --- echo byteidxcomp(s, 1) @@ -792,8 +814,9 @@ function vim.fn.byteidx(expr, nr, utf16) end --- character is 3 bytes), the second echo results in 1 ('e' is --- one byte). --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- GetName()->byteidxcomp(idx) +--- < --- --- @param expr any --- @param nr integer @@ -809,7 +832,7 @@ function vim.fn.byteidxcomp(expr, nr, utf16) end --- {dict} is for functions with the "dict" attribute. It will be --- used to set the local variable "self". |Dictionary-function| --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- GetFunc()->call([arg, arg], dict) --- < --- @@ -822,17 +845,17 @@ function vim.fn.call(func, arglist, dict) end --- Return the smallest integral value greater than or equal to --- {expr} as a |Float| (round up). --- {expr} must evaluate to a |Float| or a |Number|. ---- Examples: > +--- Examples: >vim --- echo ceil(1.456) ---- < 2.0 > +--- < 2.0 >vim --- echo ceil(-5.456) ---- < -5.0 > +--- < -5.0 >vim --- echo ceil(4.0) --- < 4.0 --- --- Returns 0.0 if {expr} is not a |Float| or a |Number|. --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- Compute()->ceil() --- < --- @@ -874,8 +897,8 @@ function vim.fn.changenr() end --- {data} may be a string, string convertible, |Blob|, or a list. --- If {data} is a list, the items will be joined by newlines; any --- newlines in an item will be sent as NUL. To send a final ---- newline, include a final empty string. Example: > ---- :call chansend(id, ["abc", "123\n456", ""]) +--- newline, include a final empty string. Example: >vim +--- call chansend(id, ["abc", "123\n456", ""]) --- 123456". --- --- chansend() writes raw data, not RPC messages. If the channel @@ -888,12 +911,12 @@ function vim.fn.changenr() end function vim.fn.chansend(id, data) end --- Return Number value of the first char in {string}. ---- Examples: > ---- char2nr(" ") returns 32 ---- char2nr("ABC") returns 65 ---- char2nr("Γ‘") returns 225 ---- char2nr("Γ‘"[0]) returns 195 ---- char2nr("\") returns 128 +--- Examples: >vim +--- echo char2nr(" ") " returns 32 +--- echo char2nr("ABC") " returns 65 +--- echo char2nr("Γ‘") " returns 225 +--- echo char2nr("Γ‘"[0]) " returns 195 +--- echo char2nr("\") " returns 128 --- +--- Can also be used as a |method|: >vim --- GetChar()->char2nr() +--- < --- --- @param string string --- @param utf8? any @@ -927,11 +951,11 @@ function vim.fn.charclass(string) end --- position given with {expr} instead of the byte position. --- --- Example: ---- With the cursor on 'μ„Έ' in line 5 with text "μ—¬λ³΄μ„Έμš”": > ---- charcol('.') returns 3 ---- col('.') returns 7 +--- With the cursor on 'μ„Έ' in line 5 with text "μ—¬λ³΄μ„Έμš”": >vim +--- echo charcol('.') " returns 3 +--- echo col('.') " returns 7 --- ---- +--- vim --- GetPos()->col() --- < --- @@ -966,14 +990,15 @@ function vim.fn.charcol(expr, winid) end --- from the character index and |utf16idx()| for getting the --- UTF-16 index from the character index. --- Refer to |string-offset-encoding| for more information. ---- Examples: > ---- echo charidx('áb́ć', 3) returns 1 ---- echo charidx('áb́ć', 6, 1) returns 4 ---- echo charidx('áb́ć', 16) returns -1 ---- echo charidx('a😊😊', 4, 0, 1) returns 2 +--- Examples: >vim +--- echo charidx('áb́ć', 3) " returns 1 +--- echo charidx('áb́ć', 6, 1) " returns 4 +--- echo charidx('áb́ć', 16) " returns -1 +--- echo charidx('a😊😊', 4, 0, 1) " returns 2 --- < ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- GetName()->charidx(idx) +--- < --- --- @param string string --- @param idx integer @@ -996,14 +1021,14 @@ function vim.fn.charidx(string, idx, countcc, utf16) end --- this to another chdir() to restore the directory. --- On failure, returns an empty string. --- ---- Example: > +--- Example: >vim --- let save_dir = chdir(newdir) --- if save_dir != "" --- " ... do some work --- call chdir(save_dir) --- endif --- ---- +--- vim --- GetDir()->chdir() --- < --- @@ -1018,8 +1043,9 @@ function vim.fn.chdir(dir) end --- When {lnum} is invalid -1 is returned. --- See |C-indenting|. --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- GetLnum()->cindent() +--- < --- --- @param lnum integer --- @return integer @@ -1030,7 +1056,7 @@ function vim.fn.cindent(lnum) end --- If {win} is specified, use the window with this number or --- window ID instead of the current window. --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- GetWin()->clearmatches() --- < --- @@ -1059,11 +1085,11 @@ function vim.fn.clearmatches(win) end --- For the screen column position use |virtcol()|. For the --- character position use |charcol()|. --- Note that only marks in the current file can be used. ---- Examples: > ---- col(".") column of cursor ---- col("$") length of cursor line plus one ---- col("'t") column of mark t ---- col("'" .. markname) column of mark markname +--- Examples: >vim +--- echo col(".") " column of cursor +--- echo col("$") " length of cursor line plus one +--- echo col("'t") " column of mark t +--- echo col("'" .. markname) " column of mark markname --- mapping the cursor isn't ---- moved, this can be used to obtain the column in Insert mode: > ---- :imap echo col(".").."\n" +--- moved, this can be used to obtain the column in Insert mode: >vim +--- imap echo col(".").."\n" --- ---- +--- vim --- GetPos()->col() --- < --- @@ -1100,7 +1126,7 @@ function vim.fn.col(expr, winid) end --- The match can be selected with CTRL-N and CTRL-P as usual with --- Insert mode completion. The popup menu will appear if --- specified, see |ins-completion-menu|. ---- Example: > +--- Example: >vim --- inoremap =ListMonths() --- --- func ListMonths() @@ -1113,8 +1139,9 @@ function vim.fn.col(expr, winid) end --- an empty string is returned to avoid a zero being inserted. --- --- Can also be used as a |method|, the base is passed as the ---- second argument: > +--- second argument: >vim --- GetMatches()->complete(col('.')) +--- < --- --- @param startcol any --- @param matches any @@ -1128,8 +1155,9 @@ function vim.fn.complete(startcol, matches) end --- See |complete-functions| for an explanation of {expr}. It is --- the same as one item in the list that 'omnifunc' would return. --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- GetMoreMatches()->complete_add() +--- < --- --- @param expr any --- @return 0|1|2 @@ -1194,7 +1222,7 @@ function vim.fn.complete_check() end --- --- Returns an empty |Dictionary| on error. --- ---- Examples: > +--- Examples: >vim --- " Get all items --- call complete_info() --- " Get only 'mode' @@ -1202,7 +1230,7 @@ function vim.fn.complete_check() end --- " Get only 'mode' and 'pum_visible' --- call complete_info(['mode', 'pum_visible']) --- ---- +--- vim --- GetItems()->complete_info() --- < --- @@ -1221,11 +1249,11 @@ function vim.fn.complete_info(what) end --- some systems the string is wrapped when it doesn't fit. --- --- {choices} is a String, with the individual choices separated ---- by '\n', e.g. > +--- by '\n', e.g. >vim --- confirm("Save changes?", "&Yes\n&No\n&Cancel") --- +--- not need to be the first letter: >vim --- confirm("file has been modified", "&Save\nSave &All") --- , CTRL-C, --- or another valid interrupt key, confirm() returns 0. --- ---- An example: > +--- An example: >vim --- let choice = confirm("What do you want?", --- \ "&Apples\n&Oranges\n&Bananas", 2) --- if choice == 0 @@ -1261,7 +1289,7 @@ function vim.fn.complete_info(what) end --- don't fit, a vertical layout is used anyway. For some systems --- the horizontal layout is always used. --- ---- Can also be used as a |method|in: > +--- Can also be used as a |method|in: >vim --- BuildMessage()->confirm("&Yes\n&No") --- < --- @@ -1280,8 +1308,9 @@ function vim.fn.confirm(msg, choices, default, type) end --- changing an item changes the contents of both |Lists|. --- A |Dictionary| is copied in a similar way as a |List|. --- Also see |deepcopy()|. ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- mylist->copy() +--- < --- --- @param expr any --- @return any @@ -1290,14 +1319,15 @@ function vim.fn.copy(expr) end --- Return the cosine of {expr}, measured in radians, as a |Float|. --- {expr} must evaluate to a |Float| or a |Number|. --- Returns 0.0 if {expr} is not a |Float| or a |Number|. ---- Examples: > ---- :echo cos(100) ---- < 0.862319 > ---- :echo cos(-4.01) +--- Examples: >vim +--- echo cos(100) +--- < 0.862319 >vim +--- echo cos(-4.01) --- < -0.646043 --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- Compute()->cos() +--- < --- --- @param expr any --- @return number @@ -1307,14 +1337,15 @@ function vim.fn.cos(expr) end --- [1, inf]. --- {expr} must evaluate to a |Float| or a |Number|. --- Returns 0.0 if {expr} is not a |Float| or a |Number|. ---- Examples: > ---- :echo cosh(0.5) ---- < 1.127626 > ---- :echo cosh(-0.5) +--- Examples: >vim +--- echo cosh(0.5) +--- < 1.127626 >vim +--- echo cosh(-0.5) --- < -1.127626 --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- Compute()->cosh() +--- < --- --- @param expr any --- @return number @@ -1332,7 +1363,7 @@ function vim.fn.cosh(expr) end --- occurrences of {expr} is returned. Zero is returned when --- {expr} is an empty string. --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- mylist->count(val) --- < --- @@ -1419,8 +1450,9 @@ function vim.fn.cursor(lnum, col, off) end --- position within a or after the last character. --- Returns 0 when the position could be set, -1 otherwise. --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- GetCursorPos()->cursor() +--- < --- --- @param list any --- @return any @@ -1434,7 +1466,7 @@ function vim.fn.cursor(list) end --- Returns |TRUE| if successfully interrupted the program. --- Otherwise returns |FALSE|. --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- GetPid()->debugbreak() --- < --- @@ -1461,8 +1493,9 @@ function vim.fn.debugbreak(pid) end --- {noref} set to 1 will fail. --- Also see |copy()|. --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- GetObject()->deepcopy() +--- < --- --- @param expr any --- @param noref? any @@ -1487,8 +1520,9 @@ function vim.fn.deepcopy(expr, noref) end --- operation was successful and -1/true when the deletion failed --- or partly failed. --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- GetName()->delete() +--- < --- --- @param fname integer --- @param flags? string @@ -1508,7 +1542,7 @@ function vim.fn.delete(fname, flags) end --- when using |line()| this refers to the current buffer. Use "$" --- to refer to the last line in buffer {buf}. --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- GetBuffer()->deletebufline(1) --- < --- @@ -1528,7 +1562,7 @@ function vim.fn.deletebufline(buf, first, last) end --- After this is called, every change on {dict} and on keys --- matching {pattern} will result in {callback} being invoked. --- ---- For example, to watch all global variables: > +--- For example, to watch all global variables: >vim --- silent! call dictwatcherdel(g:, '*', 'OnDictChanged') --- function! OnDictChanged(d,k,z) --- echomsg string(a:k) string(a:z) @@ -1595,8 +1629,9 @@ function vim.fn.did_filetype() end --- line, "'m" mark m, etc. --- Returns 0 if the current window is not in diff mode. --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- GetLnum()->diff_filler() +--- < --- --- @param lnum integer --- @return any @@ -1612,7 +1647,7 @@ function vim.fn.diff_filler(lnum) end --- The highlight ID can be used with |synIDattr()| to obtain --- syntax information about the highlighting. --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- GetLnum()->diff_hlID(col) --- < --- @@ -1628,15 +1663,15 @@ function vim.fn.diff_hlID(lnum, col) end --- --- Also see |digraph_getlist()|. --- ---- Examples: > +--- Examples: >vim --- " Get a built-in digraph ---- :echo digraph_get('00') " Returns '∞' +--- echo digraph_get('00') " Returns '∞' --- --- " Get a user-defined digraph ---- :call digraph_set('aa', 'あ') ---- :echo digraph_get('aa') " Returns 'あ' +--- call digraph_set('aa', 'あ') +--- echo digraph_get('aa') " Returns 'あ' --- < ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- GetChars()->digraph_get() --- < --- @@ -1650,14 +1685,14 @@ function vim.fn.digraph_get(chars) end --- --- Also see |digraph_get()|. --- ---- Examples: > +--- Examples: >vim --- " Get user-defined digraphs ---- :echo digraph_getlist() +--- echo digraph_getlist() --- --- " Get all the digraphs, including default digraphs ---- :echo digraph_getlist(1) +--- echo digraph_getlist(1) --- < ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- GetNumber()->digraph_getlist() --- < --- @@ -1678,10 +1713,10 @@ function vim.fn.digraph_getlist(listall) end --- If you want to define multiple digraphs at once, you can use --- |digraph_setlist()|. --- ---- Example: > +--- Example: >vim --- call digraph_set(' ', 'あ') --- < ---- Can be used as a |method|: > +--- Can be used as a |method|: >vim --- GetString()->digraph_set('あ') --- < --- @@ -1694,17 +1729,17 @@ function vim.fn.digraph_set(chars, digraph) end --- digraphs at once. {digraphlist} is a list composed of lists, --- where each list contains two strings with {chars} and --- {digraph} as in |digraph_set()|. *E1216* ---- Example: > +--- Example: >vim --- call digraph_setlist([['aa', 'あ'], ['ii', 'い']]) --- < ---- It is similar to the following: > +--- It is similar to the following: >vim --- for [chars, digraph] in [['aa', 'あ'], ['ii', 'い']] --- call digraph_set(chars, digraph) --- endfor --- +--- Can be used as a |method|: >vim --- GetList()->digraph_setlist() --- < --- @@ -1720,31 +1755,33 @@ function vim.fn.digraph_setlist(digraphlist) end --- - |v:false| and |v:null| are empty, |v:true| is not. --- - A |Blob| is empty when its length is zero. --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- mylist->empty() +--- < --- --- @param expr any --- @return any function vim.fn.empty(expr) end --- Return all of environment variables as dictionary. You can ---- check if an environment variable exists like this: > ---- :echo has_key(environ(), 'HOME') +--- check if an environment variable exists like this: >vim +--- echo has_key(environ(), 'HOME') --- ---- :echo index(keys(environ()), 'HOME', 0, 1) != -1 +--- use this: >vim +--- echo index(keys(environ()), 'HOME', 0, 1) != -1 +--- < --- --- @return any function vim.fn.environ() end --- Escape the characters in {chars} that occur in {string} with a ---- backslash. Example: > ---- :echo escape('c:\program files\vim', ' \') +--- backslash. Example: >vim +--- echo escape('c:\program files\vim', ' \') --- --- c:\\program\ files\\vim --- +--- Can also be used as a |method|: >vim --- GetText()->escape(' \') --- < --- @@ -1759,8 +1796,9 @@ function vim.fn.escape(string, chars) end --- of them. Also works for |Funcref|s that refer to existing --- functions. --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- argv->join()->eval() +--- < --- --- @param string string --- @return any @@ -1796,8 +1834,9 @@ function vim.fn.eventhandler() end --- -1 not implemented on this system --- |exepath()| can be used to get the full path of an executable. --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- GetCommand()->executable() +--- < --- --- @param expr any --- @return any @@ -1807,9 +1846,9 @@ function vim.fn.executable(expr) end --- If {command} is a |String|, returns {command} output. --- If {command} is a |List|, returns concatenated outputs. --- Line continuations in {command} are not recognized. ---- Examples: > +--- Examples: >vim --- echo execute('echon "foo"') ---- < foo > +--- < foo >vim --- echo execute(['echon "foo"', 'echon "bar"']) --- < foobar --- @@ -1820,7 +1859,7 @@ function vim.fn.executable(expr) end --- The default is "silent". Note that with "silent!", unlike --- `:redir`, error messages are dropped. --- ---- To get a list of lines use `split()` on the result: > +--- To get a list of lines use `split()` on the result: >vim --- execute('args')->split("\n") --- --- +--- Can also be used as a |method|: >vim --- GetCommand()->execute() +--- < --- --- @param command any --- @param silent? boolean @@ -1843,7 +1883,7 @@ function vim.fn.execute(command, silent) end --- Returns empty string otherwise. --- If {expr} starts with "./" the |current-directory| is used. --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- GetCommand()->exepath() --- < --- @@ -1864,11 +1904,11 @@ function vim.fn.exepath(expr) end --- entries, |List| items, etc. --- Beware that evaluating an index may --- cause an error message for an invalid ---- expression. E.g.: > ---- :let l = [1, 2, 3] ---- :echo exists("l[5]") ---- < 0 > ---- :echo exists("l[xx]") +--- expression. E.g.: >vim +--- let l = [1, 2, 3] +--- echo exists("l[5]") +--- < 0 >vim +--- echo exists("l[xx]") --- < E121: Undefined variable: xx --- 0 --- &option-name Vim option (only checks if it exists, @@ -1908,38 +1948,39 @@ function vim.fn.exepath(expr) end --- ##event autocommand for this event is --- supported. --- ---- Examples: > ---- exists("&mouse") ---- exists("$HOSTNAME") ---- exists("*strftime") ---- exists("*s:MyFunc") ---- exists("*MyFunc") ---- exists("bufcount") ---- exists(":Make") ---- exists("#CursorHold") ---- exists("#BufReadPre#*.gz") ---- exists("#filetypeindent") ---- exists("#filetypeindent#FileType") ---- exists("#filetypeindent#FileType#*") ---- exists("##ColorScheme") +--- Examples: >vim +--- echo exists("&mouse") +--- echo exists("$HOSTNAME") +--- echo exists("*strftime") +--- echo exists("*s:MyFunc") +--- echo exists("*MyFunc") +--- echo exists("bufcount") +--- echo exists(":Make") +--- echo exists("#CursorHold") +--- echo exists("#BufReadPre#*.gz") +--- echo exists("#filetypeindent") +--- echo exists("#filetypeindent#FileType") +--- echo exists("#filetypeindent#FileType#*") +--- echo exists("##ColorScheme") --- ---- exists(":make") ---- ---- exists(":make install") +--- Working example: >vim +--- echo exists(":make") +--- vim +--- echo exists(":make install") --- --- ---- exists(bufcount) +--- variable itself. For example: >vim +--- echo exists(bufcount) --- +--- Can also be used as a |method|: >vim --- Varname()->exists() +--- < --- --- @param expr any --- @return 0|1 @@ -1949,14 +1990,15 @@ function vim.fn.exists(expr) end --- [0, inf]. --- {expr} must evaluate to a |Float| or a |Number|. --- Returns 0.0 if {expr} is not a |Float| or a |Number|. ---- Examples: > ---- :echo exp(2) ---- < 7.389056 > ---- :echo exp(-1) +--- Examples: >vim +--- echo exp(2) +--- < 7.389056 >vim +--- echo exp(-1) --- < 0.367879 --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- Compute()->exp() +--- < --- --- @param expr any --- @return any @@ -2006,18 +2048,18 @@ function vim.fn.exp(expr) end --- :r root (one extension removed) --- :e extension only --- ---- Example: > ---- :let &tags = expand("%:p:h") .. "/tags" +--- Example: >vim +--- let &tags = expand("%:p:h") .. "/tags" --- ---- :let doesntwork = expand("%:h.bak") ---- ---- :let doeswork = expand("%:h") .. ".bak" +--- '<', any following text is ignored. This does NOT work: >vim +--- let doesntwork = expand("%:h.bak") +--- vim +--- let doeswork = expand("%:h") .. ".bak" --- " and others only returns the --- referenced file name without further expansion. If "" --- is "~/.cshrc", you need to do another expand() to have the ---- "~/" expanded into the path of the home directory: > ---- :echo expand(expand("")) +--- "~/" expanded into the path of the home directory: >vim +--- echo expand(expand("")) --- < --- There cannot be white space between the variables and the --- following modifier. The |fnamemodify()| function can be used @@ -2037,8 +2079,8 @@ function vim.fn.exp(expr) end --- {nosuf} argument is given and it is |TRUE|. --- Names for non-existing files are included. The "**" item can --- be used to search in a directory tree. For example, to find ---- all "README" files in the current directory and below: > ---- :echo expand("**/README") +--- all "README" files in the current directory and below: >vim +--- echo expand("**/README") --- < --- expand() can also be used to expand variables and environment --- variables that are only known in a shell. But this can be @@ -2052,8 +2094,9 @@ function vim.fn.exp(expr) end --- See |glob()| for finding existing files. See |system()| for --- getting the raw output of an external command. --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- Getpattern()->expand() +--- < --- --- @param string string --- @param nosuf? boolean @@ -2076,12 +2119,14 @@ function vim.fn.expand(string, nosuf, list) end --- Returns the expanded string. If an error is encountered --- during expansion, the unmodified {string} is returned. --- ---- Example: > ---- :echo expandcmd('make %<.o') +--- Example: >vim +--- echo expandcmd('make %<.o') +--- < > --- make /path/runtime/doc/builtin.o ---- :echo expandcmd('make %<.o', {'errmsg': v:true}) +--- < >vim +--- echo expandcmd('make %<.o', {'errmsg': v:true}) --- < ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- GetCommand()->expandcmd() --- < --- @@ -2098,16 +2143,16 @@ function vim.fn.expandcmd(string, options) end --- item with index {expr3} in {expr1}. When {expr3} is zero --- insert before the first item. When {expr3} is equal to --- len({expr1}) then {expr2} is appended. ---- Examples: > ---- :echo sort(extend(mylist, [7, 5])) ---- :call extend(mylist, [2, 3], 1) +--- Examples: >vim +--- echo sort(extend(mylist, [7, 5])) +--- call extend(mylist, [2, 3], 1) --- ---- :let newlist = [1, 2, 3] + [4, 5] +--- two lists into a new list use the + operator: >vim +--- let newlist = [1, 2, 3] + [4, 5] --- < --- If they are |Dictionaries|: --- Add all entries from {expr2} to {expr1}. @@ -2125,7 +2170,7 @@ function vim.fn.expandcmd(string, options) end --- fails. --- Returns {expr1}. Returns 0 on error. --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- mylist->extend(otherlist) --- < --- @@ -2189,8 +2234,9 @@ function vim.fn.extendnew(expr1, expr2, expr3) end --- --- Return value is always 0. --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- GetInput()->feedkeys() +--- < --- --- @param string string --- @param mode? string @@ -2210,14 +2256,19 @@ function vim.fn.file_readable(file) end --- expression, which is used as a String. --- If you don't care about the file being readable you can use --- |glob()|. ---- {file} is used as-is, you may want to expand wildcards first: > +--- {file} is used as-is, you may want to expand wildcards first: >vim --- echo filereadable('~/.vimrc') +--- < > --- 0 +--- < >vim --- echo filereadable(expand('~/.vimrc')) +--- < > --- 1 +--- < --- ---- +--- Can also be used as a |method|: >vim --- GetName()->filereadable() +--- < --- --- @param file string --- @return 0|1 @@ -2228,8 +2279,9 @@ function vim.fn.filereadable(file) end --- exist, or is not writable, the result is 0. If {file} is a --- directory, and we can write to it, the result is 2. --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- GetName()->filewritable() +--- < --- --- @param file string --- @return 0|1 @@ -2248,11 +2300,11 @@ function vim.fn.filewritable(file) end --- the current item. For a |Blob| |v:key| has the index of the --- current byte. --- ---- Examples: > +--- Examples: >vim --- call filter(mylist, 'v:val !~ "OLD"') ---- +--- vim --- call filter(mydict, 'v:key >= 8') ---- +--- vim --- call filter(var, 0) --- +--- Example that keeps the odd items of a list: >vim --- func Odd(idx, val) --- return a:idx % 2 == 1 --- endfunc --- call filter(mylist, function('Odd')) ---- +--- vim --- call filter(myList, {idx, val -> idx * val <= 42}) ---- +--- vim --- call filter(myList, {idx -> idx % 2 == 1}) --- < --- The operation is done in-place. If you want a |List| or ---- |Dictionary| to remain unmodified make a copy first: > ---- :let l = filter(copy(mylist), 'v:val =~ "KEEP"') +--- |Dictionary| to remain unmodified make a copy first: >vim +--- let l = filter(copy(mylist), 'v:val =~ "KEEP"') --- --- +--- Can also be used as a |method|: >vim --- mylist->filter(expr2) +--- < --- --- @param expr1 any --- @param expr2 any @@ -2309,8 +2362,9 @@ function vim.fn.filter(expr1, expr2) end --- --- This is quite similar to the ex-command `:find`. --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- GetName()->finddir() +--- < --- --- @param name string --- @param path? string @@ -2320,13 +2374,14 @@ function vim.fn.finddir(name, path, count) end --- Just like |finddir()|, but find a file instead of a directory. --- Uses 'suffixesadd'. ---- Example: > ---- :echo findfile("tags.vim", ".;") +--- Example: >vim +--- echo findfile("tags.vim", ".;") --- +--- Can also be used as a |method|: >vim --- GetName()->findfile() +--- < --- --- @param name string --- @param path? string @@ -2346,13 +2401,13 @@ function vim.fn.findfile(name, path, count) end --- --- If there is an error the number zero is returned. --- ---- Example: > ---- :echo flatten([1, [2, [3, 4]], 5]) ---- < [1, 2, 3, 4, 5] > ---- :echo flatten([1, [2, [3, 4]], 5], 1) +--- Example: >vim +--- echo flatten([1, [2, [3, 4]], 5]) +--- < [1, 2, 3, 4, 5] >vim +--- echo flatten([1, [2, [3, 4]], 5], 1) --- < [1, 2, [3, 4], 5] --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- mylist->flatten() --- < --- @@ -2377,20 +2432,21 @@ function vim.fn.flattennew(list, maxdepth) end --- 64-bit Number support is enabled, 0x7fffffffffffffff or --- -0x7fffffffffffffff). NaN results in -0x80000000 (or when --- 64-bit Number support is enabled, -0x8000000000000000). ---- Examples: > +--- Examples: >vim --- echo float2nr(3.95) ---- < 3 > +--- < 3 >vim --- echo float2nr(-23.45) ---- < -23 > +--- < -23 >vim --- echo float2nr(1.0e100) ---- < 2147483647 (or 9223372036854775807) > +--- < 2147483647 (or 9223372036854775807) >vim --- echo float2nr(-1.0e150) ---- < -2147483647 (or -9223372036854775807) > +--- < -2147483647 (or -9223372036854775807) >vim --- echo float2nr(1.0e-100) --- < 0 --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- Compute()->float2nr() +--- < --- --- @param expr any --- @return any @@ -2400,16 +2456,17 @@ function vim.fn.float2nr(expr) end --- {expr} as a |Float| (round down). --- {expr} must evaluate to a |Float| or a |Number|. --- Returns 0.0 if {expr} is not a |Float| or a |Number|. ---- Examples: > +--- Examples: >vim --- echo floor(1.856) ---- < 1.0 > +--- < 1.0 >vim --- echo floor(-5.456) ---- < -6.0 > +--- < -6.0 >vim --- echo floor(4.0) --- < 4.0 --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- Compute()->floor() +--- < --- --- @param expr any --- @return any @@ -2424,14 +2481,15 @@ function vim.fn.floor(expr) end --- {expr1} and {expr2} must evaluate to a |Float| or a |Number|. --- Returns 0.0 if {expr1} or {expr2} is not a |Float| or a --- |Number|. ---- Examples: > ---- :echo fmod(12.33, 1.22) ---- < 0.13 > ---- :echo fmod(-12.33, 1.22) +--- Examples: >vim +--- echo fmod(12.33, 1.22) +--- < 0.13 >vim +--- echo fmod(-12.33, 1.22) --- < -0.13 --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- Compute()->fmod(1.22) +--- < --- --- @param expr1 any --- @param expr2 any @@ -2439,7 +2497,7 @@ function vim.fn.floor(expr) end function vim.fn.fmod(expr1, expr2) end --- Escape {string} for use as file name command argument. All ---- characters that have a special meaning, such as '%' and '|' +--- characters that have a special meaning, such as `'%'` and `'|'` --- are escaped with a backslash. --- For most systems the characters escaped are --- " \t\n*?[{`$\\%#'\"|!<". For systems where a backslash @@ -2447,14 +2505,15 @@ function vim.fn.fmod(expr1, expr2) end --- A leading '+' and '>' is also escaped (special after |:edit| --- and |:write|). And a "-" by itself (special after |:cd|). --- Returns an empty string on error. ---- Example: > ---- :let fname = '+some str%nge|name' ---- :exe "edit " .. fnameescape(fname) ---- +--- Example: >vim +--- let fname = '+some str%nge|name' +--- exe "edit " .. fnameescape(fname) +--- vim --- edit \+some\ str\%nge\|name --- < ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- GetName()->fnameescape() +--- < --- --- @param string string --- @return string @@ -2463,8 +2522,8 @@ function vim.fn.fnameescape(string) end --- Modify file name {fname} according to {mods}. {mods} is a --- string of characters like it is used for file names on the --- command line. See |filename-modifiers|. ---- Example: > ---- :echo fnamemodify("main.c", ":p:h") +--- Example: >vim +--- echo fnamemodify("main.c", ":p:h") --- --- /home/user/vim/vim/src --- +--- Can also be used as a |method|: >vim --- GetName()->fnamemodify(':p:h') +--- < --- --- @param fname integer --- @param mods string @@ -2490,8 +2550,9 @@ function vim.fn.fnamemodify(fname, mods) end --- {lnum} is used like with |getline()|. Thus "." is the current --- line, "'m" mark m, etc. --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- GetLnum()->foldclosed() +--- < --- --- @param lnum integer --- @return integer @@ -2503,8 +2564,9 @@ function vim.fn.foldclosed(lnum) end --- {lnum} is used like with |getline()|. Thus "." is the current --- line, "'m" mark m, etc. --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- GetLnum()->foldclosedend() +--- < --- --- @param lnum integer --- @return integer @@ -2521,7 +2583,7 @@ function vim.fn.foldclosedend(lnum) end --- {lnum} is used like with |getline()|. Thus "." is the current --- line, "'m" mark m, etc. --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- GetLnum()->foldlevel() --- < --- @@ -2556,7 +2618,7 @@ function vim.fn.foldtext() end --- line, "'m" mark m, etc. --- Useful when exporting folded text, e.g., to HTML. --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- GetLnum()->foldtextresult() --- < --- @@ -2575,7 +2637,7 @@ function vim.fn.foldtextresult(lnum) end --- For example `fullcommand('s')`, `fullcommand('sub')`, --- `fullcommand(':%substitute')` all return "substitute". --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- GetName()->fullcommand() --- < --- @@ -2594,7 +2656,7 @@ function vim.fn.fullcommand(name) end --- instead). {name} cannot be a builtin function. --- Returns 0 on error. --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- GetFuncname()->funcref([arg]) --- < --- @@ -2610,7 +2672,7 @@ function vim.fn.funcref(name, arglist, dict) end --- --- {name} can also be a Funcref or a partial. When it is a --- partial the dict stored in it will be used and the {dict} ---- argument is not allowed. E.g.: > +--- argument is not allowed. E.g.: >vim --- let FuncWithArg = function(dict.Func, [arg]) --- let Broken = function(dict.Func, [arg], dict) --- < @@ -2623,38 +2685,41 @@ function vim.fn.funcref(name, arglist, dict) end --- the Funcref and will be used when the Funcref is called. --- --- The arguments are passed to the function in front of other ---- arguments, but after any argument from |method|. Example: > +--- arguments, but after any argument from |method|. Example: >vim --- func Callback(arg1, arg2, name) --- "... +--- endfunc --- let Partial = function('Callback', ['one', 'two']) --- "... --- call Partial('name') ---- +--- vim --- call Callback('one', 'two', 'name') --- ---- +--- vim --- func Callback(one, two, three) --- "... +--- endfunc --- let Partial = function('Callback', ['two']) --- "... --- eval 'one'->Partial('three') ---- +--- vim --- call Callback('one', 'two', 'three') --- --- +--- arguments. Example: >vim --- func Callback(arg1, arg2, name) --- "... +--- endfunc --- let Func = function('Callback', ['one']) --- let Func2 = function(Func, ['two']) --- "... --- call Func2('name') ---- +--- vim --- call Callback('one', 'two', 'name') --- --- +--- In that case the {dict} is passed in as "self". Example: >vim --- function Callback() dict --- echo "called for " .. self.name --- endfunction @@ -2665,24 +2730,26 @@ function vim.fn.funcref(name, arglist, dict) end --- call Func() " will echo: called for example --- +--- as context.Callback(): >vim --- let Func = function('Callback', context) --- let Func = context.Callback --- ---- +--- vim --- function Callback(arg1, count) dict --- "... +--- endfunction --- let context = {"name": "example"} --- let Func = function('Callback', ['one'], context) --- "... --- call Func(500) ---- +--- vim --- call context.Callback('one', 500) --- < --- Returns 0 on error. --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- GetFuncname()->function([arg]) +--- < --- --- @param name string --- @param arglist? any @@ -2716,8 +2783,9 @@ function vim.fn.garbagecollect(atexit) end --- Get item {idx} from |List| {list}. When this item is not --- available return {default}. Return zero when {default} is --- omitted. ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- mylist->get(idx) +--- < --- --- @param list any[] --- @param idx integer @@ -2737,7 +2805,7 @@ function vim.fn.get(blob, idx, default) end --- Get item with key {key} from |Dictionary| {dict}. When this --- item is not available return {default}. Return zero when ---- {default} is omitted. Useful example: > +--- {default} is omitted. Useful example: >vim --- let val = get(g:, 'var_name', 'default') --- ---- :echo line('.', {winid}) +--- window, use |line()|: >vim +--- echo line('.', {winid}) --- < --- linecount Number of lines in the buffer (only --- valid when loaded) @@ -2816,20 +2884,20 @@ function vim.fn.getbufinfo(buf) end --- windows List of |window-ID|s that display this --- buffer --- ---- Examples: > +--- Examples: >vim --- for buf in getbufinfo() --- echo buf.name --- endfor --- for buf in getbufinfo({'buflisted':1}) --- if buf.changed ---- .... +--- " .... --- endif --- endfor --- < ---- To get buffer-local options use: > +--- To get buffer-local options use: >vim --- getbufvar({bufnr}, '&option_name') --- < ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- GetBufnr()->getbufinfo() --- < --- @@ -2858,10 +2926,10 @@ function vim.fn.getbufinfo(dict) end --- This function works only for loaded buffers. For unloaded and --- non-existing buffers, an empty |List| is returned. --- ---- Example: > ---- :let lines = getbufline(bufnr("myfile"), 1, "$") +--- Example: >vim +--- let lines = getbufline(bufnr("myfile"), 1, "$") --- ---- +--- vim --- GetBufnr()->getbufline(lnum) --- < --- @@ -2895,11 +2963,11 @@ function vim.fn.getbufoneline(buf, lnum) end --- For the use of {buf}, see |bufname()| above. --- When the buffer or variable doesn't exist {def} or an empty --- string is returned, there is no error message. ---- Examples: > ---- :let bufmodified = getbufvar(1, "&mod") ---- :echo "todo myvar = " .. getbufvar("todo", "myvar") +--- Examples: >vim +--- let bufmodified = getbufvar(1, "&mod") +--- echo "todo myvar = " .. getbufvar("todo", "myvar") --- ---- +--- vim --- GetBufnr()->getbufvar(varname) --- < --- @@ -2932,8 +3000,9 @@ function vim.fn.getcellwidths() end --- position refers to the position in the list. For other --- buffers, it is set to the length of the list. --- ---- Can also be used as a |method|: > +--- Can also be used as a |method|: >vim --- GetBufnr()->getchangelist() +--- < --- --- @param buf? integer|string --- @return table[] @@ -2972,7 +3041,7 @@ function vim.fn.getchangelist(buf) end --- |v:mouse_lnum|, |v:mouse_winid| and |v:mouse_win|. --- |getmousepos()| can also be used. Mouse move events will be --- ignored. ---- This example positions the mouse as it would normally happen: > +--- This example positions the mouse as it would normally happen: >vim --- let c = getchar() --- if c == "\" && v:mouse_win > 0 --- exe v:mouse_win .. "wincmd w" @@ -2987,20 +3056,20 @@ function vim.fn.getchangelist(buf) end --- There is no mapping for the character. --- Key codes are replaced, thus when the user presses the --- key you get the code for the key, not the raw character ---- sequence. Examples: > +--- sequence. Examples: >vim --- getchar() == "\" --- getchar() == "\" ----