zeertzjq | d4d1207 | 2024-07-16 20:34:16 +0200 | [diff] [blame] | 1 | *builtin.txt* For Vim version 9.1. Last change: 2024 Jul 16 |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2 | |
| 3 | |
| 4 | VIM REFERENCE MANUAL by Bram Moolenaar |
| 5 | |
| 6 | |
| 7 | Builtin functions *builtin-functions* |
| 8 | |
Bram Moolenaar | f269eab | 2022-10-03 18:04:35 +0100 | [diff] [blame] | 9 | Note: Expression evaluation can be disabled at compile time, the builtin |
| 10 | functions are not available then. See |+eval| and |no-eval-feature|. |
| 11 | |
| 12 | For functions grouped by what they are used for see |function-list|. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 13 | |
| 14 | 1. Overview |builtin-function-list| |
| 15 | 2. Details |builtin-function-details| |
| 16 | 3. Feature list |feature-list| |
| 17 | 4. Matching a pattern in a String |string-match| |
| 18 | |
| 19 | ============================================================================== |
| 20 | 1. Overview *builtin-function-list* |
| 21 | |
| 22 | Use CTRL-] on the function name to jump to the full explanation. |
| 23 | |
| 24 | USAGE RESULT DESCRIPTION ~ |
| 25 | |
| 26 | abs({expr}) Float or Number absolute value of {expr} |
| 27 | acos({expr}) Float arc cosine of {expr} |
| 28 | add({object}, {item}) List/Blob append {item} to {object} |
| 29 | and({expr}, {expr}) Number bitwise AND |
| 30 | append({lnum}, {text}) Number append {text} below line {lnum} |
errael | f0837ba | 2024-06-24 12:27:01 -0700 | [diff] [blame] | 31 | appendbufline({buf}, {lnum}, {text}) |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 32 | Number append {text} below line {lnum} |
errael | f0837ba | 2024-06-24 12:27:01 -0700 | [diff] [blame] | 33 | in buffer {buf} |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 34 | argc([{winid}]) Number number of files in the argument list |
| 35 | argidx() Number current index in the argument list |
| 36 | arglistid([{winnr} [, {tabnr}]]) Number argument list id |
| 37 | argv({nr} [, {winid}]) String {nr} entry of the argument list |
| 38 | argv([-1, {winid}]) List the argument list |
| 39 | asin({expr}) Float arc sine of {expr} |
| 40 | assert_beeps({cmd}) Number assert {cmd} causes a beep |
| 41 | assert_equal({exp}, {act} [, {msg}]) |
| 42 | Number assert {exp} is equal to {act} |
| 43 | assert_equalfile({fname-one}, {fname-two} [, {msg}]) |
| 44 | Number assert file contents are equal |
| 45 | assert_exception({error} [, {msg}]) |
| 46 | Number assert {error} is in v:exception |
| 47 | assert_fails({cmd} [, {error} [, {msg} [, {lnum} [, {context}]]]]) |
| 48 | Number assert {cmd} fails |
| 49 | assert_false({actual} [, {msg}]) |
| 50 | Number assert {actual} is false |
| 51 | assert_inrange({lower}, {upper}, {actual} [, {msg}]) |
| 52 | Number assert {actual} is inside the range |
| 53 | assert_match({pat}, {text} [, {msg}]) |
| 54 | Number assert {pat} matches {text} |
| 55 | assert_nobeep({cmd}) Number assert {cmd} does not cause a beep |
| 56 | assert_notequal({exp}, {act} [, {msg}]) |
| 57 | Number assert {exp} is not equal {act} |
| 58 | assert_notmatch({pat}, {text} [, {msg}]) |
| 59 | Number assert {pat} not matches {text} |
| 60 | assert_report({msg}) Number report a test failure |
| 61 | assert_true({actual} [, {msg}]) Number assert {actual} is true |
| 62 | atan({expr}) Float arc tangent of {expr} |
| 63 | atan2({expr1}, {expr2}) Float arc tangent of {expr1} / {expr2} |
Yegappan Lakshmanan | 1755a91 | 2022-05-19 10:31:47 +0100 | [diff] [blame] | 64 | autocmd_add({acmds}) Bool add a list of autocmds and groups |
| 65 | autocmd_delete({acmds}) Bool delete a list of autocmds and groups |
| 66 | autocmd_get([{opts}]) List return a list of autocmds |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 67 | balloon_gettext() String current text in the balloon |
| 68 | balloon_show({expr}) none show {expr} inside the balloon |
| 69 | balloon_split({msg}) List split {msg} as used for a balloon |
Christ van Willegen | ce0ef91 | 2024-06-20 23:41:59 +0200 | [diff] [blame] | 70 | bindtextdomain({package}, {path}) |
Christ van Willegen | 8252ef1 | 2024-07-11 21:36:21 +0200 | [diff] [blame] | 71 | Bool bind text domain to specified path |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 72 | blob2list({blob}) List convert {blob} into a list of numbers |
| 73 | browse({save}, {title}, {initdir}, {default}) |
| 74 | String put up a file requester |
| 75 | browsedir({title}, {initdir}) String put up a directory requester |
| 76 | bufadd({name}) Number add a buffer to the buffer list |
| 77 | bufexists({buf}) Number |TRUE| if buffer {buf} exists |
| 78 | buflisted({buf}) Number |TRUE| if buffer {buf} is listed |
| 79 | bufload({buf}) Number load buffer {buf} if not loaded yet |
| 80 | bufloaded({buf}) Number |TRUE| if buffer {buf} is loaded |
| 81 | bufname([{buf}]) String Name of the buffer {buf} |
| 82 | bufnr([{buf} [, {create}]]) Number Number of the buffer {buf} |
| 83 | bufwinid({buf}) Number window ID of buffer {buf} |
| 84 | bufwinnr({buf}) Number window number of buffer {buf} |
| 85 | byte2line({byte}) Number line number at byte count {byte} |
Christian Brabandt | 67672ef | 2023-04-24 21:09:54 +0100 | [diff] [blame] | 86 | byteidx({expr}, {nr} [, {utf16}]) |
| 87 | Number byte index of {nr}'th char in {expr} |
| 88 | byteidxcomp({expr}, {nr} [, {utf16}]) |
| 89 | Number byte index of {nr}'th char in {expr} |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 90 | call({func}, {arglist} [, {dict}]) |
| 91 | any call {func} with arguments {arglist} |
| 92 | ceil({expr}) Float round {expr} up |
| 93 | ch_canread({handle}) Number check if there is something to read |
| 94 | ch_close({handle}) none close {handle} |
| 95 | ch_close_in({handle}) none close in part of {handle} |
| 96 | ch_evalexpr({handle}, {expr} [, {options}]) |
| 97 | any evaluate {expr} on JSON {handle} |
| 98 | ch_evalraw({handle}, {string} [, {options}]) |
| 99 | any evaluate {string} on raw {handle} |
| 100 | ch_getbufnr({handle}, {what}) Number get buffer number for {handle}/{what} |
| 101 | ch_getjob({channel}) Job get the Job of {channel} |
| 102 | ch_info({handle}) String info about channel {handle} |
| 103 | ch_log({msg} [, {handle}]) none write {msg} in the channel log file |
| 104 | ch_logfile({fname} [, {mode}]) none start logging channel activity |
| 105 | ch_open({address} [, {options}]) |
| 106 | Channel open a channel to {address} |
| 107 | ch_read({handle} [, {options}]) String read from {handle} |
| 108 | ch_readblob({handle} [, {options}]) |
| 109 | Blob read Blob from {handle} |
| 110 | ch_readraw({handle} [, {options}]) |
| 111 | String read raw from {handle} |
| 112 | ch_sendexpr({handle}, {expr} [, {options}]) |
| 113 | any send {expr} over JSON {handle} |
| 114 | ch_sendraw({handle}, {expr} [, {options}]) |
| 115 | any send {expr} over raw {handle} |
| 116 | ch_setoptions({handle}, {options}) |
| 117 | none set options for {handle} |
| 118 | ch_status({handle} [, {options}]) |
| 119 | String status of channel {handle} |
| 120 | changenr() Number current change number |
| 121 | char2nr({expr} [, {utf8}]) Number ASCII/UTF-8 value of first char in {expr} |
| 122 | charclass({string}) Number character class of {string} |
Yegappan Lakshmanan | 4c8d2f0 | 2022-11-12 16:07:47 +0000 | [diff] [blame] | 123 | charcol({expr} [, {winid}]) Number column number of cursor or mark |
Christian Brabandt | 67672ef | 2023-04-24 21:09:54 +0100 | [diff] [blame] | 124 | charidx({string}, {idx} [, {countcc} [, {utf16}]]) |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 125 | Number char index of byte {idx} in {string} |
| 126 | chdir({dir}) String change current working directory |
| 127 | cindent({lnum}) Number C indent for line {lnum} |
| 128 | clearmatches([{win}]) none clear all matches |
Yegappan Lakshmanan | 4c8d2f0 | 2022-11-12 16:07:47 +0000 | [diff] [blame] | 129 | col({expr} [, {winid}]) Number column byte index of cursor or mark |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 130 | complete({startcol}, {matches}) none set Insert mode completion |
| 131 | complete_add({expr}) Number add completion match |
| 132 | complete_check() Number check for key typed during completion |
| 133 | complete_info([{what}]) Dict get current completion information |
| 134 | confirm({msg} [, {choices} [, {default} [, {type}]]]) |
| 135 | Number number of choice picked by user |
| 136 | copy({expr}) any make a shallow copy of {expr} |
| 137 | cos({expr}) Float cosine of {expr} |
| 138 | cosh({expr}) Float hyperbolic cosine of {expr} |
| 139 | count({comp}, {expr} [, {ic} [, {start}]]) |
| 140 | Number count how many {expr} are in {comp} |
| 141 | cscope_connection([{num}, {dbpath} [, {prepend}]]) |
| 142 | Number checks existence of cscope connection |
| 143 | cursor({lnum}, {col} [, {off}]) |
| 144 | Number move cursor to {lnum}, {col}, {off} |
| 145 | cursor({list}) Number move cursor to position in {list} |
| 146 | debugbreak({pid}) Number interrupt process being debugged |
| 147 | deepcopy({expr} [, {noref}]) any make a full copy of {expr} |
| 148 | delete({fname} [, {flags}]) Number delete the file or directory {fname} |
| 149 | deletebufline({buf}, {first} [, {last}]) |
| 150 | Number delete lines from buffer {buf} |
| 151 | did_filetype() Number |TRUE| if FileType autocmd event used |
Yegappan Lakshmanan | fa37835 | 2024-02-01 22:05:27 +0100 | [diff] [blame] | 152 | diff({fromlist}, {tolist} [, {options}]) |
| 153 | List diff two Lists of strings |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 154 | diff_filler({lnum}) Number diff filler lines about {lnum} |
| 155 | diff_hlID({lnum}, {col}) Number diff highlighting at {lnum}/{col} |
| 156 | digraph_get({chars}) String get the |digraph| of {chars} |
| 157 | digraph_getlist([{listall}]) List get all |digraph|s |
Christian Brabandt | fbc37f1 | 2024-06-18 20:50:58 +0200 | [diff] [blame] | 158 | digraph_set({chars}, {digraph}) Bool register |digraph| |
| 159 | digraph_setlist({digraphlist}) Bool register multiple |digraph|s |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 160 | echoraw({expr}) none output {expr} as-is |
| 161 | empty({expr}) Number |TRUE| if {expr} is empty |
| 162 | environ() Dict return environment variables |
Sean Dewar | b0efa49 | 2023-07-08 10:35:19 +0100 | [diff] [blame] | 163 | err_teapot([{expr}]) none give E418, or E503 if {expr} is |TRUE| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 164 | escape({string}, {chars}) String escape {chars} in {string} with '\' |
| 165 | eval({string}) any evaluate {string} into its value |
| 166 | eventhandler() Number |TRUE| if inside an event handler |
| 167 | executable({expr}) Number 1 if executable {expr} exists |
| 168 | execute({command}) String execute {command} and get the output |
| 169 | exepath({expr}) String full path of the command {expr} |
| 170 | exists({expr}) Number |TRUE| if {expr} exists |
| 171 | exists_compiled({expr}) Number |TRUE| if {expr} exists at compile time |
| 172 | exp({expr}) Float exponential of {expr} |
| 173 | expand({expr} [, {nosuf} [, {list}]]) |
| 174 | any expand special keywords in {expr} |
Yegappan Lakshmanan | 2b74b68 | 2022-04-03 21:30:32 +0100 | [diff] [blame] | 175 | expandcmd({string} [, {options}]) |
| 176 | String expand {string} like with `:edit` |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 177 | extend({expr1}, {expr2} [, {expr3}]) |
| 178 | List/Dict insert items of {expr2} into {expr1} |
| 179 | extendnew({expr1}, {expr2} [, {expr3}]) |
| 180 | List/Dict like |extend()| but creates a new |
| 181 | List or Dictionary |
| 182 | feedkeys({string} [, {mode}]) Number add key sequence to typeahead buffer |
Shougo Matsushita | 60c8743 | 2024-06-03 22:59:27 +0200 | [diff] [blame] | 183 | filecopy({from}, {to}) Number |TRUE| if copying file {from} to {to} |
| 184 | worked |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 185 | filereadable({file}) Number |TRUE| if {file} is a readable file |
| 186 | filewritable({file}) Number |TRUE| if {file} is a writable file |
| 187 | filter({expr1}, {expr2}) List/Dict/Blob/String |
| 188 | remove items from {expr1} where |
| 189 | {expr2} is 0 |
| 190 | finddir({name} [, {path} [, {count}]]) |
| 191 | String find directory {name} in {path} |
| 192 | findfile({name} [, {path} [, {count}]]) |
| 193 | String find file {name} in {path} |
| 194 | flatten({list} [, {maxdepth}]) List flatten {list} up to {maxdepth} levels |
| 195 | flattennew({list} [, {maxdepth}]) |
| 196 | List flatten a copy of {list} |
| 197 | float2nr({expr}) Number convert Float {expr} to a Number |
| 198 | floor({expr}) Float round {expr} down |
| 199 | fmod({expr1}, {expr2}) Float remainder of {expr1} / {expr2} |
| 200 | fnameescape({fname}) String escape special characters in {fname} |
| 201 | fnamemodify({fname}, {mods}) String modify file name |
| 202 | foldclosed({lnum}) Number first line of fold at {lnum} if closed |
| 203 | foldclosedend({lnum}) Number last line of fold at {lnum} if closed |
| 204 | foldlevel({lnum}) Number fold level at {lnum} |
| 205 | foldtext() String line displayed for closed fold |
| 206 | foldtextresult({lnum}) String text for closed fold at {lnum} |
Ernie Rael | e79e207 | 2024-01-13 11:47:33 +0100 | [diff] [blame] | 207 | foreach({expr1}, {expr2}) List/Dict/Blob/String |
| 208 | for each item in {expr1} call {expr2} |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 209 | foreground() Number bring the Vim window to the foreground |
Bram Moolenaar | aa53414 | 2022-09-15 21:46:02 +0100 | [diff] [blame] | 210 | fullcommand({name} [, {vim9}]) String get full command from {name} |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 211 | funcref({name} [, {arglist}] [, {dict}]) |
| 212 | Funcref reference to function {name} |
| 213 | function({name} [, {arglist}] [, {dict}]) |
| 214 | Funcref named reference to function {name} |
| 215 | garbagecollect([{atexit}]) none free memory, breaking cyclic references |
| 216 | get({list}, {idx} [, {def}]) any get item {idx} from {list} or {def} |
| 217 | get({dict}, {key} [, {def}]) any get item {key} from {dict} or {def} |
| 218 | get({func}, {what}) any get property of funcref/partial {func} |
| 219 | getbufinfo([{buf}]) List information about buffers |
| 220 | getbufline({buf}, {lnum} [, {end}]) |
| 221 | List lines {lnum} to {end} of buffer {buf} |
Bram Moolenaar | ce30ccc | 2022-11-21 19:57:04 +0000 | [diff] [blame] | 222 | getbufoneline({buf}, {lnum}) String line {lnum} of buffer {buf} |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 223 | getbufvar({buf}, {varname} [, {def}]) |
| 224 | any variable {varname} in buffer {buf} |
Kota Kato | 66bb9ae | 2023-01-17 18:31:56 +0000 | [diff] [blame] | 225 | getcellwidths() List get character cell width overrides |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 226 | getchangelist([{buf}]) List list of change list items |
Doug Kearns | 9cd9e75 | 2024-04-07 17:42:17 +0200 | [diff] [blame] | 227 | getchar([{expr}]) Number or String |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 228 | get one character from the user |
| 229 | getcharmod() Number modifiers for the last typed character |
| 230 | getcharpos({expr}) List position of cursor, mark, etc. |
| 231 | getcharsearch() Dict last character search |
Doug Kearns | 9cd9e75 | 2024-04-07 17:42:17 +0200 | [diff] [blame] | 232 | getcharstr([{expr}]) String get one character from the user |
Shougo Matsushita | 79d599b | 2022-05-07 12:48:29 +0100 | [diff] [blame] | 233 | getcmdcompltype() String return the type of the current |
| 234 | command-line completion |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 235 | getcmdline() String return the current command-line |
| 236 | getcmdpos() Number return cursor position in command-line |
Shougo Matsushita | 79d599b | 2022-05-07 12:48:29 +0100 | [diff] [blame] | 237 | getcmdscreenpos() Number return cursor screen position in |
| 238 | command-line |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 239 | getcmdtype() String return current command-line type |
| 240 | getcmdwintype() String return current command-line window type |
| 241 | getcompletion({pat}, {type} [, {filtered}]) |
| 242 | List list of cmdline completion matches |
| 243 | getcurpos([{winnr}]) List position of the cursor |
| 244 | getcursorcharpos([{winnr}]) List character position of the cursor |
| 245 | getcwd([{winnr} [, {tabnr}]]) String get the current working directory |
| 246 | getenv({name}) String return environment variable |
| 247 | getfontname([{name}]) String name of font being used |
| 248 | getfperm({fname}) String file permissions of file {fname} |
| 249 | getfsize({fname}) Number size in bytes of file {fname} |
| 250 | getftime({fname}) Number last modification time of file |
| 251 | getftype({fname}) String description of type of file {fname} |
| 252 | getimstatus() Number |TRUE| if the IME status is active |
| 253 | getjumplist([{winnr} [, {tabnr}]]) |
| 254 | List list of jump list items |
| 255 | getline({lnum}) String line {lnum} of current buffer |
| 256 | getline({lnum}, {end}) List lines {lnum} to {end} of current buffer |
| 257 | getloclist({nr}) List list of location list items |
| 258 | getloclist({nr}, {what}) Dict get specific location list properties |
| 259 | getmarklist([{buf}]) List list of global/local marks |
| 260 | getmatches([{win}]) List list of current matches |
| 261 | getmousepos() Dict last known mouse position |
Bram Moolenaar | 24dc19c | 2022-11-14 19:49:15 +0000 | [diff] [blame] | 262 | getmouseshape() String current mouse shape name |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 263 | getpid() Number process ID of Vim |
| 264 | getpos({expr}) List position of cursor, mark, etc. |
| 265 | getqflist() List list of quickfix items |
| 266 | getqflist({what}) Dict get specific quickfix list properties |
| 267 | getreg([{regname} [, 1 [, {list}]]]) |
| 268 | String or List contents of a register |
| 269 | getreginfo([{regname}]) Dict information about a register |
Shougo Matsushita | 19b7188 | 2024-02-28 22:48:12 +0100 | [diff] [blame] | 270 | getregion({pos1}, {pos2} [, {opts}]) |
Shougo Matsushita | 3f905ab | 2024-02-21 00:02:45 +0100 | [diff] [blame] | 271 | List get the text from {pos1} to {pos2} |
Shougo Matsushita | b4757e6 | 2024-05-07 20:49:24 +0200 | [diff] [blame] | 272 | getregionpos({pos1}, {pos2} [, {opts}]) |
| 273 | List get a list of positions for a region |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 274 | getregtype([{regname}]) String type of a register |
Yegappan Lakshmanan | 520f6ef | 2022-08-25 17:40:40 +0100 | [diff] [blame] | 275 | getscriptinfo([{opts}]) List list of sourced scripts |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 276 | gettabinfo([{expr}]) List list of tab pages |
| 277 | gettabvar({nr}, {varname} [, {def}]) |
| 278 | any variable {varname} in tab {nr} or {def} |
| 279 | gettabwinvar({tabnr}, {winnr}, {name} [, {def}]) |
| 280 | any {name} in {winnr} in tab page {tabnr} |
| 281 | gettagstack([{nr}]) Dict get the tag stack of window {nr} |
Christ van Willegen | ce0ef91 | 2024-06-20 23:41:59 +0200 | [diff] [blame] | 282 | gettext({text} [, {package}]) |
| 283 | String lookup translation of {text} |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 284 | getwininfo([{winid}]) List list of info about each window |
Bram Moolenaar | 938ae28 | 2023-02-20 20:44:55 +0000 | [diff] [blame] | 285 | getwinpos([{timeout}]) List X and Y coord in pixels of Vim window |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 286 | getwinposx() Number X coord in pixels of the Vim window |
| 287 | getwinposy() Number Y coord in pixels of the Vim window |
| 288 | getwinvar({nr}, {varname} [, {def}]) |
| 289 | any variable {varname} in window {nr} |
| 290 | glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) |
| 291 | any expand file wildcards in {expr} |
| 292 | glob2regpat({expr}) String convert a glob pat into a search pat |
| 293 | globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]]) |
| 294 | String do glob({expr}) for all dirs in {path} |
| 295 | has({feature} [, {check}]) Number |TRUE| if feature {feature} supported |
| 296 | has_key({dict}, {key}) Number |TRUE| if {dict} has entry {key} |
| 297 | haslocaldir([{winnr} [, {tabnr}]]) |
| 298 | Number |TRUE| if the window executed |:lcd| |
| 299 | or |:tcd| |
| 300 | hasmapto({what} [, {mode} [, {abbr}]]) |
| 301 | Number |TRUE| if mapping to {what} exists |
| 302 | histadd({history}, {item}) Number add an item to a history |
| 303 | histdel({history} [, {item}]) Number remove an item from a history |
| 304 | histget({history} [, {index}]) String get the item {index} from a history |
| 305 | histnr({history}) Number highest index of a history |
| 306 | hlID({name}) Number syntax ID of highlight group {name} |
| 307 | hlexists({name}) Number |TRUE| if highlight group {name} exists |
| 308 | hlget([{name} [, {resolve}]]) List get highlight group attributes |
| 309 | hlset({list}) Number set highlight group attributes |
| 310 | hostname() String name of the machine Vim is running on |
| 311 | iconv({expr}, {from}, {to}) String convert encoding of {expr} |
Ernie Rael | 0512425 | 2024-07-11 22:10:45 +0200 | [diff] [blame] | 312 | id({item}) String get unique identity string of item |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 313 | indent({lnum}) Number indent of line {lnum} |
| 314 | index({object}, {expr} [, {start} [, {ic}]]) |
| 315 | Number index in {object} where {expr} appears |
Yegappan Lakshmanan | b218655 | 2022-08-13 13:09:20 +0100 | [diff] [blame] | 316 | indexof({object}, {expr} [, {opts}]]) |
| 317 | Number index in {object} where {expr} is true |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 318 | input({prompt} [, {text} [, {completion}]]) |
| 319 | String get input from the user |
Bram Moolenaar | b529cfb | 2022-07-25 15:42:07 +0100 | [diff] [blame] | 320 | inputdialog({prompt} [, {text} [, {cancelreturn}]]) |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 321 | String like input() but in a GUI dialog |
| 322 | inputlist({textlist}) Number let the user pick from a choice list |
| 323 | inputrestore() Number restore typeahead |
| 324 | inputsave() Number save and clear typeahead |
| 325 | inputsecret({prompt} [, {text}]) String like input() but hiding the text |
| 326 | insert({object}, {item} [, {idx}]) List insert {item} in {object} [before {idx}] |
LemonBoy | afe0466 | 2023-08-23 21:08:11 +0200 | [diff] [blame] | 327 | instanceof({object}, {class}) Number |TRUE| if {object} is an instance of {class} |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 328 | interrupt() none interrupt script execution |
| 329 | invert({expr}) Number bitwise invert |
LemonBoy | dca1d40 | 2022-04-28 15:26:33 +0100 | [diff] [blame] | 330 | isabsolutepath({path}) Number |TRUE| if {path} is an absolute path |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 331 | isdirectory({directory}) Number |TRUE| if {directory} is a directory |
| 332 | isinf({expr}) Number determine if {expr} is infinity value |
| 333 | (positive or negative) |
| 334 | islocked({expr}) Number |TRUE| if {expr} is locked |
| 335 | isnan({expr}) Number |TRUE| if {expr} is NaN |
| 336 | items({dict}) List key-value pairs in {dict} |
| 337 | job_getchannel({job}) Channel get the channel handle for {job} |
| 338 | job_info([{job}]) Dict get information about {job} |
| 339 | job_setoptions({job}, {options}) none set options for {job} |
| 340 | job_start({command} [, {options}]) |
| 341 | Job start a job |
| 342 | job_status({job}) String get the status of {job} |
| 343 | job_stop({job} [, {how}]) Number stop {job} |
| 344 | join({list} [, {sep}]) String join {list} items into one String |
| 345 | js_decode({string}) any decode JS style JSON |
| 346 | js_encode({expr}) String encode JS style JSON |
| 347 | json_decode({string}) any decode JSON |
| 348 | json_encode({expr}) String encode JSON |
| 349 | keys({dict}) List keys in {dict} |
zeertzjq | cdc8393 | 2022-09-12 13:38:41 +0100 | [diff] [blame] | 350 | keytrans({string}) String translate internal keycodes to a form |
| 351 | that can be used by |:map| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 352 | len({expr}) Number the length of {expr} |
| 353 | libcall({lib}, {func}, {arg}) String call {func} in library {lib} with {arg} |
| 354 | libcallnr({lib}, {func}, {arg}) Number idem, but return a Number |
| 355 | line({expr} [, {winid}]) Number line nr of cursor, last line or mark |
| 356 | line2byte({lnum}) Number byte count of line {lnum} |
| 357 | lispindent({lnum}) Number Lisp indent for line {lnum} |
| 358 | list2blob({list}) Blob turn {list} of numbers into a Blob |
| 359 | list2str({list} [, {utf8}]) String turn {list} of numbers into a String |
| 360 | listener_add({callback} [, {buf}]) |
| 361 | Number add a callback to listen to changes |
| 362 | listener_flush([{buf}]) none invoke listener callbacks |
| 363 | listener_remove({id}) none remove a listener callback |
| 364 | localtime() Number current time |
| 365 | log({expr}) Float natural logarithm (base e) of {expr} |
| 366 | log10({expr}) Float logarithm of Float {expr} to base 10 |
| 367 | luaeval({expr} [, {expr}]) any evaluate |Lua| expression |
| 368 | map({expr1}, {expr2}) List/Dict/Blob/String |
| 369 | change each item in {expr1} to {expr2} |
| 370 | maparg({name} [, {mode} [, {abbr} [, {dict}]]]) |
| 371 | String or Dict |
| 372 | rhs of mapping {name} in mode {mode} |
| 373 | mapcheck({name} [, {mode} [, {abbr}]]) |
| 374 | String check for mappings matching {name} |
Ernie Rael | 0966120 | 2022-04-25 14:40:44 +0100 | [diff] [blame] | 375 | maplist([{abbr}]) List list of all mappings, a dict for each |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 376 | mapnew({expr1}, {expr2}) List/Dict/Blob/String |
| 377 | like |map()| but creates a new List or |
| 378 | Dictionary |
| 379 | mapset({mode}, {abbr}, {dict}) none restore mapping from |maparg()| result |
| 380 | match({expr}, {pat} [, {start} [, {count}]]) |
| 381 | Number position where {pat} matches in {expr} |
| 382 | matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]]) |
| 383 | Number highlight {pattern} with {group} |
| 384 | matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]]) |
| 385 | Number highlight positions with {group} |
| 386 | matcharg({nr}) List arguments of |:match| |
Yegappan Lakshmanan | f93b1c8 | 2024-01-04 22:28:46 +0100 | [diff] [blame] | 387 | matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict}) |
| 388 | List all the {pat} matches in buffer {buf} |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 389 | matchdelete({id} [, {win}]) Number delete match identified by {id} |
| 390 | matchend({expr}, {pat} [, {start} [, {count}]]) |
| 391 | Number position where {pat} ends in {expr} |
| 392 | matchfuzzy({list}, {str} [, {dict}]) |
| 393 | List fuzzy match {str} in {list} |
| 394 | matchfuzzypos({list}, {str} [, {dict}]) |
| 395 | List fuzzy match {str} in {list} |
| 396 | matchlist({expr}, {pat} [, {start} [, {count}]]) |
| 397 | List match and submatches of {pat} in {expr} |
| 398 | matchstr({expr}, {pat} [, {start} [, {count}]]) |
| 399 | String {count}'th match of {pat} in {expr} |
Yegappan Lakshmanan | f93b1c8 | 2024-01-04 22:28:46 +0100 | [diff] [blame] | 400 | matchstrlist({list}, {pat} [, {dict}) |
| 401 | List all the {pat} matches in {list} |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 402 | matchstrpos({expr}, {pat} [, {start} [, {count}]]) |
| 403 | List {count}'th match of {pat} in {expr} |
| 404 | max({expr}) Number maximum value of items in {expr} |
| 405 | menu_info({name} [, {mode}]) Dict get menu item information |
| 406 | min({expr}) Number minimum value of items in {expr} |
Bram Moolenaar | 938ae28 | 2023-02-20 20:44:55 +0000 | [diff] [blame] | 407 | mkdir({name} [, {flags} [, {prot}]]) |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 408 | Number create directory {name} |
Doug Kearns | 9cd9e75 | 2024-04-07 17:42:17 +0200 | [diff] [blame] | 409 | mode([{expr}]) String current editing mode |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 410 | mzeval({expr}) any evaluate |MzScheme| expression |
| 411 | nextnonblank({lnum}) Number line nr of non-blank line >= {lnum} |
| 412 | nr2char({expr} [, {utf8}]) String single char with ASCII/UTF-8 value {expr} |
| 413 | or({expr}, {expr}) Number bitwise OR |
| 414 | pathshorten({expr} [, {len}]) String shorten directory names in a path |
| 415 | perleval({expr}) any evaluate |Perl| expression |
| 416 | popup_atcursor({what}, {options}) Number create popup window near the cursor |
| 417 | popup_beval({what}, {options}) Number create popup window for 'ballooneval' |
| 418 | popup_clear() none close all popup windows |
| 419 | popup_close({id} [, {result}]) none close popup window {id} |
| 420 | popup_create({what}, {options}) Number create a popup window |
| 421 | popup_dialog({what}, {options}) Number create a popup window used as a dialog |
| 422 | popup_filter_menu({id}, {key}) Number filter for a menu popup window |
| 423 | popup_filter_yesno({id}, {key}) Number filter for a dialog popup window |
Bram Moolenaar | bdc09a1 | 2022-10-07 14:31:45 +0100 | [diff] [blame] | 424 | popup_findecho() Number get window ID of popup for `:echowin` |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 425 | popup_findinfo() Number get window ID of info popup window |
| 426 | popup_findpreview() Number get window ID of preview popup window |
| 427 | popup_getoptions({id}) Dict get options of popup window {id} |
| 428 | popup_getpos({id}) Dict get position of popup window {id} |
| 429 | popup_hide({id}) none hide popup menu {id} |
| 430 | popup_list() List get a list of window IDs of all popups |
| 431 | popup_locate({row}, {col}) Number get window ID of popup at position |
| 432 | popup_menu({what}, {options}) Number create a popup window used as a menu |
| 433 | popup_move({id}, {options}) none set position of popup window {id} |
| 434 | popup_notification({what}, {options}) |
| 435 | Number create a notification popup window |
Christian Brabandt | fbc37f1 | 2024-06-18 20:50:58 +0200 | [diff] [blame] | 436 | popup_setbuf({id}, {buf}) Bool set the buffer for the popup window {id} |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 437 | popup_setoptions({id}, {options}) |
| 438 | none set options for popup window {id} |
| 439 | popup_settext({id}, {text}) none set the text of popup window {id} |
| 440 | popup_show({id}) none unhide popup window {id} |
| 441 | pow({x}, {y}) Float {x} to the power of {y} |
| 442 | prevnonblank({lnum}) Number line nr of non-blank line <= {lnum} |
| 443 | printf({fmt}, {expr1}...) String format text |
| 444 | prompt_getprompt({buf}) String get prompt text |
| 445 | prompt_setcallback({buf}, {expr}) none set prompt callback function |
| 446 | prompt_setinterrupt({buf}, {text}) none set prompt interrupt function |
| 447 | prompt_setprompt({buf}, {text}) none set prompt text |
| 448 | prop_add({lnum}, {col}, {props}) none add one text property |
| 449 | prop_add_list({props}, [[{lnum}, {col}, {end-lnum}, {end-col}], ...]) |
| 450 | none add multiple text properties |
| 451 | prop_clear({lnum} [, {lnum-end} [, {props}]]) |
| 452 | none remove all text properties |
| 453 | prop_find({props} [, {direction}]) |
| 454 | Dict search for a text property |
| 455 | prop_list({lnum} [, {props}]) List text properties in {lnum} |
| 456 | prop_remove({props} [, {lnum} [, {lnum-end}]]) |
| 457 | Number remove a text property |
| 458 | prop_type_add({name}, {props}) none define a new property type |
| 459 | prop_type_change({name}, {props}) |
| 460 | none change an existing property type |
| 461 | prop_type_delete({name} [, {props}]) |
| 462 | none delete a property type |
| 463 | prop_type_get({name} [, {props}]) |
| 464 | Dict get property type values |
| 465 | prop_type_list([{props}]) List get list of property types |
| 466 | pum_getpos() Dict position and size of pum if visible |
| 467 | pumvisible() Number whether popup menu is visible |
| 468 | py3eval({expr}) any evaluate |python3| expression |
| 469 | pyeval({expr}) any evaluate |Python| expression |
| 470 | pyxeval({expr}) any evaluate |python_x| expression |
| 471 | rand([{expr}]) Number get pseudo-random number |
| 472 | range({expr} [, {max} [, {stride}]]) |
| 473 | List items from {expr} to {max} |
K.Takata | 11df3ae | 2022-10-19 14:02:40 +0100 | [diff] [blame] | 474 | readblob({fname} [, {offset} [, {size}]]) |
| 475 | Blob read a |Blob| from {fname} |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 476 | readdir({dir} [, {expr} [, {dict}]]) |
| 477 | List file names in {dir} selected by {expr} |
| 478 | readdirex({dir} [, {expr} [, {dict}]]) |
| 479 | List file info in {dir} selected by {expr} |
| 480 | readfile({fname} [, {type} [, {max}]]) |
| 481 | List get list of lines from file {fname} |
| 482 | reduce({object}, {func} [, {initial}]) |
| 483 | any reduce {object} using {func} |
| 484 | reg_executing() String get the executing register name |
| 485 | reg_recording() String get the recording register name |
| 486 | reltime([{start} [, {end}]]) List get time value |
| 487 | reltimefloat({time}) Float turn the time value into a Float |
| 488 | reltimestr({time}) String turn time value into a String |
| 489 | remote_expr({server}, {string} [, {idvar} [, {timeout}]]) |
| 490 | String send expression |
| 491 | remote_foreground({server}) Number bring Vim server to the foreground |
| 492 | remote_peek({serverid} [, {retvar}]) |
| 493 | Number check for reply string |
| 494 | remote_read({serverid} [, {timeout}]) |
| 495 | String read reply string |
| 496 | remote_send({server}, {string} [, {idvar}]) |
| 497 | String send key sequence |
| 498 | remote_startserver({name}) none become server {name} |
| 499 | remove({list}, {idx} [, {end}]) any/List |
| 500 | remove items {idx}-{end} from {list} |
| 501 | remove({blob}, {idx} [, {end}]) Number/Blob |
| 502 | remove bytes {idx}-{end} from {blob} |
| 503 | remove({dict}, {key}) any remove entry {key} from {dict} |
| 504 | rename({from}, {to}) Number rename (move) file from {from} to {to} |
Bakudankun | 375141e | 2022-09-09 18:46:47 +0100 | [diff] [blame] | 505 | repeat({expr}, {count}) List/Blob/String |
| 506 | repeat {expr} {count} times |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 507 | resolve({filename}) String get filename a shortcut points to |
Yegappan Lakshmanan | 03ff1c2 | 2023-05-06 14:08:21 +0100 | [diff] [blame] | 508 | reverse({obj}) List/Blob/String |
| 509 | reverse {obj} |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 510 | round({expr}) Float round off {expr} |
| 511 | rubyeval({expr}) any evaluate |Ruby| expression |
| 512 | screenattr({row}, {col}) Number attribute at screen position |
| 513 | screenchar({row}, {col}) Number character at screen position |
| 514 | screenchars({row}, {col}) List List of characters at screen position |
| 515 | screencol() Number current cursor column |
| 516 | screenpos({winid}, {lnum}, {col}) Dict screen row and col of a text character |
| 517 | screenrow() Number current cursor row |
| 518 | screenstring({row}, {col}) String characters at screen position |
| 519 | search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]]) |
| 520 | Number search for {pattern} |
| 521 | searchcount([{options}]) Dict get or update search stats |
| 522 | searchdecl({name} [, {global} [, {thisblock}]]) |
| 523 | Number search for variable declaration |
| 524 | searchpair({start}, {middle}, {end} [, {flags} [, {skip} [...]]]) |
| 525 | Number search for other end of start/end pair |
| 526 | searchpairpos({start}, {middle}, {end} [, {flags} [, {skip} [...]]]) |
| 527 | List search for other end of start/end pair |
| 528 | searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]]) |
| 529 | List search for {pattern} |
| 530 | server2client({clientid}, {string}) |
| 531 | Number send reply string |
| 532 | serverlist() String get a list of available servers |
errael | f0837ba | 2024-06-24 12:27:01 -0700 | [diff] [blame] | 533 | setbufline({buf}, {lnum}, {text}) |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 534 | Number set line {lnum} to {text} in buffer |
errael | f0837ba | 2024-06-24 12:27:01 -0700 | [diff] [blame] | 535 | {buf} |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 536 | setbufvar({buf}, {varname}, {val}) |
| 537 | none set {varname} in buffer {buf} to {val} |
| 538 | setcellwidths({list}) none set character cell width overrides |
| 539 | setcharpos({expr}, {list}) Number set the {expr} position to {list} |
| 540 | setcharsearch({dict}) Dict set character search from {dict} |
Shougo Matsushita | 07ea5f1 | 2022-08-27 12:22:25 +0100 | [diff] [blame] | 541 | setcmdline({str} [, {pos}]) Number set command-line |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 542 | setcmdpos({pos}) Number set cursor position in command-line |
| 543 | setcursorcharpos({list}) Number move cursor to position in {list} |
| 544 | setenv({name}, {val}) none set environment variable |
| 545 | setfperm({fname}, {mode}) Number set {fname} file permissions to {mode} |
| 546 | setline({lnum}, {line}) Number set line {lnum} to {line} |
| 547 | setloclist({nr}, {list} [, {action}]) |
| 548 | Number modify location list using {list} |
| 549 | setloclist({nr}, {list}, {action}, {what}) |
| 550 | Number modify specific location list props |
| 551 | setmatches({list} [, {win}]) Number restore a list of matches |
| 552 | setpos({expr}, {list}) Number set the {expr} position to {list} |
| 553 | setqflist({list} [, {action}]) Number modify quickfix list using {list} |
| 554 | setqflist({list}, {action}, {what}) |
| 555 | Number modify specific quickfix list props |
| 556 | setreg({n}, {v} [, {opt}]) Number set register to value and type |
| 557 | settabvar({nr}, {varname}, {val}) none set {varname} in tab page {nr} to {val} |
| 558 | settabwinvar({tabnr}, {winnr}, {varname}, {val}) |
| 559 | none set {varname} in window {winnr} in tab |
| 560 | page {tabnr} to {val} |
| 561 | settagstack({nr}, {dict} [, {action}]) |
| 562 | Number modify tag stack using {dict} |
| 563 | setwinvar({nr}, {varname}, {val}) none set {varname} in window {nr} to {val} |
| 564 | sha256({string}) String SHA256 checksum of {string} |
| 565 | shellescape({string} [, {special}]) |
| 566 | String escape {string} for use as shell |
| 567 | command argument |
| 568 | shiftwidth([{col}]) Number effective value of 'shiftwidth' |
| 569 | sign_define({name} [, {dict}]) Number define or update a sign |
| 570 | sign_define({list}) List define or update a list of signs |
| 571 | sign_getdefined([{name}]) List get a list of defined signs |
| 572 | sign_getplaced([{buf} [, {dict}]]) |
| 573 | List get a list of placed signs |
| 574 | sign_jump({id}, {group}, {buf}) |
| 575 | Number jump to a sign |
| 576 | sign_place({id}, {group}, {name}, {buf} [, {dict}]) |
| 577 | Number place a sign |
| 578 | sign_placelist({list}) List place a list of signs |
| 579 | sign_undefine([{name}]) Number undefine a sign |
| 580 | sign_undefine({list}) List undefine a list of signs |
| 581 | sign_unplace({group} [, {dict}]) |
| 582 | Number unplace a sign |
| 583 | sign_unplacelist({list}) List unplace a list of signs |
| 584 | simplify({filename}) String simplify filename as much as possible |
| 585 | sin({expr}) Float sine of {expr} |
| 586 | sinh({expr}) Float hyperbolic sine of {expr} |
| 587 | slice({expr}, {start} [, {end}]) String, List or Blob |
| 588 | slice of a String, List or Blob |
Bram Moolenaar | 2007dd4 | 2022-02-23 13:17:47 +0000 | [diff] [blame] | 589 | sort({list} [, {how} [, {dict}]]) |
| 590 | List sort {list}, compare with {how} |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 591 | sound_clear() none stop playing all sounds |
| 592 | sound_playevent({name} [, {callback}]) |
| 593 | Number play an event sound |
| 594 | sound_playfile({path} [, {callback}]) |
| 595 | Number play sound file {path} |
| 596 | sound_stop({id}) none stop playing sound {id} |
| 597 | soundfold({word}) String sound-fold {word} |
| 598 | spellbadword() String badly spelled word at cursor |
| 599 | spellsuggest({word} [, {max} [, {capital}]]) |
| 600 | List spelling suggestions |
| 601 | split({expr} [, {pat} [, {keepempty}]]) |
| 602 | List make |List| from {pat} separated {expr} |
| 603 | sqrt({expr}) Float square root of {expr} |
| 604 | srand([{expr}]) List get seed for |rand()| |
| 605 | state([{what}]) String current state of Vim |
| 606 | str2float({expr} [, {quoted}]) Float convert String to Float |
| 607 | str2list({expr} [, {utf8}]) List convert each character of {expr} to |
| 608 | ASCII/UTF-8 value |
| 609 | str2nr({expr} [, {base} [, {quoted}]]) |
| 610 | Number convert String to Number |
| 611 | strcharlen({expr}) Number character length of the String {expr} |
| 612 | strcharpart({str}, {start} [, {len} [, {skipcc}]]) |
| 613 | String {len} characters of {str} at |
| 614 | character {start} |
| 615 | strchars({expr} [, {skipcc}]) Number character count of the String {expr} |
| 616 | strdisplaywidth({expr} [, {col}]) Number display length of the String {expr} |
| 617 | strftime({format} [, {time}]) String format time with a specified format |
| 618 | strgetchar({str}, {index}) Number get char {index} from {str} |
| 619 | stridx({haystack}, {needle} [, {start}]) |
| 620 | Number index of {needle} in {haystack} |
| 621 | string({expr}) String String representation of {expr} value |
| 622 | strlen({expr}) Number length of the String {expr} |
| 623 | strpart({str}, {start} [, {len} [, {chars}]]) |
| 624 | String {len} bytes/chars of {str} at |
| 625 | byte {start} |
| 626 | strptime({format}, {timestring}) |
| 627 | Number Convert {timestring} to unix timestamp |
| 628 | strridx({haystack}, {needle} [, {start}]) |
| 629 | Number last index of {needle} in {haystack} |
| 630 | strtrans({expr}) String translate string to make it printable |
Christian Brabandt | 67672ef | 2023-04-24 21:09:54 +0100 | [diff] [blame] | 631 | strutf16len({string} [, {countcc}]) |
| 632 | Number number of UTF-16 code units in {string} |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 633 | strwidth({expr}) Number display cell length of the String {expr} |
| 634 | submatch({nr} [, {list}]) String or List |
| 635 | specific match in ":s" or substitute() |
| 636 | substitute({expr}, {pat}, {sub}, {flags}) |
| 637 | String all {pat} in {expr} replaced with {sub} |
Bram Moolenaar | c216a7a | 2022-12-05 13:50:55 +0000 | [diff] [blame] | 638 | swapfilelist() List swap files found in 'directory' |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 639 | swapinfo({fname}) Dict information about swap file {fname} |
| 640 | swapname({buf}) String swap file of buffer {buf} |
| 641 | synID({lnum}, {col}, {trans}) Number syntax ID at {lnum} and {col} |
| 642 | synIDattr({synID}, {what} [, {mode}]) |
| 643 | String attribute {what} of syntax ID {synID} |
| 644 | synIDtrans({synID}) Number translated syntax ID of {synID} |
| 645 | synconcealed({lnum}, {col}) List info about concealing |
| 646 | synstack({lnum}, {col}) List stack of syntax IDs at {lnum} and {col} |
| 647 | system({expr} [, {input}]) String output of shell command/filter {expr} |
| 648 | systemlist({expr} [, {input}]) List output of shell command/filter {expr} |
| 649 | tabpagebuflist([{arg}]) List list of buffer numbers in tab page |
| 650 | tabpagenr([{arg}]) Number number of current or last tab page |
| 651 | tabpagewinnr({tabarg} [, {arg}]) Number number of current window in tab page |
| 652 | tagfiles() List tags files used |
| 653 | taglist({expr} [, {filename}]) List list of tags matching {expr} |
| 654 | tan({expr}) Float tangent of {expr} |
| 655 | tanh({expr}) Float hyperbolic tangent of {expr} |
| 656 | tempname() String name for a temporary file |
| 657 | term_dumpdiff({filename}, {filename} [, {options}]) |
| 658 | Number display difference between two dumps |
| 659 | term_dumpload({filename} [, {options}]) |
| 660 | Number displaying a screen dump |
| 661 | term_dumpwrite({buf}, {filename} [, {options}]) |
| 662 | none dump terminal window contents |
| 663 | term_getaltscreen({buf}) Number get the alternate screen flag |
| 664 | term_getansicolors({buf}) List get ANSI palette in GUI color mode |
| 665 | term_getattr({attr}, {what}) Number get the value of attribute {what} |
| 666 | term_getcursor({buf}) List get the cursor position of a terminal |
| 667 | term_getjob({buf}) Job get the job associated with a terminal |
| 668 | term_getline({buf}, {row}) String get a line of text from a terminal |
| 669 | term_getscrolled({buf}) Number get the scroll count of a terminal |
| 670 | term_getsize({buf}) List get the size of a terminal |
| 671 | term_getstatus({buf}) String get the status of a terminal |
| 672 | term_gettitle({buf}) String get the title of a terminal |
| 673 | term_gettty({buf}, [{input}]) String get the tty name of a terminal |
| 674 | term_list() List get the list of terminal buffers |
| 675 | term_scrape({buf}, {row}) List get row of a terminal screen |
| 676 | term_sendkeys({buf}, {keys}) none send keystrokes to a terminal |
| 677 | term_setansicolors({buf}, {colors}) |
| 678 | none set ANSI palette in GUI color mode |
| 679 | term_setapi({buf}, {expr}) none set |terminal-api| function name prefix |
| 680 | term_setkill({buf}, {how}) none set signal to stop job in terminal |
| 681 | term_setrestore({buf}, {command}) none set command to restore terminal |
| 682 | term_setsize({buf}, {rows}, {cols}) |
| 683 | none set the size of a terminal |
| 684 | term_start({cmd} [, {options}]) Number open a terminal window and run a job |
| 685 | term_wait({buf} [, {time}]) Number wait for screen to be updated |
| 686 | terminalprops() Dict properties of the terminal |
| 687 | test_alloc_fail({id}, {countdown}, {repeat}) |
| 688 | none make memory allocation fail |
| 689 | test_autochdir() none enable 'autochdir' during startup |
| 690 | test_feedinput({string}) none add key sequence to input buffer |
| 691 | test_garbagecollect_now() none free memory right now for testing |
| 692 | test_garbagecollect_soon() none free memory soon for testing |
| 693 | test_getvalue({string}) any get value of an internal variable |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 694 | test_gui_event({event}, {args}) bool generate a GUI event for testing |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 695 | test_ignore_error({expr}) none ignore a specific error |
Christopher Plewright | 20b795e | 2022-12-20 20:01:58 +0000 | [diff] [blame] | 696 | test_mswin_event({event}, {args}) |
| 697 | bool generate MS-Windows event for testing |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 698 | test_null_blob() Blob null value for testing |
| 699 | test_null_channel() Channel null value for testing |
| 700 | test_null_dict() Dict null value for testing |
| 701 | test_null_function() Funcref null value for testing |
| 702 | test_null_job() Job null value for testing |
| 703 | test_null_list() List null value for testing |
| 704 | test_null_partial() Funcref null value for testing |
| 705 | test_null_string() String null value for testing |
| 706 | test_option_not_set({name}) none reset flag indicating option was set |
| 707 | test_override({expr}, {val}) none test with Vim internal overrides |
| 708 | test_refcount({expr}) Number get the reference count of {expr} |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 709 | test_setmouse({row}, {col}) none set the mouse position for testing |
| 710 | test_settime({expr}) none set current time for testing |
Doug Kearns | 9cd9e75 | 2024-04-07 17:42:17 +0200 | [diff] [blame] | 711 | test_srand_seed([{seed}]) none set seed for testing srand() |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 712 | test_unknown() any unknown value for testing |
| 713 | test_void() any void value for testing |
| 714 | timer_info([{id}]) List information about timers |
| 715 | timer_pause({id}, {pause}) none pause or unpause a timer |
| 716 | timer_start({time}, {callback} [, {options}]) |
| 717 | Number create a timer |
| 718 | timer_stop({timer}) none stop a timer |
| 719 | timer_stopall() none stop all timers |
| 720 | tolower({expr}) String the String {expr} switched to lowercase |
| 721 | toupper({expr}) String the String {expr} switched to uppercase |
| 722 | tr({src}, {fromstr}, {tostr}) String translate chars of {src} in {fromstr} |
| 723 | to chars in {tostr} |
| 724 | trim({text} [, {mask} [, {dir}]]) |
| 725 | String trim characters in {mask} from {text} |
| 726 | trunc({expr}) Float truncate Float {expr} |
| 727 | type({expr}) Number type of value {expr} |
| 728 | typename({expr}) String representation of the type of {expr} |
| 729 | undofile({name}) String undo file name for {name} |
Devin J. Pohly | 5fee111 | 2023-04-23 20:26:59 -0500 | [diff] [blame] | 730 | undotree([{buf}]) List undo file tree for buffer {buf} |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 731 | uniq({list} [, {func} [, {dict}]]) |
| 732 | List remove adjacent duplicates from a list |
Christian Brabandt | 67672ef | 2023-04-24 21:09:54 +0100 | [diff] [blame] | 733 | utf16idx({string}, {idx} [, {countcc} [, {charidx}]]) |
| 734 | Number UTF-16 index of byte {idx} in {string} |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 735 | values({dict}) List values in {dict} |
zeertzjq | 825cf81 | 2023-08-17 22:55:25 +0200 | [diff] [blame] | 736 | virtcol({expr} [, {list} [, {winid}]) |
| 737 | Number or List |
LemonBoy | 0f7a3e1 | 2022-05-26 12:10:37 +0100 | [diff] [blame] | 738 | screen column of cursor or mark |
Bram Moolenaar | 5a6ec10 | 2022-05-27 21:58:00 +0100 | [diff] [blame] | 739 | virtcol2col({winid}, {lnum}, {col}) |
| 740 | Number byte index of a character on screen |
Doug Kearns | 9cd9e75 | 2024-04-07 17:42:17 +0200 | [diff] [blame] | 741 | visualmode([{expr}]) String last visual mode used |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 742 | wildmenumode() Number whether 'wildmenu' mode is active |
| 743 | win_execute({id}, {command} [, {silent}]) |
| 744 | String execute {command} in window {id} |
| 745 | win_findbuf({bufnr}) List find windows containing {bufnr} |
| 746 | win_getid([{win} [, {tab}]]) Number get window ID for {win} in {tab} |
| 747 | win_gettype([{nr}]) String type of window {nr} |
| 748 | win_gotoid({expr}) Number go to window with ID {expr} |
| 749 | win_id2tabwin({expr}) List get tab and window nr from window ID |
| 750 | win_id2win({expr}) Number get window nr from window ID |
Daniel Steinberg | ee63031 | 2022-01-10 13:36:34 +0000 | [diff] [blame] | 751 | win_move_separator({nr}) Number move window vertical separator |
| 752 | win_move_statusline({nr}) Number move window status line |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 753 | win_screenpos({nr}) List get screen position of window {nr} |
| 754 | win_splitmove({nr}, {target} [, {options}]) |
| 755 | Number move window {nr} to split of {target} |
| 756 | winbufnr({nr}) Number buffer number of window {nr} |
| 757 | wincol() Number window column of the cursor |
| 758 | windowsversion() String MS-Windows OS version |
| 759 | winheight({nr}) Number height of window {nr} |
| 760 | winlayout([{tabnr}]) List layout of windows in tab {tabnr} |
| 761 | winline() Number window line of the cursor |
| 762 | winnr([{expr}]) Number number of current window |
| 763 | winrestcmd() String returns command to restore window sizes |
| 764 | winrestview({dict}) none restore view of current window |
| 765 | winsaveview() Dict save view of current window |
| 766 | winwidth({nr}) Number width of window {nr} |
| 767 | wordcount() Dict get byte/char/word statistics |
| 768 | writefile({object}, {fname} [, {flags}]) |
| 769 | Number write |Blob| or |List| of lines to file |
| 770 | xor({expr}, {expr}) Number bitwise XOR |
| 771 | |
| 772 | ============================================================================== |
| 773 | 2. Details *builtin-function-details* |
| 774 | |
| 775 | Not all functions are here, some have been moved to a help file covering the |
| 776 | specific functionality. |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 777 | Return type specifies the type for |Vim9-script|, see |vim9-types| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 778 | |
| 779 | abs({expr}) *abs()* |
| 780 | Return the absolute value of {expr}. When {expr} evaluates to |
| 781 | a |Float| abs() returns a |Float|. When {expr} can be |
| 782 | converted to a |Number| abs() returns a |Number|. Otherwise |
| 783 | abs() gives an error message and returns -1. |
| 784 | Examples: > |
| 785 | echo abs(1.456) |
| 786 | < 1.456 > |
| 787 | echo abs(-5.456) |
| 788 | < 5.456 > |
| 789 | echo abs(-4) |
| 790 | < 4 |
| 791 | |
| 792 | Can also be used as a |method|: > |
| 793 | Compute()->abs() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 794 | < |
| 795 | Return type: |Number| or |Float| depending on {expr} |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 796 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 797 | |
| 798 | acos({expr}) *acos()* |
| 799 | Return the arc cosine of {expr} measured in radians, as a |
| 800 | |Float| in the range of [0, pi]. |
| 801 | {expr} must evaluate to a |Float| or a |Number| in the range |
Bram Moolenaar | 016188f | 2022-06-06 20:52:59 +0100 | [diff] [blame] | 802 | [-1, 1]. Otherwise acos() returns "nan". |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 803 | Examples: > |
| 804 | :echo acos(0) |
| 805 | < 1.570796 > |
| 806 | :echo acos(-0.5) |
| 807 | < 2.094395 |
| 808 | |
| 809 | Can also be used as a |method|: > |
| 810 | Compute()->acos() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 811 | < |
| 812 | Return type: |Float| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 813 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 814 | |
| 815 | add({object}, {expr}) *add()* |
| 816 | Append the item {expr} to |List| or |Blob| {object}. Returns |
| 817 | the resulting |List| or |Blob|. Examples: > |
| 818 | :let alist = add([1, 2, 3], item) |
| 819 | :call add(mylist, "woodstock") |
| 820 | < Note that when {expr} is a |List| it is appended as a single |
| 821 | item. Use |extend()| to concatenate |Lists|. |
| 822 | When {object} is a |Blob| then {expr} must be a number. |
| 823 | Use |insert()| to add an item at another position. |
Bram Moolenaar | 016188f | 2022-06-06 20:52:59 +0100 | [diff] [blame] | 824 | Returns 1 if {object} is not a |List| or a |Blob|. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 825 | |
| 826 | Can also be used as a |method|: > |
| 827 | mylist->add(val1)->add(val2) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 828 | < |
| 829 | Return type: list<{type}> (depending on the given |List|) or |
| 830 | |Blob| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 831 | |
| 832 | |
| 833 | and({expr}, {expr}) *and()* |
| 834 | Bitwise AND on the two arguments. The arguments are converted |
| 835 | to a number. A List, Dict or Float argument causes an error. |
LemonBoy | 0f7a3e1 | 2022-05-26 12:10:37 +0100 | [diff] [blame] | 836 | Also see `or()` and `xor()`. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 837 | Example: > |
| 838 | :let flag = and(bits, 0x80) |
| 839 | < Can also be used as a |method|: > |
| 840 | :let flag = bits->and(0x80) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 841 | < |
| 842 | Return type: |Number| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 843 | |
| 844 | |
| 845 | append({lnum}, {text}) *append()* |
| 846 | When {text} is a |List|: Append each item of the |List| as a |
| 847 | text line below line {lnum} in the current buffer. |
| 848 | Otherwise append {text} as one text line below line {lnum} in |
| 849 | the current buffer. |
| 850 | Any type of item is accepted and converted to a String. |
| 851 | {lnum} can be zero to insert a line before the first one. |
| 852 | {lnum} is used like with |getline()|. |
| 853 | Returns 1 for failure ({lnum} out of range or out of memory), |
Bram Moolenaar | cd9c8d4 | 2022-11-05 23:46:43 +0000 | [diff] [blame] | 854 | 0 for success. When {text} is an empty list zero is returned, |
| 855 | no matter the value of {lnum}. |
| 856 | In |Vim9| script an invalid argument or negative number |
| 857 | results in an error. Example: > |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 858 | :let failed = append(line('$'), "# THE END") |
| 859 | :let failed = append(0, ["Chapter 1", "the beginning"]) |
| 860 | |
| 861 | < Can also be used as a |method| after a List, the base is |
| 862 | passed as the second argument: > |
| 863 | mylist->append(lnum) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 864 | < |
| 865 | Return type: |Number| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 866 | |
| 867 | |
| 868 | appendbufline({buf}, {lnum}, {text}) *appendbufline()* |
| 869 | Like |append()| but append the text in buffer {buf}. |
| 870 | |
| 871 | This function works only for loaded buffers. First call |
| 872 | |bufload()| if needed. |
| 873 | |
| 874 | For the use of {buf}, see |bufname()|. |
| 875 | |
Bram Moolenaar | 8b6256f | 2021-12-28 11:24:49 +0000 | [diff] [blame] | 876 | {lnum} is the line number to append below. Note that using |
| 877 | |line()| would use the current buffer, not the one appending |
| 878 | to. Use "$" to append at the end of the buffer. Other string |
| 879 | values are not supported. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 880 | |
| 881 | On success 0 is returned, on failure 1 is returned. |
| 882 | In |Vim9| script an error is given for an invalid {lnum}. |
| 883 | |
| 884 | If {buf} is not a valid buffer or {lnum} is not valid, an |
| 885 | error message is given. Example: > |
| 886 | :let failed = appendbufline(13, 0, "# THE START") |
Bram Moolenaar | cd9c8d4 | 2022-11-05 23:46:43 +0000 | [diff] [blame] | 887 | < However, when {text} is an empty list then no error is given |
| 888 | for an invalid {lnum}, since {lnum} isn't actually used. |
| 889 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 890 | Can also be used as a |method| after a List, the base is |
| 891 | passed as the second argument: > |
| 892 | mylist->appendbufline(buf, lnum) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 893 | < |
| 894 | Return type: |Number| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 895 | |
| 896 | |
| 897 | argc([{winid}]) *argc()* |
| 898 | The result is the number of files in the argument list. See |
| 899 | |arglist|. |
| 900 | If {winid} is not supplied, the argument list of the current |
| 901 | window is used. |
| 902 | If {winid} is -1, the global argument list is used. |
| 903 | Otherwise {winid} specifies the window of which the argument |
| 904 | list is used: either the window number or the window ID. |
| 905 | Returns -1 if the {winid} argument is invalid. |
| 906 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 907 | Return type: |Number| |
| 908 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 909 | *argidx()* |
| 910 | argidx() The result is the current index in the argument list. 0 is |
| 911 | the first file. argc() - 1 is the last one. See |arglist|. |
| 912 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 913 | Return type: |Number| |
| 914 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 915 | *arglistid()* |
| 916 | arglistid([{winnr} [, {tabnr}]]) |
| 917 | Return the argument list ID. This is a number which |
| 918 | identifies the argument list being used. Zero is used for the |
| 919 | global argument list. See |arglist|. |
| 920 | Returns -1 if the arguments are invalid. |
| 921 | |
| 922 | Without arguments use the current window. |
| 923 | With {winnr} only use this window in the current tab page. |
| 924 | With {winnr} and {tabnr} use the window in the specified tab |
| 925 | page. |
| 926 | {winnr} can be the window number or the |window-ID|. |
| 927 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 928 | Return type: |Number| |
| 929 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 930 | *argv()* |
| 931 | argv([{nr} [, {winid}]]) |
| 932 | The result is the {nr}th file in the argument list. See |
| 933 | |arglist|. "argv(0)" is the first one. Example: > |
| 934 | :let i = 0 |
| 935 | :while i < argc() |
| 936 | : let f = escape(fnameescape(argv(i)), '.') |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 937 | : exe 'amenu Arg.' .. f .. ' :e ' .. f .. '<CR>' |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 938 | : let i = i + 1 |
| 939 | :endwhile |
| 940 | < Without the {nr} argument, or when {nr} is -1, a |List| with |
| 941 | the whole |arglist| is returned. |
| 942 | |
| 943 | The {winid} argument specifies the window ID, see |argc()|. |
| 944 | For the Vim command line arguments see |v:argv|. |
| 945 | |
Bram Moolenaar | 016188f | 2022-06-06 20:52:59 +0100 | [diff] [blame] | 946 | Returns an empty string if {nr}th argument is not present in |
| 947 | the argument list. Returns an empty List if the {winid} |
| 948 | argument is invalid. |
| 949 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 950 | Return type: |String| |
| 951 | |
| 952 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 953 | asin({expr}) *asin()* |
| 954 | Return the arc sine of {expr} measured in radians, as a |Float| |
| 955 | in the range of [-pi/2, pi/2]. |
| 956 | {expr} must evaluate to a |Float| or a |Number| in the range |
| 957 | [-1, 1]. |
Bram Moolenaar | 016188f | 2022-06-06 20:52:59 +0100 | [diff] [blame] | 958 | Returns "nan" if {expr} is outside the range [-1, 1]. Returns |
| 959 | 0.0 if {expr} is not a |Float| or a |Number|. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 960 | Examples: > |
| 961 | :echo asin(0.8) |
| 962 | < 0.927295 > |
| 963 | :echo asin(-0.5) |
| 964 | < -0.523599 |
| 965 | |
| 966 | Can also be used as a |method|: > |
| 967 | Compute()->asin() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 968 | < |
| 969 | Return type: |Float| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 970 | |
| 971 | assert_ functions are documented here: |assert-functions-details| |
| 972 | |
| 973 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 974 | atan({expr}) *atan()* |
| 975 | Return the principal value of the arc tangent of {expr}, in |
| 976 | the range [-pi/2, +pi/2] radians, as a |Float|. |
| 977 | {expr} must evaluate to a |Float| or a |Number|. |
Bram Moolenaar | 016188f | 2022-06-06 20:52:59 +0100 | [diff] [blame] | 978 | Returns 0.0 if {expr} is not a |Float| or a |Number|. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 979 | Examples: > |
| 980 | :echo atan(100) |
| 981 | < 1.560797 > |
| 982 | :echo atan(-4.01) |
| 983 | < -1.326405 |
| 984 | |
| 985 | Can also be used as a |method|: > |
| 986 | Compute()->atan() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 987 | < |
| 988 | Return type: |Float| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 989 | |
| 990 | |
| 991 | atan2({expr1}, {expr2}) *atan2()* |
| 992 | Return the arc tangent of {expr1} / {expr2}, measured in |
| 993 | radians, as a |Float| in the range [-pi, pi]. |
| 994 | {expr1} and {expr2} must evaluate to a |Float| or a |Number|. |
Bram Moolenaar | 016188f | 2022-06-06 20:52:59 +0100 | [diff] [blame] | 995 | Returns 0.0 if {expr1} or {expr2} is not a |Float| or a |
| 996 | |Number|. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 997 | Examples: > |
| 998 | :echo atan2(-1, 1) |
| 999 | < -0.785398 > |
| 1000 | :echo atan2(1, -1) |
| 1001 | < 2.356194 |
| 1002 | |
| 1003 | Can also be used as a |method|: > |
| 1004 | Compute()->atan2(1) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 1005 | < |
| 1006 | Return type: |Float| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1007 | |
Yegappan Lakshmanan | 1755a91 | 2022-05-19 10:31:47 +0100 | [diff] [blame] | 1008 | |
| 1009 | autocmd_add({acmds}) *autocmd_add()* |
| 1010 | Adds a List of autocmds and autocmd groups. |
| 1011 | |
| 1012 | The {acmds} argument is a List where each item is a Dict with |
| 1013 | the following optional items: |
| 1014 | bufnr buffer number to add a buffer-local autocmd. |
| 1015 | If this item is specified, then the "pattern" |
| 1016 | item is ignored. |
| 1017 | cmd Ex command to execute for this autocmd event |
| 1018 | event autocmd event name. Refer to |autocmd-events|. |
Yegappan Lakshmanan | e0ff3a7 | 2022-05-27 18:05:33 +0100 | [diff] [blame] | 1019 | This can be either a String with a single |
| 1020 | event name or a List of event names. |
Yegappan Lakshmanan | 1755a91 | 2022-05-19 10:31:47 +0100 | [diff] [blame] | 1021 | group autocmd group name. Refer to |autocmd-groups|. |
| 1022 | If this group doesn't exist then it is |
| 1023 | created. If not specified or empty, then the |
| 1024 | default group is used. |
Yegappan Lakshmanan | 971f682 | 2022-05-24 11:40:11 +0100 | [diff] [blame] | 1025 | nested boolean flag, set to v:true to add a nested |
| 1026 | autocmd. Refer to |autocmd-nested|. |
LemonBoy | 0f7a3e1 | 2022-05-26 12:10:37 +0100 | [diff] [blame] | 1027 | once boolean flag, set to v:true to add an autocmd |
Yegappan Lakshmanan | 971f682 | 2022-05-24 11:40:11 +0100 | [diff] [blame] | 1028 | which executes only once. Refer to |
| 1029 | |autocmd-once|. |
Yegappan Lakshmanan | 1755a91 | 2022-05-19 10:31:47 +0100 | [diff] [blame] | 1030 | pattern autocmd pattern string. Refer to |
| 1031 | |autocmd-patterns|. If "bufnr" item is |
Yegappan Lakshmanan | e0ff3a7 | 2022-05-27 18:05:33 +0100 | [diff] [blame] | 1032 | present, then this item is ignored. This can |
| 1033 | be a String with a single pattern or a List of |
| 1034 | patterns. |
Yegappan Lakshmanan | 971f682 | 2022-05-24 11:40:11 +0100 | [diff] [blame] | 1035 | replace boolean flag, set to v:true to remove all the |
| 1036 | commands associated with the specified autocmd |
| 1037 | event and group and add the {cmd}. This is |
| 1038 | useful to avoid adding the same command |
LemonBoy | 0f7a3e1 | 2022-05-26 12:10:37 +0100 | [diff] [blame] | 1039 | multiple times for an autocmd event in a group. |
Yegappan Lakshmanan | 1755a91 | 2022-05-19 10:31:47 +0100 | [diff] [blame] | 1040 | |
| 1041 | Returns v:true on success and v:false on failure. |
| 1042 | Examples: > |
| 1043 | " Create a buffer-local autocmd for buffer 5 |
| 1044 | let acmd = {} |
| 1045 | let acmd.group = 'MyGroup' |
| 1046 | let acmd.event = 'BufEnter' |
| 1047 | let acmd.bufnr = 5 |
| 1048 | let acmd.cmd = 'call BufEnterFunc()' |
| 1049 | call autocmd_add([acmd]) |
Bram Moolenaar | cd9c8d4 | 2022-11-05 23:46:43 +0000 | [diff] [blame] | 1050 | < |
Yegappan Lakshmanan | 1755a91 | 2022-05-19 10:31:47 +0100 | [diff] [blame] | 1051 | Can also be used as a |method|: > |
| 1052 | GetAutocmdList()->autocmd_add() |
| 1053 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 1054 | Return type: |vim9-boolean| |
| 1055 | |
| 1056 | |
Yegappan Lakshmanan | 1755a91 | 2022-05-19 10:31:47 +0100 | [diff] [blame] | 1057 | autocmd_delete({acmds}) *autocmd_delete()* |
| 1058 | Deletes a List of autocmds and autocmd groups. |
| 1059 | |
| 1060 | The {acmds} argument is a List where each item is a Dict with |
| 1061 | the following optional items: |
| 1062 | bufnr buffer number to delete a buffer-local autocmd. |
| 1063 | If this item is specified, then the "pattern" |
| 1064 | item is ignored. |
| 1065 | cmd Ex command for this autocmd event |
| 1066 | event autocmd event name. Refer to |autocmd-events|. |
| 1067 | If '*' then all the autocmd events in this |
| 1068 | group are deleted. |
| 1069 | group autocmd group name. Refer to |autocmd-groups|. |
| 1070 | If not specified or empty, then the default |
| 1071 | group is used. |
| 1072 | nested set to v:true for a nested autocmd. |
| 1073 | Refer to |autocmd-nested|. |
| 1074 | once set to v:true for an autocmd which executes |
| 1075 | only once. Refer to |autocmd-once|. |
| 1076 | pattern autocmd pattern string. Refer to |
| 1077 | |autocmd-patterns|. If "bufnr" item is |
| 1078 | present, then this item is ignored. |
| 1079 | |
| 1080 | If only {group} is specified in a {acmds} entry and {event}, |
| 1081 | {pattern} and {cmd} are not specified, then that autocmd group |
| 1082 | is deleted. |
| 1083 | |
Bram Moolenaar | 016188f | 2022-06-06 20:52:59 +0100 | [diff] [blame] | 1084 | Returns |v:true| on success and |v:false| on failure. |
Yegappan Lakshmanan | 1755a91 | 2022-05-19 10:31:47 +0100 | [diff] [blame] | 1085 | Examples: > |
| 1086 | " :autocmd! BufLeave *.vim |
| 1087 | let acmd = #{event: 'BufLeave', pattern: '*.vim'} |
| 1088 | call autocmd_delete([acmd]}) |
| 1089 | " :autocmd! MyGroup1 BufLeave |
| 1090 | let acmd = #{group: 'MyGroup1', event: 'BufLeave'} |
| 1091 | call autocmd_delete([acmd]) |
| 1092 | " :autocmd! MyGroup2 BufEnter *.c |
| 1093 | let acmd = #{group: 'MyGroup2', event: 'BufEnter', |
| 1094 | \ pattern: '*.c'} |
| 1095 | " :autocmd! MyGroup2 * *.c |
| 1096 | let acmd = #{group: 'MyGroup2', event: '*', |
| 1097 | \ pattern: '*.c'} |
| 1098 | call autocmd_delete([acmd]) |
| 1099 | " :autocmd! MyGroup3 |
| 1100 | let acmd = #{group: 'MyGroup3'} |
| 1101 | call autocmd_delete([acmd]) |
| 1102 | < |
| 1103 | Can also be used as a |method|: > |
| 1104 | GetAutocmdList()->autocmd_delete() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 1105 | < |
| 1106 | Return type: |vim9-boolean| |
| 1107 | |
Yegappan Lakshmanan | 1755a91 | 2022-05-19 10:31:47 +0100 | [diff] [blame] | 1108 | |
| 1109 | autocmd_get([{opts}]) *autocmd_get()* |
| 1110 | Returns a |List| of autocmds. If {opts} is not supplied, then |
| 1111 | returns the autocmds for all the events in all the groups. |
| 1112 | |
| 1113 | The optional {opts} Dict argument supports the following |
| 1114 | items: |
| 1115 | group Autocmd group name. If specified, returns only |
| 1116 | the autocmds defined in this group. If the |
| 1117 | specified group doesn't exist, results in an |
| 1118 | error message. If set to an empty string, |
| 1119 | then the default autocmd group is used. |
| 1120 | event Autocmd event name. If specified, returns only |
| 1121 | the autocmds defined for this event. If set |
| 1122 | to "*", then returns autocmds for all the |
| 1123 | events. If the specified event doesn't exist, |
| 1124 | results in an error message. |
| 1125 | pattern Autocmd pattern. If specified, returns only |
| 1126 | the autocmds defined for this pattern. |
| 1127 | A combination of the above three times can be supplied in |
| 1128 | {opts}. |
| 1129 | |
| 1130 | Each Dict in the returned List contains the following items: |
| 1131 | bufnr For buffer-local autocmds, buffer number where |
| 1132 | the autocmd is defined. |
| 1133 | cmd Command executed for this autocmd. |
| 1134 | event Autocmd event name. |
| 1135 | group Autocmd group name. |
Yegappan Lakshmanan | 971f682 | 2022-05-24 11:40:11 +0100 | [diff] [blame] | 1136 | nested Boolean flag, set to v:true for a nested |
| 1137 | autocmd. See |autocmd-nested|. |
| 1138 | once Boolean flag, set to v:true, if the autocmd |
| 1139 | will be executed only once. See |autocmd-once|. |
Yegappan Lakshmanan | 1755a91 | 2022-05-19 10:31:47 +0100 | [diff] [blame] | 1140 | pattern Autocmd pattern. For a buffer-local |
| 1141 | autocmd, this will be of the form "<buffer=n>". |
| 1142 | If there are multiple commands for an autocmd event in a |
| 1143 | group, then separate items are returned for each command. |
| 1144 | |
Bram Moolenaar | 016188f | 2022-06-06 20:52:59 +0100 | [diff] [blame] | 1145 | Returns an empty List if an autocmd with the specified group |
| 1146 | or event or pattern is not found. |
| 1147 | |
Yegappan Lakshmanan | 1755a91 | 2022-05-19 10:31:47 +0100 | [diff] [blame] | 1148 | Examples: > |
| 1149 | " :autocmd MyGroup |
| 1150 | echo autocmd_get(#{group: 'Mygroup'}) |
| 1151 | " :autocmd G BufUnload |
| 1152 | echo autocmd_get(#{group: 'G', event: 'BufUnload'}) |
| 1153 | " :autocmd G * *.ts |
| 1154 | let acmd = #{group: 'G', event: '*', pattern: '*.ts'} |
| 1155 | echo autocmd_get(acmd) |
| 1156 | " :autocmd Syntax |
| 1157 | echo autocmd_get(#{event: 'Syntax'}) |
| 1158 | " :autocmd G BufEnter *.ts |
| 1159 | let acmd = #{group: 'G', event: 'BufEnter', |
| 1160 | \ pattern: '*.ts'} |
| 1161 | echo autocmd_get(acmd) |
| 1162 | < |
| 1163 | Can also be used as a |method|: > |
| 1164 | Getopts()->autocmd_get() |
| 1165 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 1166 | Return type: list<dict<any>> |
| 1167 | |
| 1168 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1169 | balloon_gettext() *balloon_gettext()* |
| 1170 | Return the current text in the balloon. Only for the string, |
Bram Moolenaar | 016188f | 2022-06-06 20:52:59 +0100 | [diff] [blame] | 1171 | not used for the List. Returns an empty string if balloon |
| 1172 | is not present. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1173 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 1174 | Return type: |String| |
| 1175 | |
| 1176 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1177 | balloon_show({expr}) *balloon_show()* |
| 1178 | Show {expr} inside the balloon. For the GUI {expr} is used as |
| 1179 | a string. For a terminal {expr} can be a list, which contains |
| 1180 | the lines of the balloon. If {expr} is not a list it will be |
| 1181 | split with |balloon_split()|. |
| 1182 | If {expr} is an empty string any existing balloon is removed. |
| 1183 | |
| 1184 | Example: > |
| 1185 | func GetBalloonContent() |
| 1186 | " ... initiate getting the content |
| 1187 | return '' |
| 1188 | endfunc |
| 1189 | set balloonexpr=GetBalloonContent() |
| 1190 | |
| 1191 | func BalloonCallback(result) |
| 1192 | call balloon_show(a:result) |
| 1193 | endfunc |
| 1194 | < Can also be used as a |method|: > |
| 1195 | GetText()->balloon_show() |
| 1196 | < |
| 1197 | The intended use is that fetching the content of the balloon |
| 1198 | is initiated from 'balloonexpr'. It will invoke an |
| 1199 | asynchronous method, in which a callback invokes |
| 1200 | balloon_show(). The 'balloonexpr' itself can return an |
Bram Moolenaar | 069a7d5 | 2022-06-27 22:16:08 +0100 | [diff] [blame] | 1201 | empty string or a placeholder, e.g. "loading...". |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1202 | |
Bram Moolenaar | 069a7d5 | 2022-06-27 22:16:08 +0100 | [diff] [blame] | 1203 | When showing a balloon is not possible then nothing happens, |
| 1204 | no error message is given. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1205 | {only available when compiled with the |+balloon_eval| or |
| 1206 | |+balloon_eval_term| feature} |
| 1207 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 1208 | Return type: |Number| |
| 1209 | |
| 1210 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1211 | balloon_split({msg}) *balloon_split()* |
| 1212 | Split String {msg} into lines to be displayed in a balloon. |
| 1213 | The splits are made for the current window size and optimize |
| 1214 | to show debugger output. |
Bram Moolenaar | 016188f | 2022-06-06 20:52:59 +0100 | [diff] [blame] | 1215 | Returns a |List| with the split lines. Returns an empty List |
| 1216 | on error. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1217 | Can also be used as a |method|: > |
| 1218 | GetText()->balloon_split()->balloon_show() |
| 1219 | |
| 1220 | < {only available when compiled with the |+balloon_eval_term| |
| 1221 | feature} |
| 1222 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 1223 | Return type: list<any> or list<string> |
| 1224 | |
Christ van Willegen | ce0ef91 | 2024-06-20 23:41:59 +0200 | [diff] [blame] | 1225 | bindtextdomain({package}, {path}) *bindtextdomain()* |
| 1226 | Bind a specific {package} to a {path} so that the |
| 1227 | |gettext()| function can be used to get language-specific |
| 1228 | translations for a package. {path} is the directory name |
RestorerZ | 9650910 | 2024-07-11 21:14:15 +0200 | [diff] [blame] | 1229 | for the translations. See |package-translation|. |
Christ van Willegen | ce0ef91 | 2024-06-20 23:41:59 +0200 | [diff] [blame] | 1230 | |
Christ van Willegen | 8252ef1 | 2024-07-11 21:36:21 +0200 | [diff] [blame] | 1231 | Returns v:true on success and v:false on failure (out of |
| 1232 | memory). |
| 1233 | |
| 1234 | Return type: |vim9-boolean| |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 1235 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1236 | blob2list({blob}) *blob2list()* |
| 1237 | Return a List containing the number value of each byte in Blob |
| 1238 | {blob}. Examples: > |
| 1239 | blob2list(0z0102.0304) returns [1, 2, 3, 4] |
| 1240 | blob2list(0z) returns [] |
| 1241 | < Returns an empty List on error. |list2blob()| does the |
| 1242 | opposite. |
| 1243 | |
| 1244 | Can also be used as a |method|: > |
| 1245 | GetBlob()->blob2list() |
Bram Moolenaar | b529cfb | 2022-07-25 15:42:07 +0100 | [diff] [blame] | 1246 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 1247 | Return type: list<any> or list<number> |
| 1248 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1249 | *browse()* |
| 1250 | browse({save}, {title}, {initdir}, {default}) |
| 1251 | Put up a file requester. This only works when "has("browse")" |
| 1252 | returns |TRUE| (only in some GUI versions). |
| 1253 | The input fields are: |
| 1254 | {save} when |TRUE|, select file to write |
| 1255 | {title} title for the requester |
| 1256 | {initdir} directory to start browsing in |
| 1257 | {default} default file name |
| 1258 | An empty string is returned when the "Cancel" button is hit, |
| 1259 | something went wrong, or browsing is not possible. |
| 1260 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 1261 | Return type: |String| |
| 1262 | |
| 1263 | |
| 1264 | browsedir({title}, {initdir}) *browsedir()* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1265 | Put up a directory requester. This only works when |
| 1266 | "has("browse")" returns |TRUE| (only in some GUI versions). |
| 1267 | On systems where a directory browser is not supported a file |
| 1268 | browser is used. In that case: select a file in the directory |
| 1269 | to be used. |
| 1270 | The input fields are: |
| 1271 | {title} title for the requester |
| 1272 | {initdir} directory to start browsing in |
| 1273 | When the "Cancel" button is hit, something went wrong, or |
| 1274 | browsing is not possible, an empty string is returned. |
| 1275 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 1276 | Return type: |String| |
| 1277 | |
| 1278 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1279 | bufadd({name}) *bufadd()* |
Bram Moolenaar | 2eddbac | 2022-08-25 12:45:21 +0100 | [diff] [blame] | 1280 | Add a buffer to the buffer list with name {name} (must be a |
| 1281 | String). |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1282 | If a buffer for file {name} already exists, return that buffer |
| 1283 | number. Otherwise return the buffer number of the newly |
| 1284 | created buffer. When {name} is an empty string then a new |
| 1285 | buffer is always created. |
| 1286 | The buffer will not have 'buflisted' set and not be loaded |
| 1287 | yet. To add some text to the buffer use this: > |
| 1288 | let bufnr = bufadd('someName') |
| 1289 | call bufload(bufnr) |
| 1290 | call setbufline(bufnr, 1, ['some', 'text']) |
Bram Moolenaar | 016188f | 2022-06-06 20:52:59 +0100 | [diff] [blame] | 1291 | < Returns 0 on error. |
| 1292 | Can also be used as a |method|: > |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1293 | let bufnr = 'somename'->bufadd() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 1294 | < |
| 1295 | Return type: |Number| |
| 1296 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1297 | |
| 1298 | bufexists({buf}) *bufexists()* |
| 1299 | The result is a Number, which is |TRUE| if a buffer called |
| 1300 | {buf} exists. |
| 1301 | If the {buf} argument is a number, buffer numbers are used. |
| 1302 | Number zero is the alternate buffer for the current window. |
| 1303 | |
| 1304 | If the {buf} argument is a string it must match a buffer name |
| 1305 | exactly. The name can be: |
| 1306 | - Relative to the current directory. |
| 1307 | - A full path. |
| 1308 | - The name of a buffer with 'buftype' set to "nofile". |
| 1309 | - A URL name. |
| 1310 | Unlisted buffers will be found. |
| 1311 | Note that help files are listed by their short name in the |
| 1312 | output of |:buffers|, but bufexists() requires using their |
| 1313 | long name to be able to find them. |
| 1314 | bufexists() may report a buffer exists, but to use the name |
| 1315 | with a |:buffer| command you may need to use |expand()|. Esp |
| 1316 | for MS-Windows 8.3 names in the form "c:\DOCUME~1" |
| 1317 | Use "bufexists(0)" to test for the existence of an alternate |
| 1318 | file name. |
| 1319 | |
| 1320 | Can also be used as a |method|: > |
| 1321 | let exists = 'somename'->bufexists() |
| 1322 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 1323 | Return type: |Number| |
| 1324 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1325 | Obsolete name: buffer_exists(). *buffer_exists()* |
| 1326 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 1327 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1328 | buflisted({buf}) *buflisted()* |
| 1329 | The result is a Number, which is |TRUE| if a buffer called |
| 1330 | {buf} exists and is listed (has the 'buflisted' option set). |
| 1331 | The {buf} argument is used like with |bufexists()|. |
| 1332 | |
| 1333 | Can also be used as a |method|: > |
| 1334 | let listed = 'somename'->buflisted() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 1335 | < |
| 1336 | Return type: |Number| |
| 1337 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1338 | |
| 1339 | bufload({buf}) *bufload()* |
| 1340 | Ensure the buffer {buf} is loaded. When the buffer name |
| 1341 | refers to an existing file then the file is read. Otherwise |
| 1342 | the buffer will be empty. If the buffer was already loaded |
Bram Moolenaar | 2eddbac | 2022-08-25 12:45:21 +0100 | [diff] [blame] | 1343 | then there is no change. If the buffer is not related to a |
Daniel Steinberg | c2bd205 | 2023-08-09 12:10:59 -0400 | [diff] [blame] | 1344 | file then no file is read (e.g., when 'buftype' is "nofile"). |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1345 | If there is an existing swap file for the file of the buffer, |
| 1346 | there will be no dialog, the buffer will be loaded anyway. |
| 1347 | The {buf} argument is used like with |bufexists()|. |
| 1348 | |
| 1349 | Can also be used as a |method|: > |
| 1350 | eval 'somename'->bufload() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 1351 | < |
| 1352 | Return type: |Number| |
| 1353 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1354 | |
| 1355 | bufloaded({buf}) *bufloaded()* |
| 1356 | The result is a Number, which is |TRUE| if a buffer called |
| 1357 | {buf} exists and is loaded (shown in a window or hidden). |
| 1358 | The {buf} argument is used like with |bufexists()|. |
| 1359 | |
| 1360 | Can also be used as a |method|: > |
| 1361 | let loaded = 'somename'->bufloaded() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 1362 | < |
| 1363 | Return type: |Number| |
| 1364 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1365 | |
| 1366 | bufname([{buf}]) *bufname()* |
| 1367 | The result is the name of a buffer. Mostly as it is displayed |
| 1368 | by the `:ls` command, but not using special names such as |
| 1369 | "[No Name]". |
| 1370 | If {buf} is omitted the current buffer is used. |
| 1371 | If {buf} is a Number, that buffer number's name is given. |
| 1372 | Number zero is the alternate buffer for the current window. |
| 1373 | If {buf} is a String, it is used as a |file-pattern| to match |
| 1374 | with the buffer names. This is always done like 'magic' is |
| 1375 | set and 'cpoptions' is empty. When there is more than one |
| 1376 | match an empty string is returned. |
| 1377 | "" or "%" can be used for the current buffer, "#" for the |
| 1378 | alternate buffer. |
| 1379 | A full match is preferred, otherwise a match at the start, end |
| 1380 | or middle of the buffer name is accepted. If you only want a |
| 1381 | full match then put "^" at the start and "$" at the end of the |
| 1382 | pattern. |
| 1383 | Listed buffers are found first. If there is a single match |
| 1384 | with a listed buffer, that one is returned. Next unlisted |
| 1385 | buffers are searched for. |
| 1386 | If the {buf} is a String, but you want to use it as a buffer |
| 1387 | number, force it to be a Number by adding zero to it: > |
| 1388 | :echo bufname("3" + 0) |
| 1389 | < Can also be used as a |method|: > |
| 1390 | echo bufnr->bufname() |
| 1391 | |
| 1392 | < If the buffer doesn't exist, or doesn't have a name, an empty |
| 1393 | string is returned. > |
| 1394 | bufname("#") alternate buffer name |
| 1395 | bufname(3) name of buffer 3 |
| 1396 | bufname("%") name of current buffer |
| 1397 | bufname("file2") name of buffer where "file2" matches. |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 1398 | < |
| 1399 | Return type: |String| |
| 1400 | *buffer_name()* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1401 | Obsolete name: buffer_name(). |
| 1402 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 1403 | |
| 1404 | bufnr([{buf} [, {create}]]) *bufnr()* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1405 | The result is the number of a buffer, as it is displayed by |
| 1406 | the `:ls` command. For the use of {buf}, see |bufname()| |
| 1407 | above. |
| 1408 | |
| 1409 | If the buffer doesn't exist, -1 is returned. Or, if the |
| 1410 | {create} argument is present and TRUE, a new, unlisted, |
| 1411 | buffer is created and its number is returned. Example: > |
| 1412 | let newbuf = bufnr('Scratch001', 1) |
| 1413 | < Using an empty name uses the current buffer. To create a new |
| 1414 | buffer with an empty name use |bufadd()|. |
| 1415 | |
| 1416 | bufnr("$") is the last buffer: > |
| 1417 | :let last_buffer = bufnr("$") |
| 1418 | < The result is a Number, which is the highest buffer number |
| 1419 | of existing buffers. Note that not all buffers with a smaller |
| 1420 | number necessarily exist, because ":bwipeout" may have removed |
| 1421 | them. Use bufexists() to test for the existence of a buffer. |
| 1422 | |
| 1423 | Can also be used as a |method|: > |
| 1424 | echo bufref->bufnr() |
| 1425 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 1426 | Return type: |Number| |
| 1427 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1428 | Obsolete name: buffer_number(). *buffer_number()* |
| 1429 | *last_buffer_nr()* |
| 1430 | Obsolete name for bufnr("$"): last_buffer_nr(). |
| 1431 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 1432 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1433 | bufwinid({buf}) *bufwinid()* |
| 1434 | The result is a Number, which is the |window-ID| of the first |
| 1435 | window associated with buffer {buf}. For the use of {buf}, |
| 1436 | see |bufname()| above. If buffer {buf} doesn't exist or |
| 1437 | there is no such window, -1 is returned. Example: > |
| 1438 | |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 1439 | echo "A window containing buffer 1 is " .. (bufwinid(1)) |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1440 | < |
Bram Moolenaar | 76db9e0 | 2022-11-09 21:21:04 +0000 | [diff] [blame] | 1441 | Only deals with the current tab page. See |win_findbuf()| for |
| 1442 | finding more. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1443 | |
| 1444 | Can also be used as a |method|: > |
| 1445 | FindBuffer()->bufwinid() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 1446 | < |
| 1447 | Return type: |Number| |
| 1448 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1449 | |
| 1450 | bufwinnr({buf}) *bufwinnr()* |
| 1451 | Like |bufwinid()| but return the window number instead of the |
| 1452 | |window-ID|. |
| 1453 | If buffer {buf} doesn't exist or there is no such window, -1 |
| 1454 | is returned. Example: > |
| 1455 | |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 1456 | echo "A window containing buffer 1 is " .. (bufwinnr(1)) |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1457 | |
| 1458 | < The number can be used with |CTRL-W_w| and ":wincmd w" |
| 1459 | |:wincmd|. |
| 1460 | |
| 1461 | Can also be used as a |method|: > |
| 1462 | FindBuffer()->bufwinnr() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 1463 | < |
| 1464 | Return type: |Number| |
| 1465 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1466 | |
| 1467 | byte2line({byte}) *byte2line()* |
| 1468 | Return the line number that contains the character at byte |
| 1469 | count {byte} in the current buffer. This includes the |
| 1470 | end-of-line character, depending on the 'fileformat' option |
| 1471 | for the current buffer. The first character has byte count |
| 1472 | one. |
| 1473 | Also see |line2byte()|, |go| and |:goto|. |
| 1474 | |
Bram Moolenaar | 016188f | 2022-06-06 20:52:59 +0100 | [diff] [blame] | 1475 | Returns -1 if the {byte} value is invalid. |
| 1476 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1477 | Can also be used as a |method|: > |
| 1478 | GetOffset()->byte2line() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 1479 | < |
| 1480 | Return type: |Number| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1481 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 1482 | {not available when compiled without the |+byte_offset| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1483 | feature} |
| 1484 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 1485 | |
Christian Brabandt | 67672ef | 2023-04-24 21:09:54 +0100 | [diff] [blame] | 1486 | byteidx({expr}, {nr} [, {utf16}]) *byteidx()* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1487 | Return byte index of the {nr}'th character in the String |
| 1488 | {expr}. Use zero for the first character, it then returns |
| 1489 | zero. |
| 1490 | If there are no multibyte characters the returned value is |
| 1491 | equal to {nr}. |
| 1492 | Composing characters are not counted separately, their byte |
| 1493 | length is added to the preceding base character. See |
| 1494 | |byteidxcomp()| below for counting composing characters |
| 1495 | separately. |
Christian Brabandt | 67672ef | 2023-04-24 21:09:54 +0100 | [diff] [blame] | 1496 | When {utf16} is present and TRUE, {nr} is used as the UTF-16 |
| 1497 | index in the String {expr} instead of as the character index. |
| 1498 | The UTF-16 index is the index in the string when it is encoded |
| 1499 | with 16-bit words. If the specified UTF-16 index is in the |
| 1500 | middle of a character (e.g. in a 4-byte character), then the |
| 1501 | byte index of the first byte in the character is returned. |
| 1502 | Refer to |string-offset-encoding| for more information. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1503 | Example : > |
| 1504 | echo matchstr(str, ".", byteidx(str, 3)) |
| 1505 | < will display the fourth character. Another way to do the |
| 1506 | same: > |
| 1507 | let s = strpart(str, byteidx(str, 3)) |
| 1508 | echo strpart(s, 0, byteidx(s, 1)) |
| 1509 | < Also see |strgetchar()| and |strcharpart()|. |
| 1510 | |
| 1511 | If there are less than {nr} characters -1 is returned. |
| 1512 | If there are exactly {nr} characters the length of the string |
| 1513 | in bytes is returned. |
Christian Brabandt | 67672ef | 2023-04-24 21:09:54 +0100 | [diff] [blame] | 1514 | See |charidx()| and |utf16idx()| for getting the character and |
| 1515 | UTF-16 index respectively from the byte index. |
| 1516 | Examples: > |
| 1517 | echo byteidx('a😊😊', 2) returns 5 |
| 1518 | echo byteidx('a😊😊', 2, 1) returns 1 |
| 1519 | echo byteidx('a😊😊', 3, 1) returns 5 |
| 1520 | < |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1521 | Can also be used as a |method|: > |
| 1522 | GetName()->byteidx(idx) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 1523 | < |
| 1524 | Return type: |Number| |
| 1525 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1526 | |
Christian Brabandt | 67672ef | 2023-04-24 21:09:54 +0100 | [diff] [blame] | 1527 | byteidxcomp({expr}, {nr} [, {utf16}]) *byteidxcomp()* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1528 | Like byteidx(), except that a composing character is counted |
| 1529 | as a separate character. Example: > |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 1530 | let s = 'e' .. nr2char(0x301) |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1531 | echo byteidx(s, 1) |
| 1532 | echo byteidxcomp(s, 1) |
| 1533 | echo byteidxcomp(s, 2) |
| 1534 | < The first and third echo result in 3 ('e' plus composing |
| 1535 | character is 3 bytes), the second echo results in 1 ('e' is |
| 1536 | one byte). |
| 1537 | Only works differently from byteidx() when 'encoding' is set |
| 1538 | to a Unicode encoding. |
| 1539 | |
| 1540 | Can also be used as a |method|: > |
| 1541 | GetName()->byteidxcomp(idx) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 1542 | < |
| 1543 | Return type: |Number| |
| 1544 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1545 | |
| 1546 | call({func}, {arglist} [, {dict}]) *call()* *E699* |
| 1547 | Call function {func} with the items in |List| {arglist} as |
| 1548 | arguments. |
| 1549 | {func} can either be a |Funcref| or the name of a function. |
| 1550 | a:firstline and a:lastline are set to the cursor line. |
| 1551 | Returns the return value of the called function. |
| 1552 | {dict} is for functions with the "dict" attribute. It will be |
| 1553 | used to set the local variable "self". |Dictionary-function| |
| 1554 | |
| 1555 | Can also be used as a |method|: > |
| 1556 | GetFunc()->call([arg, arg], dict) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 1557 | < |
| 1558 | Return type: any, depending on {func} |
| 1559 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1560 | |
| 1561 | ceil({expr}) *ceil()* |
| 1562 | Return the smallest integral value greater than or equal to |
| 1563 | {expr} as a |Float| (round up). |
| 1564 | {expr} must evaluate to a |Float| or a |Number|. |
| 1565 | Examples: > |
| 1566 | echo ceil(1.456) |
| 1567 | < 2.0 > |
| 1568 | echo ceil(-5.456) |
| 1569 | < -5.0 > |
| 1570 | echo ceil(4.0) |
| 1571 | < 4.0 |
| 1572 | |
Bram Moolenaar | 016188f | 2022-06-06 20:52:59 +0100 | [diff] [blame] | 1573 | Returns 0.0 if {expr} is not a |Float| or a |Number|. |
| 1574 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1575 | Can also be used as a |method|: > |
| 1576 | Compute()->ceil() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 1577 | < |
| 1578 | Return type: |Float| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1579 | |
| 1580 | |
| 1581 | ch_ functions are documented here: |channel-functions-details| |
| 1582 | |
| 1583 | |
| 1584 | changenr() *changenr()* |
| 1585 | Return the number of the most recent change. This is the same |
| 1586 | number as what is displayed with |:undolist| and can be used |
| 1587 | with the |:undo| command. |
| 1588 | When a change was made it is the number of that change. After |
| 1589 | redo it is the number of the redone change. After undo it is |
| 1590 | one less than the number of the undone change. |
Bram Moolenaar | 016188f | 2022-06-06 20:52:59 +0100 | [diff] [blame] | 1591 | Returns 0 if the undo list is empty. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1592 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 1593 | Return type: |Number| |
| 1594 | |
| 1595 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1596 | char2nr({string} [, {utf8}]) *char2nr()* |
Bram Moolenaar | 2d8ed02 | 2022-05-21 13:08:16 +0100 | [diff] [blame] | 1597 | Return Number value of the first char in {string}. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1598 | Examples: > |
| 1599 | char2nr(" ") returns 32 |
| 1600 | char2nr("ABC") returns 65 |
| 1601 | < When {utf8} is omitted or zero, the current 'encoding' is used. |
| 1602 | Example for "utf-8": > |
| 1603 | char2nr("á") returns 225 |
| 1604 | char2nr("á"[0]) returns 195 |
| 1605 | < When {utf8} is TRUE, always treat as UTF-8 characters. |
| 1606 | A combining character is a separate character. |
| 1607 | |nr2char()| does the opposite. |
| 1608 | To turn a string into a list of character numbers: > |
| 1609 | let str = "ABC" |
| 1610 | let list = map(split(str, '\zs'), {_, val -> char2nr(val)}) |
| 1611 | < Result: [65, 66, 67] |
| 1612 | |
Bram Moolenaar | 016188f | 2022-06-06 20:52:59 +0100 | [diff] [blame] | 1613 | Returns 0 if {string} is not a |String|. |
| 1614 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1615 | Can also be used as a |method|: > |
| 1616 | GetChar()->char2nr() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 1617 | < |
| 1618 | Return type: |Number| |
| 1619 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1620 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1621 | charclass({string}) *charclass()* |
| 1622 | Return the character class of the first character in {string}. |
| 1623 | The character class is one of: |
| 1624 | 0 blank |
| 1625 | 1 punctuation |
| 1626 | 2 word character |
| 1627 | 3 emoji |
| 1628 | other specific Unicode class |
| 1629 | The class is used in patterns and word motions. |
Bram Moolenaar | 016188f | 2022-06-06 20:52:59 +0100 | [diff] [blame] | 1630 | Returns 0 if {string} is not a |String|. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1631 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 1632 | Return type: |Number| |
| 1633 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1634 | |
Yegappan Lakshmanan | 4c8d2f0 | 2022-11-12 16:07:47 +0000 | [diff] [blame] | 1635 | charcol({expr} [, {winid}]) *charcol()* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1636 | Same as |col()| but returns the character index of the column |
| 1637 | position given with {expr} instead of the byte position. |
| 1638 | |
| 1639 | Example: |
| 1640 | With the cursor on '세' in line 5 with text "여보세요": > |
| 1641 | charcol('.') returns 3 |
| 1642 | col('.') returns 7 |
| 1643 | |
| 1644 | < Can also be used as a |method|: > |
| 1645 | GetPos()->col() |
| 1646 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 1647 | Return type: |Number| |
| 1648 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1649 | *charidx()* |
Christian Brabandt | 67672ef | 2023-04-24 21:09:54 +0100 | [diff] [blame] | 1650 | charidx({string}, {idx} [, {countcc} [, {utf16}]]) |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1651 | Return the character index of the byte at {idx} in {string}. |
| 1652 | The index of the first character is zero. |
| 1653 | If there are no multibyte characters the returned value is |
| 1654 | equal to {idx}. |
Christian Brabandt | 67672ef | 2023-04-24 21:09:54 +0100 | [diff] [blame] | 1655 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1656 | When {countcc} is omitted or |FALSE|, then composing characters |
Christian Brabandt | 67672ef | 2023-04-24 21:09:54 +0100 | [diff] [blame] | 1657 | are not counted separately, their byte length is added to the |
| 1658 | preceding base character. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1659 | When {countcc} is |TRUE|, then composing characters are |
| 1660 | counted as separate characters. |
Christian Brabandt | 67672ef | 2023-04-24 21:09:54 +0100 | [diff] [blame] | 1661 | |
| 1662 | When {utf16} is present and TRUE, {idx} is used as the UTF-16 |
| 1663 | index in the String {expr} instead of as the byte index. |
| 1664 | |
Yegappan Lakshmanan | 577922b | 2023-06-08 17:09:45 +0100 | [diff] [blame] | 1665 | Returns -1 if the arguments are invalid or if there are less |
| 1666 | than {idx} bytes. If there are exactly {idx} bytes the length |
| 1667 | of the string in characters is returned. |
| 1668 | |
| 1669 | An error is given and -1 is returned if the first argument is |
| 1670 | not a string, the second argument is not a number or when the |
| 1671 | third argument is present and is not zero or one. |
Christian Brabandt | 67672ef | 2023-04-24 21:09:54 +0100 | [diff] [blame] | 1672 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1673 | See |byteidx()| and |byteidxcomp()| for getting the byte index |
Christian Brabandt | 67672ef | 2023-04-24 21:09:54 +0100 | [diff] [blame] | 1674 | from the character index and |utf16idx()| for getting the |
| 1675 | UTF-16 index from the character index. |
| 1676 | Refer to |string-offset-encoding| for more information. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1677 | Examples: > |
| 1678 | echo charidx('áb́ć', 3) returns 1 |
| 1679 | echo charidx('áb́ć', 6, 1) returns 4 |
| 1680 | echo charidx('áb́ć', 16) returns -1 |
Christian Brabandt | 67672ef | 2023-04-24 21:09:54 +0100 | [diff] [blame] | 1681 | echo charidx('a😊😊', 4, 0, 1) returns 2 |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1682 | < |
| 1683 | Can also be used as a |method|: > |
| 1684 | GetName()->charidx(idx) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 1685 | < |
| 1686 | Return type: |Number| |
| 1687 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1688 | |
| 1689 | chdir({dir}) *chdir()* |
| 1690 | Change the current working directory to {dir}. The scope of |
| 1691 | the directory change depends on the directory of the current |
| 1692 | window: |
| 1693 | - If the current window has a window-local directory |
| 1694 | (|:lcd|), then changes the window local directory. |
| 1695 | - Otherwise, if the current tabpage has a local |
| 1696 | directory (|:tcd|) then changes the tabpage local |
| 1697 | directory. |
| 1698 | - Otherwise, changes the global directory. |
| 1699 | {dir} must be a String. |
| 1700 | If successful, returns the previous working directory. Pass |
| 1701 | this to another chdir() to restore the directory. |
| 1702 | On failure, returns an empty string. |
| 1703 | |
| 1704 | Example: > |
| 1705 | let save_dir = chdir(newdir) |
| 1706 | if save_dir != "" |
| 1707 | " ... do some work |
| 1708 | call chdir(save_dir) |
| 1709 | endif |
| 1710 | |
| 1711 | < Can also be used as a |method|: > |
| 1712 | GetDir()->chdir() |
| 1713 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 1714 | Return type: |String| |
| 1715 | |
| 1716 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1717 | cindent({lnum}) *cindent()* |
| 1718 | Get the amount of indent for line {lnum} according the C |
| 1719 | indenting rules, as with 'cindent'. |
| 1720 | The indent is counted in spaces, the value of 'tabstop' is |
| 1721 | relevant. {lnum} is used just like in |getline()|. |
Bram Moolenaar | 8e145b8 | 2022-05-21 20:17:31 +0100 | [diff] [blame] | 1722 | When {lnum} is invalid -1 is returned. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1723 | See |C-indenting|. |
| 1724 | |
| 1725 | Can also be used as a |method|: > |
| 1726 | GetLnum()->cindent() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 1727 | < |
| 1728 | Return type: |Number| |
| 1729 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1730 | |
| 1731 | clearmatches([{win}]) *clearmatches()* |
| 1732 | Clears all matches previously defined for the current window |
| 1733 | by |matchadd()| and the |:match| commands. |
| 1734 | If {win} is specified, use the window with this number or |
| 1735 | window ID instead of the current window. |
| 1736 | |
| 1737 | Can also be used as a |method|: > |
| 1738 | GetWin()->clearmatches() |
| 1739 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 1740 | Return type: |Number| |
| 1741 | |
| 1742 | |
Bram Moolenaar | 10e8ff9 | 2023-06-10 21:40:39 +0100 | [diff] [blame] | 1743 | col({expr} [, {winid}]) *col()* |
Yegappan Lakshmanan | 4c8d2f0 | 2022-11-12 16:07:47 +0000 | [diff] [blame] | 1744 | The result is a Number, which is the byte index of the column |
zeertzjq | 02f3eba | 2024-06-12 20:45:24 +0200 | [diff] [blame] | 1745 | position given with {expr}. |
| 1746 | For accepted positions see |getpos()|. |
zeertzjq | d353d27 | 2024-06-13 23:00:25 +0800 | [diff] [blame] | 1747 | When {expr} is "$", it means the end of the cursor line, so |
| 1748 | the result is the number of bytes in the cursor line plus one. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1749 | Additionally {expr} can be [lnum, col]: a |List| with the line |
| 1750 | and column number. Most useful when the column is "$", to get |
| 1751 | the last column of a specific line. When "lnum" or "col" is |
| 1752 | out of range then col() returns zero. |
zeertzjq | 02f3eba | 2024-06-12 20:45:24 +0200 | [diff] [blame] | 1753 | |
Yegappan Lakshmanan | 4c8d2f0 | 2022-11-12 16:07:47 +0000 | [diff] [blame] | 1754 | With the optional {winid} argument the values are obtained for |
| 1755 | that window instead of the current window. |
zeertzjq | 02f3eba | 2024-06-12 20:45:24 +0200 | [diff] [blame] | 1756 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1757 | To get the line number use |line()|. To get both use |
| 1758 | |getpos()|. |
| 1759 | For the screen column position use |virtcol()|. For the |
| 1760 | character position use |charcol()|. |
zeertzjq | 02f3eba | 2024-06-12 20:45:24 +0200 | [diff] [blame] | 1761 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1762 | Note that only marks in the current file can be used. |
zeertzjq | 02f3eba | 2024-06-12 20:45:24 +0200 | [diff] [blame] | 1763 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1764 | Examples: > |
| 1765 | col(".") column of cursor |
| 1766 | col("$") length of cursor line plus one |
| 1767 | col("'t") column of mark t |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 1768 | col("'" .. markname) column of mark markname |
zeertzjq | 02f3eba | 2024-06-12 20:45:24 +0200 | [diff] [blame] | 1769 | < |
| 1770 | The first column is 1. Returns 0 if {expr} is invalid or when |
Yegappan Lakshmanan | 4c8d2f0 | 2022-11-12 16:07:47 +0000 | [diff] [blame] | 1771 | the window with ID {winid} is not found. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1772 | For an uppercase mark the column may actually be in another |
| 1773 | buffer. |
| 1774 | For the cursor position, when 'virtualedit' is active, the |
| 1775 | column is one higher if the cursor is after the end of the |
Bram Moolenaar | 6ebe4f9 | 2022-10-28 20:47:54 +0100 | [diff] [blame] | 1776 | line. Also, when using a <Cmd> mapping the cursor isn't |
| 1777 | moved, this can be used to obtain the column in Insert mode: > |
Bram Moolenaar | 76db9e0 | 2022-11-09 21:21:04 +0000 | [diff] [blame] | 1778 | :imap <F2> <Cmd>echowin col(".")<CR> |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1779 | |
| 1780 | < Can also be used as a |method|: > |
| 1781 | GetPos()->col() |
| 1782 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 1783 | Return type: |Number| |
| 1784 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1785 | |
| 1786 | complete({startcol}, {matches}) *complete()* *E785* |
| 1787 | Set the matches for Insert mode completion. |
| 1788 | Can only be used in Insert mode. You need to use a mapping |
| 1789 | with CTRL-R = (see |i_CTRL-R|). It does not work after CTRL-O |
| 1790 | or with an expression mapping. |
| 1791 | {startcol} is the byte offset in the line where the completed |
| 1792 | text start. The text up to the cursor is the original text |
| 1793 | that will be replaced by the matches. Use col('.') for an |
| 1794 | empty string. "col('.') - 1" will replace one character by a |
| 1795 | match. |
| 1796 | {matches} must be a |List|. Each |List| item is one match. |
| 1797 | See |complete-items| for the kind of items that are possible. |
| 1798 | "longest" in 'completeopt' is ignored. |
| 1799 | Note that the after calling this function you need to avoid |
| 1800 | inserting anything that would cause completion to stop. |
| 1801 | The match can be selected with CTRL-N and CTRL-P as usual with |
| 1802 | Insert mode completion. The popup menu will appear if |
| 1803 | specified, see |ins-completion-menu|. |
| 1804 | Example: > |
| 1805 | inoremap <F5> <C-R>=ListMonths()<CR> |
| 1806 | |
Bram Moolenaar | 10e8ff9 | 2023-06-10 21:40:39 +0100 | [diff] [blame] | 1807 | func ListMonths() |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1808 | call complete(col('.'), ['January', 'February', 'March', |
| 1809 | \ 'April', 'May', 'June', 'July', 'August', 'September', |
| 1810 | \ 'October', 'November', 'December']) |
| 1811 | return '' |
| 1812 | endfunc |
| 1813 | < This isn't very useful, but it shows how it works. Note that |
| 1814 | an empty string is returned to avoid a zero being inserted. |
| 1815 | |
| 1816 | Can also be used as a |method|, the base is passed as the |
| 1817 | second argument: > |
| 1818 | GetMatches()->complete(col('.')) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 1819 | < |
| 1820 | Return type: |Number| |
| 1821 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1822 | |
| 1823 | complete_add({expr}) *complete_add()* |
| 1824 | Add {expr} to the list of matches. Only to be used by the |
| 1825 | function specified with the 'completefunc' option. |
| 1826 | Returns 0 for failure (empty string or out of memory), |
| 1827 | 1 when the match was added, 2 when the match was already in |
| 1828 | the list. |
| 1829 | See |complete-functions| for an explanation of {expr}. It is |
| 1830 | the same as one item in the list that 'omnifunc' would return. |
| 1831 | |
| 1832 | Can also be used as a |method|: > |
| 1833 | GetMoreMatches()->complete_add() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 1834 | < |
| 1835 | Return type: |Number| |
| 1836 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1837 | |
| 1838 | complete_check() *complete_check()* |
| 1839 | Check for a key typed while looking for completion matches. |
| 1840 | This is to be used when looking for matches takes some time. |
| 1841 | Returns |TRUE| when searching for matches is to be aborted, |
| 1842 | zero otherwise. |
| 1843 | Only to be used by the function specified with the |
| 1844 | 'completefunc' option. |
| 1845 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 1846 | Return type: |Number| |
| 1847 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1848 | |
| 1849 | complete_info([{what}]) *complete_info()* |
| 1850 | Returns a |Dictionary| with information about Insert mode |
| 1851 | completion. See |ins-completion|. |
| 1852 | The items are: |
| 1853 | mode Current completion mode name string. |
| 1854 | See |complete_info_mode| for the values. |
| 1855 | pum_visible |TRUE| if popup menu is visible. |
| 1856 | See |pumvisible()|. |
| 1857 | items List of completion matches. Each item is a |
| 1858 | dictionary containing the entries "word", |
| 1859 | "abbr", "menu", "kind", "info" and "user_data". |
| 1860 | See |complete-items|. |
| 1861 | selected Selected item index. First index is zero. |
| 1862 | Index is -1 if no item is selected (showing |
| 1863 | typed text only, or the last completion after |
| 1864 | no item is selected when using the <Up> or |
| 1865 | <Down> keys) |
Bram Moolenaar | 0daafaa | 2022-09-04 17:45:43 +0100 | [diff] [blame] | 1866 | inserted Inserted string. [NOT IMPLEMENTED YET] |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1867 | |
| 1868 | *complete_info_mode* |
| 1869 | mode values are: |
| 1870 | "" Not in completion mode |
| 1871 | "keyword" Keyword completion |i_CTRL-X_CTRL-N| |
| 1872 | "ctrl_x" Just pressed CTRL-X |i_CTRL-X| |
| 1873 | "scroll" Scrolling with |i_CTRL-X_CTRL-E| or |
| 1874 | |i_CTRL-X_CTRL-Y| |
| 1875 | "whole_line" Whole lines |i_CTRL-X_CTRL-L| |
| 1876 | "files" File names |i_CTRL-X_CTRL-F| |
| 1877 | "tags" Tags |i_CTRL-X_CTRL-]| |
| 1878 | "path_defines" Definition completion |i_CTRL-X_CTRL-D| |
| 1879 | "path_patterns" Include completion |i_CTRL-X_CTRL-I| |
| 1880 | "dictionary" Dictionary |i_CTRL-X_CTRL-K| |
| 1881 | "thesaurus" Thesaurus |i_CTRL-X_CTRL-T| |
| 1882 | "cmdline" Vim Command line |i_CTRL-X_CTRL-V| |
| 1883 | "function" User defined completion |i_CTRL-X_CTRL-U| |
| 1884 | "omni" Omni completion |i_CTRL-X_CTRL-O| |
| 1885 | "spell" Spelling suggestions |i_CTRL-X_s| |
| 1886 | "eval" |complete()| completion |
| 1887 | "unknown" Other internal modes |
| 1888 | |
| 1889 | If the optional {what} list argument is supplied, then only |
| 1890 | the items listed in {what} are returned. Unsupported items in |
| 1891 | {what} are silently ignored. |
| 1892 | |
| 1893 | To get the position and size of the popup menu, see |
| 1894 | |pum_getpos()|. It's also available in |v:event| during the |
| 1895 | |CompleteChanged| event. |
| 1896 | |
Bram Moolenaar | 016188f | 2022-06-06 20:52:59 +0100 | [diff] [blame] | 1897 | Returns an empty |Dictionary| on error. |
| 1898 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1899 | Examples: > |
| 1900 | " Get all items |
| 1901 | call complete_info() |
| 1902 | " Get only 'mode' |
| 1903 | call complete_info(['mode']) |
| 1904 | " Get only 'mode' and 'pum_visible' |
| 1905 | call complete_info(['mode', 'pum_visible']) |
| 1906 | |
| 1907 | < Can also be used as a |method|: > |
| 1908 | GetItems()->complete_info() |
| 1909 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 1910 | Return type: dict<any> |
| 1911 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1912 | *confirm()* |
| 1913 | confirm({msg} [, {choices} [, {default} [, {type}]]]) |
| 1914 | confirm() offers the user a dialog, from which a choice can be |
| 1915 | made. It returns the number of the choice. For the first |
| 1916 | choice this is 1. |
| 1917 | Note: confirm() is only supported when compiled with dialog |
glepnir | df46115 | 2024-04-04 22:23:29 +0200 | [diff] [blame] | 1918 | support, see |+dialog_con| |+dialog_con_gui| and |+dialog_gui|. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1919 | |
| 1920 | {msg} is displayed in a |dialog| with {choices} as the |
| 1921 | alternatives. When {choices} is missing or empty, "&OK" is |
| 1922 | used (and translated). |
| 1923 | {msg} is a String, use '\n' to include a newline. Only on |
| 1924 | some systems the string is wrapped when it doesn't fit. |
| 1925 | |
| 1926 | {choices} is a String, with the individual choices separated |
| 1927 | by '\n', e.g. > |
| 1928 | confirm("Save changes?", "&Yes\n&No\n&Cancel") |
| 1929 | < The letter after the '&' is the shortcut key for that choice. |
| 1930 | Thus you can type 'c' to select "Cancel". The shortcut does |
| 1931 | not need to be the first letter: > |
| 1932 | confirm("file has been modified", "&Save\nSave &All") |
| 1933 | < For the console, the first letter of each choice is used as |
| 1934 | the default shortcut key. Case is ignored. |
| 1935 | |
| 1936 | The optional {default} argument is the number of the choice |
| 1937 | that is made if the user hits <CR>. Use 1 to make the first |
| 1938 | choice the default one. Use 0 to not set a default. If |
| 1939 | {default} is omitted, 1 is used. |
| 1940 | |
| 1941 | The optional {type} String argument gives the type of dialog. |
| 1942 | This is only used for the icon of the GTK, Mac, Motif and |
| 1943 | Win32 GUI. It can be one of these values: "Error", |
| 1944 | "Question", "Info", "Warning" or "Generic". Only the first |
| 1945 | character is relevant. When {type} is omitted, "Generic" is |
| 1946 | used. |
| 1947 | |
| 1948 | If the user aborts the dialog by pressing <Esc>, CTRL-C, |
| 1949 | or another valid interrupt key, confirm() returns 0. |
| 1950 | |
| 1951 | An example: > |
Bram Moolenaar | 46eea44 | 2022-03-30 10:51:39 +0100 | [diff] [blame] | 1952 | let choice = confirm("What do you want?", |
Bram Moolenaar | 2d8ed02 | 2022-05-21 13:08:16 +0100 | [diff] [blame] | 1953 | \ "&Apples\n&Oranges\n&Bananas", 2) |
Bram Moolenaar | 46eea44 | 2022-03-30 10:51:39 +0100 | [diff] [blame] | 1954 | if choice == 0 |
Bram Moolenaar | 2d8ed02 | 2022-05-21 13:08:16 +0100 | [diff] [blame] | 1955 | echo "make up your mind!" |
Bram Moolenaar | 46eea44 | 2022-03-30 10:51:39 +0100 | [diff] [blame] | 1956 | elseif choice == 3 |
Bram Moolenaar | 2d8ed02 | 2022-05-21 13:08:16 +0100 | [diff] [blame] | 1957 | echo "tasteful" |
Bram Moolenaar | 46eea44 | 2022-03-30 10:51:39 +0100 | [diff] [blame] | 1958 | else |
Bram Moolenaar | 2d8ed02 | 2022-05-21 13:08:16 +0100 | [diff] [blame] | 1959 | echo "I prefer bananas myself." |
Bram Moolenaar | 46eea44 | 2022-03-30 10:51:39 +0100 | [diff] [blame] | 1960 | endif |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1961 | < In a GUI dialog, buttons are used. The layout of the buttons |
| 1962 | depends on the 'v' flag in 'guioptions'. If it is included, |
| 1963 | the buttons are always put vertically. Otherwise, confirm() |
| 1964 | tries to put the buttons in one horizontal line. If they |
| 1965 | don't fit, a vertical layout is used anyway. For some systems |
| 1966 | the horizontal layout is always used. |
| 1967 | |
| 1968 | Can also be used as a |method|in: > |
| 1969 | BuildMessage()->confirm("&Yes\n&No") |
| 1970 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 1971 | Return type: |Number| |
| 1972 | |
| 1973 | |
| 1974 | copy({expr}) *copy()* |
| 1975 | Make a copy of {expr}. For Numbers and Strings this isn't |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1976 | different from using {expr} directly. |
| 1977 | When {expr} is a |List| a shallow copy is created. This means |
| 1978 | that the original |List| can be changed without changing the |
| 1979 | copy, and vice versa. But the items are identical, thus |
| 1980 | changing an item changes the contents of both |Lists|. |
| 1981 | A |Dictionary| is copied in a similar way as a |List|. |
| 1982 | Also see |deepcopy()|. |
| 1983 | Can also be used as a |method|: > |
| 1984 | mylist->copy() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 1985 | < |
| 1986 | Return type: any, depending on {expr} |
| 1987 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1988 | |
| 1989 | cos({expr}) *cos()* |
| 1990 | Return the cosine of {expr}, measured in radians, as a |Float|. |
| 1991 | {expr} must evaluate to a |Float| or a |Number|. |
Bram Moolenaar | 016188f | 2022-06-06 20:52:59 +0100 | [diff] [blame] | 1992 | Returns 0.0 if {expr} is not a |Float| or a |Number|. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 1993 | Examples: > |
| 1994 | :echo cos(100) |
| 1995 | < 0.862319 > |
| 1996 | :echo cos(-4.01) |
| 1997 | < -0.646043 |
| 1998 | |
| 1999 | Can also be used as a |method|: > |
| 2000 | Compute()->cos() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 2001 | < |
| 2002 | Return type: |Float| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2003 | |
| 2004 | |
| 2005 | cosh({expr}) *cosh()* |
| 2006 | Return the hyperbolic cosine of {expr} as a |Float| in the range |
| 2007 | [1, inf]. |
| 2008 | {expr} must evaluate to a |Float| or a |Number|. |
Bram Moolenaar | 016188f | 2022-06-06 20:52:59 +0100 | [diff] [blame] | 2009 | Returns 0.0 if {expr} is not a |Float| or a |Number|. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2010 | Examples: > |
| 2011 | :echo cosh(0.5) |
| 2012 | < 1.127626 > |
| 2013 | :echo cosh(-0.5) |
| 2014 | < -1.127626 |
| 2015 | |
| 2016 | Can also be used as a |method|: > |
| 2017 | Compute()->cosh() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 2018 | < |
| 2019 | Return type: |Float| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2020 | |
| 2021 | |
Yegappan Lakshmanan | cd39b69 | 2023-10-02 12:50:45 -0700 | [diff] [blame] | 2022 | count({comp}, {expr} [, {ic} [, {start}]]) *count()* *E706* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2023 | Return the number of times an item with value {expr} appears |
| 2024 | in |String|, |List| or |Dictionary| {comp}. |
| 2025 | |
| 2026 | If {start} is given then start with the item with this index. |
| 2027 | {start} can only be used with a |List|. |
| 2028 | |
| 2029 | When {ic} is given and it's |TRUE| then case is ignored. |
| 2030 | |
| 2031 | When {comp} is a string then the number of not overlapping |
| 2032 | occurrences of {expr} is returned. Zero is returned when |
| 2033 | {expr} is an empty string. |
| 2034 | |
| 2035 | Can also be used as a |method|: > |
| 2036 | mylist->count(val) |
| 2037 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 2038 | Return type: |Number| |
| 2039 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2040 | *cscope_connection()* |
| 2041 | cscope_connection([{num} , {dbpath} [, {prepend}]]) |
| 2042 | Checks for the existence of a |cscope| connection. If no |
| 2043 | parameters are specified, then the function returns: |
| 2044 | 0, if cscope was not available (not compiled in), or |
| 2045 | if there are no cscope connections; |
| 2046 | 1, if there is at least one cscope connection. |
| 2047 | |
| 2048 | If parameters are specified, then the value of {num} |
| 2049 | determines how existence of a cscope connection is checked: |
| 2050 | |
| 2051 | {num} Description of existence check |
| 2052 | ----- ------------------------------ |
| 2053 | 0 Same as no parameters (e.g., "cscope_connection()"). |
| 2054 | 1 Ignore {prepend}, and use partial string matches for |
| 2055 | {dbpath}. |
| 2056 | 2 Ignore {prepend}, and use exact string matches for |
| 2057 | {dbpath}. |
| 2058 | 3 Use {prepend}, use partial string matches for both |
| 2059 | {dbpath} and {prepend}. |
| 2060 | 4 Use {prepend}, use exact string matches for both |
| 2061 | {dbpath} and {prepend}. |
| 2062 | |
| 2063 | Note: All string comparisons are case sensitive! |
| 2064 | |
| 2065 | Examples. Suppose we had the following (from ":cs show"): > |
| 2066 | |
| 2067 | # pid database name prepend path |
| 2068 | 0 27664 cscope.out /usr/local |
| 2069 | < |
| 2070 | Invocation Return Val ~ |
| 2071 | ---------- ---------- > |
| 2072 | cscope_connection() 1 |
| 2073 | cscope_connection(1, "out") 1 |
| 2074 | cscope_connection(2, "out") 0 |
| 2075 | cscope_connection(3, "out") 0 |
| 2076 | cscope_connection(3, "out", "local") 1 |
| 2077 | cscope_connection(4, "out") 0 |
| 2078 | cscope_connection(4, "out", "local") 0 |
| 2079 | cscope_connection(4, "cscope.out", "/usr/local") 1 |
| 2080 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 2081 | Return type: |Number| |
| 2082 | |
| 2083 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2084 | cursor({lnum}, {col} [, {off}]) *cursor()* |
| 2085 | cursor({list}) |
| 2086 | Positions the cursor at the column (byte count) {col} in the |
| 2087 | line {lnum}. The first column is one. |
| 2088 | |
| 2089 | When there is one argument {list} this is used as a |List| |
| 2090 | with two, three or four item: |
| 2091 | [{lnum}, {col}] |
| 2092 | [{lnum}, {col}, {off}] |
| 2093 | [{lnum}, {col}, {off}, {curswant}] |
| 2094 | This is like the return value of |getpos()| or |getcurpos()|, |
| 2095 | but without the first item. |
| 2096 | |
Bram Moolenaar | 10e8ff9 | 2023-06-10 21:40:39 +0100 | [diff] [blame] | 2097 | To position the cursor using {col} as the character count, use |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2098 | |setcursorcharpos()|. |
| 2099 | |
| 2100 | Does not change the jumplist. |
Bram Moolenaar | 7c6cd44 | 2022-10-11 21:54:04 +0100 | [diff] [blame] | 2101 | {lnum} is used like with |getline()|, except that if {lnum} is |
| 2102 | zero, the cursor will stay in the current line. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2103 | If {lnum} is greater than the number of lines in the buffer, |
| 2104 | the cursor will be positioned at the last line in the buffer. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2105 | If {col} is greater than the number of bytes in the line, |
| 2106 | the cursor will be positioned at the last character in the |
| 2107 | line. |
| 2108 | If {col} is zero, the cursor will stay in the current column. |
| 2109 | If {curswant} is given it is used to set the preferred column |
| 2110 | for vertical movement. Otherwise {col} is used. |
| 2111 | |
| 2112 | When 'virtualedit' is used {off} specifies the offset in |
| 2113 | screen columns from the start of the character. E.g., a |
| 2114 | position within a <Tab> or after the last character. |
| 2115 | Returns 0 when the position could be set, -1 otherwise. |
| 2116 | |
| 2117 | Can also be used as a |method|: > |
| 2118 | GetCursorPos()->cursor() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 2119 | < |
| 2120 | Return type: |Number| |
| 2121 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2122 | |
| 2123 | debugbreak({pid}) *debugbreak()* |
| 2124 | Specifically used to interrupt a program being debugged. It |
| 2125 | will cause process {pid} to get a SIGTRAP. Behavior for other |
| 2126 | processes is undefined. See |terminal-debugger|. |
| 2127 | {only available on MS-Windows} |
| 2128 | |
Bram Moolenaar | 016188f | 2022-06-06 20:52:59 +0100 | [diff] [blame] | 2129 | Returns |TRUE| if successfully interrupted the program. |
| 2130 | Otherwise returns |FALSE|. |
| 2131 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2132 | Can also be used as a |method|: > |
| 2133 | GetPid()->debugbreak() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 2134 | < |
| 2135 | Return type: |Number| |
| 2136 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2137 | |
| 2138 | deepcopy({expr} [, {noref}]) *deepcopy()* *E698* |
| 2139 | Make a copy of {expr}. For Numbers and Strings this isn't |
| 2140 | different from using {expr} directly. |
| 2141 | When {expr} is a |List| a full copy is created. This means |
| 2142 | that the original |List| can be changed without changing the |
| 2143 | copy, and vice versa. When an item is a |List| or |
| 2144 | |Dictionary|, a copy for it is made, recursively. Thus |
| 2145 | changing an item in the copy does not change the contents of |
| 2146 | the original |List|. |
| 2147 | A |Dictionary| is copied in a similar way as a |List|. |
| 2148 | |
| 2149 | When {noref} is omitted or zero a contained |List| or |
| 2150 | |Dictionary| is only copied once. All references point to |
| 2151 | this single copy. With {noref} set to 1 every occurrence of a |
| 2152 | |List| or |Dictionary| results in a new copy. This also means |
| 2153 | that a cyclic reference causes deepcopy() to fail. |
| 2154 | *E724* |
| 2155 | Nesting is possible up to 100 levels. When there is an item |
| 2156 | that refers back to a higher level making a deep copy with |
| 2157 | {noref} set to 1 will fail. |
| 2158 | Also see |copy()|. |
| 2159 | |
| 2160 | Can also be used as a |method|: > |
| 2161 | GetObject()->deepcopy() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 2162 | < |
| 2163 | Return type: any, depending on {expr} |
| 2164 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2165 | |
| 2166 | delete({fname} [, {flags}]) *delete()* |
| 2167 | Without {flags} or with {flags} empty: Deletes the file by the |
Bram Moolenaar | cbaff5e | 2022-04-08 17:45:08 +0100 | [diff] [blame] | 2168 | name {fname}. |
| 2169 | |
| 2170 | This also works when {fname} is a symbolic link. The symbolic |
| 2171 | link itself is deleted, not what it points to. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2172 | |
| 2173 | When {flags} is "d": Deletes the directory by the name |
| 2174 | {fname}. This fails when directory {fname} is not empty. |
| 2175 | |
| 2176 | When {flags} is "rf": Deletes the directory by the name |
| 2177 | {fname} and everything in it, recursively. BE CAREFUL! |
| 2178 | Note: on MS-Windows it is not possible to delete a directory |
| 2179 | that is being used. |
| 2180 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2181 | The result is a Number, which is 0/false if the delete |
| 2182 | operation was successful and -1/true when the deletion failed |
| 2183 | or partly failed. |
| 2184 | |
| 2185 | Use |remove()| to delete an item from a |List|. |
| 2186 | To delete a line from the buffer use |:delete| or |
| 2187 | |deletebufline()|. |
| 2188 | |
| 2189 | Can also be used as a |method|: > |
| 2190 | GetName()->delete() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 2191 | < |
| 2192 | Return type: |Number| |
| 2193 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2194 | |
| 2195 | deletebufline({buf}, {first} [, {last}]) *deletebufline()* |
| 2196 | Delete lines {first} to {last} (inclusive) from buffer {buf}. |
| 2197 | If {last} is omitted then delete line {first} only. |
| 2198 | On success 0 is returned, on failure 1 is returned. |
| 2199 | |
| 2200 | This function works only for loaded buffers. First call |
| 2201 | |bufload()| if needed. |
| 2202 | |
| 2203 | For the use of {buf}, see |bufname()| above. |
| 2204 | |
| 2205 | {first} and {last} are used like with |getline()|. Note that |
| 2206 | when using |line()| this refers to the current buffer. Use "$" |
| 2207 | to refer to the last line in buffer {buf}. |
| 2208 | |
| 2209 | Can also be used as a |method|: > |
| 2210 | GetBuffer()->deletebufline(1) |
| 2211 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 2212 | Return type: |Number| |
| 2213 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2214 | *did_filetype()* |
| 2215 | did_filetype() Returns |TRUE| when autocommands are being executed and the |
| 2216 | FileType event has been triggered at least once. Can be used |
| 2217 | to avoid triggering the FileType event again in the scripts |
| 2218 | that detect the file type. |FileType| |
| 2219 | Returns |FALSE| when `:setf FALLBACK` was used. |
| 2220 | When editing another file, the counter is reset, thus this |
| 2221 | really checks if the FileType event has been triggered for the |
| 2222 | current buffer. This allows an autocommand that starts |
| 2223 | editing another buffer to set 'filetype' and load a syntax |
| 2224 | file. |
| 2225 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 2226 | Return type: |Number| |
| 2227 | |
| 2228 | |
Yegappan Lakshmanan | fa37835 | 2024-02-01 22:05:27 +0100 | [diff] [blame] | 2229 | diff({fromlist}, {tolist} [, {options}]) *diff()* |
| 2230 | Returns a String or a List containing the diff between the |
| 2231 | strings in {fromlist} and {tolist}. Uses the Vim internal |
| 2232 | diff library to compute the diff. |
| 2233 | |
| 2234 | *E106* |
| 2235 | The optional "output" item in {options} specifies the returned |
| 2236 | diff format. The following values are supported: |
| 2237 | indices Return a List of the starting and ending |
| 2238 | indices and a count of the strings in each |
| 2239 | diff hunk. |
| 2240 | unified Return the unified diff output as a String. |
| 2241 | This is the default. |
| 2242 | |
| 2243 | If the "output" item in {options} is "indices", then a List is |
| 2244 | returned. Each List item contains a Dict with the following |
| 2245 | items for each diff hunk: |
| 2246 | from_idx start index in {fromlist} for this diff hunk. |
| 2247 | from_count number of strings in {fromlist} that are |
| 2248 | added/removed/modified in this diff hunk. |
| 2249 | to_idx start index in {tolist} for this diff hunk. |
| 2250 | to_count number of strings in {tolist} that are |
| 2251 | added/removed/modified in this diff hunk. |
| 2252 | |
| 2253 | The {options} Dict argument also specifies diff options |
| 2254 | (similar to 'diffopt') and supports the following items: |
Yegappan Lakshmanan | be156a3 | 2024-02-11 17:08:29 +0100 | [diff] [blame] | 2255 | algorithm Dict specifying the diff algorithm to |
| 2256 | use. Supported boolean items are |
| 2257 | "myers", "minimal", "patience" and |
| 2258 | "histogram". |
Yegappan Lakshmanan | a0010a1 | 2024-02-12 20:21:26 +0100 | [diff] [blame] | 2259 | context diff context length. Default is 0. |
Yegappan Lakshmanan | fa37835 | 2024-02-01 22:05:27 +0100 | [diff] [blame] | 2260 | iblank ignore changes where lines are all |
| 2261 | blank. |
| 2262 | icase ignore changes in case of text. |
Yegappan Lakshmanan | be156a3 | 2024-02-11 17:08:29 +0100 | [diff] [blame] | 2263 | indent-heuristic use the indent heuristic for the |
| 2264 | internal diff library. |
Yegappan Lakshmanan | fa37835 | 2024-02-01 22:05:27 +0100 | [diff] [blame] | 2265 | iwhite ignore changes in amount of white |
| 2266 | space. |
| 2267 | iwhiteall ignore all white space changes. |
| 2268 | iwhiteeol ignore white space changes at end of |
| 2269 | line. |
Yegappan Lakshmanan | fa37835 | 2024-02-01 22:05:27 +0100 | [diff] [blame] | 2270 | For more information about these options, refer to 'diffopt'. |
| 2271 | |
Yegappan Lakshmanan | a0010a1 | 2024-02-12 20:21:26 +0100 | [diff] [blame] | 2272 | To compute the unified diff, all the items in {fromlist} are |
| 2273 | concatenated into a string using a newline separator and the |
| 2274 | same for {tolist}. The unified diff output uses line numbers. |
| 2275 | |
Yegappan Lakshmanan | fa37835 | 2024-02-01 22:05:27 +0100 | [diff] [blame] | 2276 | Returns an empty List or String if {fromlist} and {tolist} are |
| 2277 | identical. |
| 2278 | |
Yegappan Lakshmanan | 1af3563 | 2024-02-06 11:03:36 +0100 | [diff] [blame] | 2279 | Examples: > |
Yegappan Lakshmanan | fa37835 | 2024-02-01 22:05:27 +0100 | [diff] [blame] | 2280 | :echo diff(['abc'], ['xxx']) |
| 2281 | @@ -1 +1 @@ |
| 2282 | -abc |
| 2283 | +xxx |
| 2284 | |
| 2285 | :echo diff(['abc'], ['xxx'], {'output': 'indices'}) |
| 2286 | [{'from_idx': 0, 'from_count': 1, 'to_idx': 0, 'to_count': 1}] |
| 2287 | :echo diff(readfile('oldfile'), readfile('newfile')) |
| 2288 | :echo diff(getbufline(5, 1, '$'), getbufline(6, 1, '$')) |
Yegappan Lakshmanan | 1af3563 | 2024-02-06 11:03:36 +0100 | [diff] [blame] | 2289 | < |
Yegappan Lakshmanan | fa37835 | 2024-02-01 22:05:27 +0100 | [diff] [blame] | 2290 | For more examples, refer to |diff-func-examples| |
| 2291 | |
| 2292 | Can also be used as a |method|: > |
| 2293 | GetFromList->diff(to_list) |
| 2294 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 2295 | Return type: |String| or list<dict<number>> or list<any> |
| 2296 | depending on {options} |
| 2297 | |
| 2298 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2299 | diff_filler({lnum}) *diff_filler()* |
| 2300 | Returns the number of filler lines above line {lnum}. |
| 2301 | These are the lines that were inserted at this point in |
| 2302 | another diff'ed window. These filler lines are shown in the |
| 2303 | display but don't exist in the buffer. |
| 2304 | {lnum} is used like with |getline()|. Thus "." is the current |
| 2305 | line, "'m" mark m, etc. |
| 2306 | Returns 0 if the current window is not in diff mode. |
| 2307 | |
| 2308 | Can also be used as a |method|: > |
| 2309 | GetLnum()->diff_filler() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 2310 | < |
| 2311 | Return type: |Number| |
| 2312 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2313 | |
| 2314 | diff_hlID({lnum}, {col}) *diff_hlID()* |
| 2315 | Returns the highlight ID for diff mode at line {lnum} column |
| 2316 | {col} (byte index). When the current line does not have a |
| 2317 | diff change zero is returned. |
| 2318 | {lnum} is used like with |getline()|. Thus "." is the current |
| 2319 | line, "'m" mark m, etc. |
| 2320 | {col} is 1 for the leftmost column, {lnum} is 1 for the first |
| 2321 | line. |
| 2322 | The highlight ID can be used with |synIDattr()| to obtain |
| 2323 | syntax information about the highlighting. |
| 2324 | |
| 2325 | Can also be used as a |method|: > |
| 2326 | GetLnum()->diff_hlID(col) |
| 2327 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 2328 | Return type: |Number| |
| 2329 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2330 | |
| 2331 | digraph_get({chars}) *digraph_get()* *E1214* |
| 2332 | Return the digraph of {chars}. This should be a string with |
| 2333 | exactly two characters. If {chars} are not just two |
| 2334 | characters, or the digraph of {chars} does not exist, an error |
| 2335 | is given and an empty string is returned. |
| 2336 | |
| 2337 | The character will be converted from Unicode to 'encoding' |
| 2338 | when needed. This does require the conversion to be |
| 2339 | available, it might fail. |
| 2340 | |
| 2341 | Also see |digraph_getlist()|. |
| 2342 | |
| 2343 | Examples: > |
| 2344 | " Get a built-in digraph |
| 2345 | :echo digraph_get('00') " Returns '∞' |
| 2346 | |
| 2347 | " Get a user-defined digraph |
| 2348 | :call digraph_set('aa', 'あ') |
| 2349 | :echo digraph_get('aa') " Returns 'あ' |
| 2350 | < |
| 2351 | Can also be used as a |method|: > |
| 2352 | GetChars()->digraph_get() |
| 2353 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 2354 | Return type: |String| |
| 2355 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2356 | This function works only when compiled with the |+digraphs| |
| 2357 | feature. If this feature is disabled, this function will |
| 2358 | display an error message. |
| 2359 | |
| 2360 | |
| 2361 | digraph_getlist([{listall}]) *digraph_getlist()* |
| 2362 | Return a list of digraphs. If the {listall} argument is given |
| 2363 | and it is TRUE, return all digraphs, including the default |
| 2364 | digraphs. Otherwise, return only user-defined digraphs. |
| 2365 | |
| 2366 | The characters will be converted from Unicode to 'encoding' |
| 2367 | when needed. This does require the conservation to be |
| 2368 | available, it might fail. |
| 2369 | |
| 2370 | Also see |digraph_get()|. |
| 2371 | |
| 2372 | Examples: > |
| 2373 | " Get user-defined digraphs |
| 2374 | :echo digraph_getlist() |
| 2375 | |
| 2376 | " Get all the digraphs, including default digraphs |
| 2377 | :echo digraph_getlist(1) |
| 2378 | < |
| 2379 | Can also be used as a |method|: > |
| 2380 | GetNumber()->digraph_getlist() |
| 2381 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 2382 | Return type: list<list<string>> |
| 2383 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2384 | This function works only when compiled with the |+digraphs| |
| 2385 | feature. If this feature is disabled, this function will |
| 2386 | display an error message. |
| 2387 | |
| 2388 | |
Bram Moolenaar | a2baa73 | 2022-02-04 16:09:54 +0000 | [diff] [blame] | 2389 | digraph_set({chars}, {digraph}) *digraph_set()* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2390 | Add digraph {chars} to the list. {chars} must be a string |
| 2391 | with two characters. {digraph} is a string with one UTF-8 |
Bram Moolenaar | a2baa73 | 2022-02-04 16:09:54 +0000 | [diff] [blame] | 2392 | encoded character. *E1215* |
| 2393 | Be careful, composing characters are NOT ignored. This |
| 2394 | function is similar to |:digraphs| command, but useful to add |
| 2395 | digraphs start with a white space. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2396 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 2397 | The function returns v:true if |digraph| is registered. If |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2398 | this fails an error message is given and v:false is returned. |
| 2399 | |
| 2400 | If you want to define multiple digraphs at once, you can use |
| 2401 | |digraph_setlist()|. |
| 2402 | |
| 2403 | Example: > |
| 2404 | call digraph_set(' ', 'あ') |
| 2405 | < |
| 2406 | Can be used as a |method|: > |
| 2407 | GetString()->digraph_set('あ') |
| 2408 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 2409 | Return type: |vim9-boolean| |
| 2410 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2411 | This function works only when compiled with the |+digraphs| |
| 2412 | feature. If this feature is disabled, this function will |
| 2413 | display an error message. |
| 2414 | |
| 2415 | |
| 2416 | digraph_setlist({digraphlist}) *digraph_setlist()* |
| 2417 | Similar to |digraph_set()| but this function can add multiple |
| 2418 | digraphs at once. {digraphlist} is a list composed of lists, |
| 2419 | where each list contains two strings with {chars} and |
Bram Moolenaar | a2baa73 | 2022-02-04 16:09:54 +0000 | [diff] [blame] | 2420 | {digraph} as in |digraph_set()|. *E1216* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2421 | Example: > |
| 2422 | call digraph_setlist([['aa', 'あ'], ['ii', 'い']]) |
| 2423 | < |
| 2424 | It is similar to the following: > |
| 2425 | for [chars, digraph] in [['aa', 'あ'], ['ii', 'い']] |
| 2426 | call digraph_set(chars, digraph) |
| 2427 | endfor |
| 2428 | < Except that the function returns after the first error, |
| 2429 | following digraphs will not be added. |
| 2430 | |
| 2431 | Can be used as a |method|: > |
| 2432 | GetList()->digraph_setlist() |
| 2433 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 2434 | Return type: |vim9-boolean| |
| 2435 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2436 | This function works only when compiled with the |+digraphs| |
| 2437 | feature. If this feature is disabled, this function will |
| 2438 | display an error message. |
| 2439 | |
| 2440 | |
| 2441 | echoraw({string}) *echoraw()* |
| 2442 | Output {string} as-is, including unprintable characters. |
| 2443 | This can be used to output a terminal code. For example, to |
| 2444 | disable modifyOtherKeys: > |
| 2445 | call echoraw(&t_TE) |
| 2446 | < and to enable it again: > |
| 2447 | call echoraw(&t_TI) |
| 2448 | < Use with care, you can mess up the terminal this way. |
| 2449 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 2450 | Return type: |Number| |
| 2451 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2452 | |
| 2453 | empty({expr}) *empty()* |
| 2454 | Return the Number 1 if {expr} is empty, zero otherwise. |
| 2455 | - A |List| or |Dictionary| is empty when it does not have any |
| 2456 | items. |
| 2457 | - A |String| is empty when its length is zero. |
| 2458 | - A |Number| and |Float| are empty when their value is zero. |
| 2459 | - |v:false|, |v:none| and |v:null| are empty, |v:true| is not. |
| 2460 | - A |Job| is empty when it failed to start. |
| 2461 | - A |Channel| is empty when it is closed. |
| 2462 | - A |Blob| is empty when its length is zero. |
mityu | 7f0bba2 | 2024-03-29 10:14:41 +0100 | [diff] [blame] | 2463 | - An |Object| is empty, when the empty() method in the object |
| 2464 | (if present) returns true. |object-empty()| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2465 | |
| 2466 | For a long |List| this is much faster than comparing the |
| 2467 | length with zero. |
| 2468 | |
| 2469 | Can also be used as a |method|: > |
| 2470 | mylist->empty() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 2471 | < |
| 2472 | Return type: |Number| |
| 2473 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2474 | |
| 2475 | environ() *environ()* |
| 2476 | Return all of environment variables as dictionary. You can |
| 2477 | check if an environment variable exists like this: > |
| 2478 | :echo has_key(environ(), 'HOME') |
| 2479 | < Note that the variable name may be CamelCase; to ignore case |
| 2480 | use this: > |
| 2481 | :echo index(keys(environ()), 'HOME', 0, 1) != -1 |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 2482 | < |
| 2483 | Return type: dict<string> |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2484 | |
Bram Moolenaar | 416bd91 | 2023-07-07 23:19:18 +0100 | [diff] [blame] | 2485 | |
| 2486 | err_teapot([{expr}]) *err_teapot()* |
| 2487 | Produce an error with number 418, needed for implementation of |
Christian Brabandt | ee17b6f | 2023-09-09 11:23:50 +0200 | [diff] [blame] | 2488 | RFC 2324. |
Bram Moolenaar | 416bd91 | 2023-07-07 23:19:18 +0100 | [diff] [blame] | 2489 | If {expr} is present and it is TRUE error 503 is given, |
| 2490 | indicating that coffee is temporarily not available. |
| 2491 | If {expr} is present it must be a String. |
| 2492 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 2493 | Return type: |Number| |
| 2494 | |
Bram Moolenaar | 416bd91 | 2023-07-07 23:19:18 +0100 | [diff] [blame] | 2495 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2496 | escape({string}, {chars}) *escape()* |
| 2497 | Escape the characters in {chars} that occur in {string} with a |
| 2498 | backslash. Example: > |
| 2499 | :echo escape('c:\program files\vim', ' \') |
| 2500 | < results in: > |
| 2501 | c:\\program\ files\\vim |
| 2502 | < Also see |shellescape()| and |fnameescape()|. |
| 2503 | |
| 2504 | Can also be used as a |method|: > |
| 2505 | GetText()->escape(' \') |
| 2506 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 2507 | Return type: |String| |
| 2508 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2509 | *eval()* |
| 2510 | eval({string}) Evaluate {string} and return the result. Especially useful to |
| 2511 | turn the result of |string()| back into the original value. |
| 2512 | This works for Numbers, Floats, Strings, Blobs and composites |
| 2513 | of them. Also works for |Funcref|s that refer to existing |
Aliaksei Budavei | 9574022 | 2024-04-04 23:05:33 +0300 | [diff] [blame] | 2514 | functions. In |Vim9| script, it can be used to obtain |enum| |
| 2515 | values from their fully qualified names. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2516 | |
| 2517 | Can also be used as a |method|: > |
| 2518 | argv->join()->eval() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 2519 | < |
| 2520 | Return type: any, depending on {string} |
| 2521 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2522 | |
| 2523 | eventhandler() *eventhandler()* |
| 2524 | Returns 1 when inside an event handler. That is that Vim got |
| 2525 | interrupted while waiting for the user to type a character, |
| 2526 | e.g., when dropping a file on Vim. This means interactive |
| 2527 | commands cannot be used. Otherwise zero is returned. |
| 2528 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 2529 | Return type: |Number| |
| 2530 | |
| 2531 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2532 | executable({expr}) *executable()* |
| 2533 | This function checks if an executable with the name {expr} |
| 2534 | exists. {expr} must be the name of the program without any |
| 2535 | arguments. |
| 2536 | executable() uses the value of $PATH and/or the normal |
| 2537 | searchpath for programs. *PATHEXT* |
| 2538 | On MS-Windows the ".exe", ".bat", etc. can optionally be |
| 2539 | included. Then the extensions in $PATHEXT are tried. Thus if |
| 2540 | "foo.exe" does not exist, "foo.exe.bat" can be found. If |
| 2541 | $PATHEXT is not set then ".com;.exe;.bat;.cmd" is used. A dot |
| 2542 | by itself can be used in $PATHEXT to try using the name |
| 2543 | without an extension. When 'shell' looks like a Unix shell, |
| 2544 | then the name is also tried without adding an extension. |
| 2545 | On MS-Windows it only checks if the file exists and is not a |
| 2546 | directory, not if it's really executable. |
| 2547 | On MS-Windows an executable in the same directory as Vim is |
Yasuhiro Matsumoto | 05cf63e | 2022-05-03 11:02:28 +0100 | [diff] [blame] | 2548 | normally found. Since this directory is added to $PATH it |
| 2549 | should also work to execute it |win32-PATH|. This can be |
| 2550 | disabled by setting the $NoDefaultCurrentDirectoryInExePath |
| 2551 | environment variable. *NoDefaultCurrentDirectoryInExePath* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2552 | The result is a Number: |
| 2553 | 1 exists |
| 2554 | 0 does not exist |
| 2555 | -1 not implemented on this system |
| 2556 | |exepath()| can be used to get the full path of an executable. |
| 2557 | |
| 2558 | Can also be used as a |method|: > |
| 2559 | GetCommand()->executable() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 2560 | < |
| 2561 | Return type: |Number| |
| 2562 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2563 | |
| 2564 | execute({command} [, {silent}]) *execute()* |
| 2565 | Execute an Ex command or commands and return the output as a |
| 2566 | string. |
| 2567 | {command} can be a string or a List. In case of a List the |
| 2568 | lines are executed one by one. |
Bram Moolenaar | b7398fe | 2023-05-14 18:50:25 +0100 | [diff] [blame] | 2569 | This is more or less equivalent to: > |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2570 | redir => var |
| 2571 | {command} |
| 2572 | redir END |
Bram Moolenaar | 71badf9 | 2023-04-22 22:40:14 +0100 | [diff] [blame] | 2573 | < Except that line continuation in {command} is not recognized. |
| 2574 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2575 | The optional {silent} argument can have these values: |
| 2576 | "" no `:silent` used |
| 2577 | "silent" `:silent` used |
| 2578 | "silent!" `:silent!` used |
| 2579 | The default is "silent". Note that with "silent!", unlike |
| 2580 | `:redir`, error messages are dropped. When using an external |
| 2581 | command the screen may be messed up, use `system()` instead. |
| 2582 | *E930* |
| 2583 | It is not possible to use `:redir` anywhere in {command}. |
| 2584 | |
Bram Moolenaar | b7398fe | 2023-05-14 18:50:25 +0100 | [diff] [blame] | 2585 | To get a list of lines use `split()` on the result: > |
Bram Moolenaar | 75ab590 | 2022-04-18 15:36:40 +0100 | [diff] [blame] | 2586 | execute('args')->split("\n") |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2587 | |
| 2588 | < To execute a command in another window than the current one |
| 2589 | use `win_execute()`. |
| 2590 | |
| 2591 | When used recursively the output of the recursive call is not |
| 2592 | included in the output of the higher level call. |
| 2593 | |
| 2594 | Can also be used as a |method|: > |
| 2595 | GetCommand()->execute() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 2596 | < |
Marius Gedminas | c98bfb9 | 2024-06-19 19:59:23 +0200 | [diff] [blame] | 2597 | Return type: |String| |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 2598 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2599 | |
| 2600 | exepath({expr}) *exepath()* |
| 2601 | If {expr} is an executable and is either an absolute path, a |
| 2602 | relative path or found in $PATH, return the full path. |
| 2603 | Note that the current directory is used when {expr} starts |
| 2604 | with "./", which may be a problem for Vim: > |
| 2605 | echo exepath(v:progpath) |
| 2606 | < If {expr} cannot be found in $PATH or is not executable then |
| 2607 | an empty string is returned. |
| 2608 | |
| 2609 | Can also be used as a |method|: > |
| 2610 | GetCommand()->exepath() |
| 2611 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 2612 | Return type: |String| |
| 2613 | |
| 2614 | |
| 2615 | exists({expr}) *exists()* |
| 2616 | The result is a Number, which is |TRUE| if {expr} is defined, |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2617 | zero otherwise. |
| 2618 | |
| 2619 | Note: In a compiled |:def| function the evaluation is done at |
| 2620 | runtime. Use `exists_compiled()` to evaluate the expression |
| 2621 | at compile time. |
| 2622 | |
| 2623 | For checking for a supported feature use |has()|. |
| 2624 | For checking if a file exists use |filereadable()|. |
| 2625 | |
| 2626 | The {expr} argument is a string, which contains one of these: |
Bram Moolenaar | f10911e | 2022-01-29 22:20:48 +0000 | [diff] [blame] | 2627 | varname internal variable (see |
| 2628 | dict.key |internal-variables|). Also works |
| 2629 | list[i] for |curly-braces-names|, |Dictionary| |
Yegappan Lakshmanan | a2ebb6e | 2024-02-25 08:40:10 +0100 | [diff] [blame] | 2630 | import.Func entries, |List| items, class and |
| 2631 | class.Func object methods, imported items, etc. |
| 2632 | object.Func Does not work for local variables in a |
| 2633 | class.varname compiled `:def` function. |
| 2634 | object.varname Also works for a function in |Vim9| |
Bram Moolenaar | 944697a | 2022-02-20 19:48:20 +0000 | [diff] [blame] | 2635 | script, since it can be used as a |
| 2636 | function reference. |
Bram Moolenaar | f10911e | 2022-01-29 22:20:48 +0000 | [diff] [blame] | 2637 | Beware that evaluating an index may |
| 2638 | cause an error message for an invalid |
| 2639 | expression. E.g.: > |
| 2640 | :let l = [1, 2, 3] |
| 2641 | :echo exists("l[5]") |
| 2642 | < 0 > |
| 2643 | :echo exists("l[xx]") |
| 2644 | < E121: Undefined variable: xx |
| 2645 | 0 |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2646 | &option-name Vim option (only checks if it exists, |
| 2647 | not if it really works) |
| 2648 | +option-name Vim option that works. |
| 2649 | $ENVNAME environment variable (could also be |
| 2650 | done by comparing with an empty |
| 2651 | string) |
| 2652 | *funcname built-in function (see |functions|) |
| 2653 | or user defined function (see |
| 2654 | |user-functions|) that is implemented. |
| 2655 | Also works for a variable that is a |
| 2656 | Funcref. |
| 2657 | ?funcname built-in function that could be |
| 2658 | implemented; to be used to check if |
| 2659 | "funcname" is valid |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2660 | :cmdname Ex command: built-in command, user |
| 2661 | command or command modifier |:command|. |
| 2662 | Returns: |
| 2663 | 1 for match with start of a command |
| 2664 | 2 full match with a command |
| 2665 | 3 matches several user commands |
| 2666 | To check for a supported command |
| 2667 | always check the return value to be 2. |
| 2668 | :2match The |:2match| command. |
Bram Moolenaar | b529cfb | 2022-07-25 15:42:07 +0100 | [diff] [blame] | 2669 | :3match The |:3match| command (but you |
| 2670 | probably should not use it, it is |
| 2671 | reserved for internal usage) |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2672 | #event autocommand defined for this event |
| 2673 | #event#pattern autocommand defined for this event and |
| 2674 | pattern (the pattern is taken |
| 2675 | literally and compared to the |
| 2676 | autocommand patterns character by |
| 2677 | character) |
| 2678 | #group autocommand group exists |
| 2679 | #group#event autocommand defined for this group and |
| 2680 | event. |
| 2681 | #group#event#pattern |
| 2682 | autocommand defined for this group, |
| 2683 | event and pattern. |
| 2684 | ##event autocommand for this event is |
| 2685 | supported. |
| 2686 | |
| 2687 | Examples: > |
| 2688 | exists("&shortname") |
| 2689 | exists("$HOSTNAME") |
| 2690 | exists("*strftime") |
Bram Moolenaar | 944697a | 2022-02-20 19:48:20 +0000 | [diff] [blame] | 2691 | exists("*s:MyFunc") " only for legacy script |
| 2692 | exists("*MyFunc") |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2693 | exists("bufcount") |
| 2694 | exists(":Make") |
| 2695 | exists("#CursorHold") |
| 2696 | exists("#BufReadPre#*.gz") |
| 2697 | exists("#filetypeindent") |
| 2698 | exists("#filetypeindent#FileType") |
| 2699 | exists("#filetypeindent#FileType#*") |
| 2700 | exists("##ColorScheme") |
| 2701 | < There must be no space between the symbol (&/$/*/#) and the |
| 2702 | name. |
| 2703 | There must be no extra characters after the name, although in |
Bram Moolenaar | 2d8ed02 | 2022-05-21 13:08:16 +0100 | [diff] [blame] | 2704 | a few cases this is ignored. That may become stricter in the |
| 2705 | future, thus don't count on it! |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2706 | Working example: > |
| 2707 | exists(":make") |
| 2708 | < NOT working example: > |
| 2709 | exists(":make install") |
| 2710 | |
| 2711 | < Note that the argument must be a string, not the name of the |
| 2712 | variable itself. For example: > |
| 2713 | exists(bufcount) |
| 2714 | < This doesn't check for existence of the "bufcount" variable, |
| 2715 | but gets the value of "bufcount", and checks if that exists. |
| 2716 | |
| 2717 | Can also be used as a |method|: > |
| 2718 | Varname()->exists() |
| 2719 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 2720 | Return type: |String| |
| 2721 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2722 | |
| 2723 | exists_compiled({expr}) *exists_compiled()* |
| 2724 | Like `exists()` but evaluated at compile time. This is useful |
| 2725 | to skip a block where a function is used that would otherwise |
| 2726 | give an error: > |
| 2727 | if exists_compiled('*ThatFunction') |
| 2728 | ThatFunction('works') |
| 2729 | endif |
| 2730 | < If `exists()` were used then a compilation error would be |
| 2731 | given if ThatFunction() is not defined. |
| 2732 | |
| 2733 | {expr} must be a literal string. *E1232* |
| 2734 | Can only be used in a |:def| function. *E1233* |
| 2735 | This does not work to check for arguments or local variables. |
| 2736 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 2737 | Return type: |String| |
| 2738 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2739 | |
| 2740 | exp({expr}) *exp()* |
| 2741 | Return the exponential of {expr} as a |Float| in the range |
| 2742 | [0, inf]. |
| 2743 | {expr} must evaluate to a |Float| or a |Number|. |
Bram Moolenaar | 016188f | 2022-06-06 20:52:59 +0100 | [diff] [blame] | 2744 | Returns 0.0 if {expr} is not a |Float| or a |Number|. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2745 | Examples: > |
| 2746 | :echo exp(2) |
| 2747 | < 7.389056 > |
| 2748 | :echo exp(-1) |
| 2749 | < 0.367879 |
| 2750 | |
| 2751 | Can also be used as a |method|: > |
| 2752 | Compute()->exp() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 2753 | < |
| 2754 | Return type: |Float| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2755 | |
| 2756 | |
| 2757 | expand({string} [, {nosuf} [, {list}]]) *expand()* |
| 2758 | Expand wildcards and the following special keywords in |
| 2759 | {string}. 'wildignorecase' applies. |
| 2760 | |
| 2761 | If {list} is given and it is |TRUE|, a List will be returned. |
| 2762 | Otherwise the result is a String and when there are several |
| 2763 | matches, they are separated by <NL> characters. [Note: in |
| 2764 | version 5.0 a space was used, which caused problems when a |
| 2765 | file name contains a space] |
| 2766 | |
| 2767 | If the expansion fails, the result is an empty string. A name |
| 2768 | for a non-existing file is not included, unless {string} does |
| 2769 | not start with '%', '#' or '<', see below. |
| 2770 | |
Christian Brabandt | ec9c326 | 2024-02-21 20:40:05 +0100 | [diff] [blame] | 2771 | For a |:terminal| window '%' expands to a '!' followed by |
h-east | 53753f6 | 2024-05-05 18:42:31 +0200 | [diff] [blame] | 2772 | the command or shell that is run. |terminal-bufname| |
Christian Brabandt | ec9c326 | 2024-02-21 20:40:05 +0100 | [diff] [blame] | 2773 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2774 | When {string} starts with '%', '#' or '<', the expansion is |
| 2775 | done like for the |cmdline-special| variables with their |
| 2776 | associated modifiers. Here is a short overview: |
| 2777 | |
| 2778 | % current file name |
| 2779 | # alternate file name |
| 2780 | #n alternate file name n |
| 2781 | <cfile> file name under the cursor |
| 2782 | <afile> autocmd file name |
| 2783 | <abuf> autocmd buffer number (as a String!) |
| 2784 | <amatch> autocmd matched name |
| 2785 | <cexpr> C expression under the cursor |
| 2786 | <sfile> sourced script file or function name |
| 2787 | <slnum> sourced script line number or function |
| 2788 | line number |
| 2789 | <sflnum> script file line number, also when in |
| 2790 | a function |
| 2791 | <SID> "<SNR>123_" where "123" is the |
| 2792 | current script ID |<SID>| |
Bram Moolenaar | 75ab590 | 2022-04-18 15:36:40 +0100 | [diff] [blame] | 2793 | <script> sourced script file, or script file |
| 2794 | where the current function was defined |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2795 | <stack> call stack |
| 2796 | <cword> word under the cursor |
| 2797 | <cWORD> WORD under the cursor |
| 2798 | <client> the {clientid} of the last received |
| 2799 | message |server2client()| |
| 2800 | Modifiers: |
| 2801 | :p expand to full path |
| 2802 | :h head (last path component removed) |
| 2803 | :t tail (last path component only) |
| 2804 | :r root (one extension removed) |
| 2805 | :e extension only |
| 2806 | |
| 2807 | Example: > |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 2808 | :let &tags = expand("%:p:h") .. "/tags" |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2809 | < Note that when expanding a string that starts with '%', '#' or |
| 2810 | '<', any following text is ignored. This does NOT work: > |
| 2811 | :let doesntwork = expand("%:h.bak") |
| 2812 | < Use this: > |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 2813 | :let doeswork = expand("%:h") .. ".bak" |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2814 | < Also note that expanding "<cfile>" and others only returns the |
| 2815 | referenced file name without further expansion. If "<cfile>" |
| 2816 | is "~/.cshrc", you need to do another expand() to have the |
| 2817 | "~/" expanded into the path of the home directory: > |
| 2818 | :echo expand(expand("<cfile>")) |
| 2819 | < |
| 2820 | There cannot be white space between the variables and the |
| 2821 | following modifier. The |fnamemodify()| function can be used |
| 2822 | to modify normal file names. |
| 2823 | |
| 2824 | When using '%' or '#', and the current or alternate file name |
| 2825 | is not defined, an empty string is used. Using "%:p" in a |
| 2826 | buffer with no name, results in the current directory, with a |
| 2827 | '/' added. |
Bram Moolenaar | 5754452 | 2022-04-12 12:54:11 +0100 | [diff] [blame] | 2828 | When 'verbose' is set then expanding '%', '#' and <> items |
| 2829 | will result in an error message if the argument cannot be |
| 2830 | expanded. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2831 | |
| 2832 | When {string} does not start with '%', '#' or '<', it is |
| 2833 | expanded like a file name is expanded on the command line. |
| 2834 | 'suffixes' and 'wildignore' are used, unless the optional |
| 2835 | {nosuf} argument is given and it is |TRUE|. |
| 2836 | Names for non-existing files are included. The "**" item can |
| 2837 | be used to search in a directory tree. For example, to find |
| 2838 | all "README" files in the current directory and below: > |
| 2839 | :echo expand("**/README") |
| 2840 | < |
| 2841 | expand() can also be used to expand variables and environment |
| 2842 | variables that are only known in a shell. But this can be |
| 2843 | slow, because a shell may be used to do the expansion. See |
| 2844 | |expr-env-expand|. |
| 2845 | The expanded variable is still handled like a list of file |
| 2846 | names. When an environment variable cannot be expanded, it is |
| 2847 | left unchanged. Thus ":echo expand('$FOOBAR')" results in |
| 2848 | "$FOOBAR". |
| 2849 | |
| 2850 | See |glob()| for finding existing files. See |system()| for |
| 2851 | getting the raw output of an external command. |
| 2852 | |
| 2853 | Can also be used as a |method|: > |
| 2854 | Getpattern()->expand() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 2855 | < |
| 2856 | Return type: |String| or list<string> depending on {list} |
| 2857 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2858 | |
Yegappan Lakshmanan | 2b74b68 | 2022-04-03 21:30:32 +0100 | [diff] [blame] | 2859 | expandcmd({string} [, {options}]) *expandcmd()* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2860 | Expand special items in String {string} like what is done for |
| 2861 | an Ex command such as `:edit`. This expands special keywords, |
| 2862 | like with |expand()|, and environment variables, anywhere in |
| 2863 | {string}. "~user" and "~/path" are only expanded at the |
| 2864 | start. |
Yegappan Lakshmanan | 2b74b68 | 2022-04-03 21:30:32 +0100 | [diff] [blame] | 2865 | |
| 2866 | The following items are supported in the {options} Dict |
| 2867 | argument: |
| 2868 | errmsg If set to TRUE, error messages are displayed |
| 2869 | if an error is encountered during expansion. |
| 2870 | By default, error messages are not displayed. |
| 2871 | |
Yegappan Lakshmanan | 5018a83 | 2022-04-02 21:12:21 +0100 | [diff] [blame] | 2872 | Returns the expanded string. If an error is encountered |
| 2873 | during expansion, the unmodified {string} is returned. |
Yegappan Lakshmanan | 2b74b68 | 2022-04-03 21:30:32 +0100 | [diff] [blame] | 2874 | |
Yegappan Lakshmanan | 5018a83 | 2022-04-02 21:12:21 +0100 | [diff] [blame] | 2875 | Example: > |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2876 | :echo expandcmd('make %<.o') |
Yegappan Lakshmanan | 2b74b68 | 2022-04-03 21:30:32 +0100 | [diff] [blame] | 2877 | make /path/runtime/doc/builtin.o |
| 2878 | :echo expandcmd('make %<.o', {'errmsg': v:true}) |
| 2879 | < |
Yegappan Lakshmanan | 5018a83 | 2022-04-02 21:12:21 +0100 | [diff] [blame] | 2880 | Can also be used as a |method|: > |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2881 | GetCommand()->expandcmd() |
| 2882 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 2883 | Return type: |String| or list<string> depending on {list} |
| 2884 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2885 | extend({expr1}, {expr2} [, {expr3}]) *extend()* |
| 2886 | {expr1} and {expr2} must be both |Lists| or both |
| 2887 | |Dictionaries|. |
| 2888 | |
| 2889 | If they are |Lists|: Append {expr2} to {expr1}. |
| 2890 | If {expr3} is given insert the items of {expr2} before the |
| 2891 | item with index {expr3} in {expr1}. When {expr3} is zero |
| 2892 | insert before the first item. When {expr3} is equal to |
| 2893 | len({expr1}) then {expr2} is appended. |
| 2894 | Examples: > |
| 2895 | :echo sort(extend(mylist, [7, 5])) |
| 2896 | :call extend(mylist, [2, 3], 1) |
| 2897 | < When {expr1} is the same List as {expr2} then the number of |
| 2898 | items copied is equal to the original length of the List. |
| 2899 | E.g., when {expr3} is 1 you get N new copies of the first item |
| 2900 | (where N is the original length of the List). |
| 2901 | Use |add()| to concatenate one item to a list. To concatenate |
| 2902 | two lists into a new list use the + operator: > |
| 2903 | :let newlist = [1, 2, 3] + [4, 5] |
| 2904 | < |
| 2905 | If they are |Dictionaries|: |
| 2906 | Add all entries from {expr2} to {expr1}. |
| 2907 | If a key exists in both {expr1} and {expr2} then {expr3} is |
| 2908 | used to decide what to do: |
| 2909 | {expr3} = "keep": keep the value of {expr1} |
| 2910 | {expr3} = "force": use the value of {expr2} |
| 2911 | {expr3} = "error": give an error message *E737* |
| 2912 | When {expr3} is omitted then "force" is assumed. |
| 2913 | |
| 2914 | {expr1} is changed when {expr2} is not empty. If necessary |
| 2915 | make a copy of {expr1} first. |
| 2916 | {expr2} remains unchanged. |
| 2917 | When {expr1} is locked and {expr2} is not empty the operation |
| 2918 | fails. |
Bram Moolenaar | 016188f | 2022-06-06 20:52:59 +0100 | [diff] [blame] | 2919 | Returns {expr1}. Returns 0 on error. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2920 | |
| 2921 | Can also be used as a |method|: > |
| 2922 | mylist->extend(otherlist) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 2923 | < |
| 2924 | Return type: list<{type}> or dict<{type}> depending on {expr1} |
| 2925 | and {expr2}, in case of error: |Number| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2926 | |
| 2927 | |
| 2928 | extendnew({expr1}, {expr2} [, {expr3}]) *extendnew()* |
| 2929 | Like |extend()| but instead of adding items to {expr1} a new |
| 2930 | List or Dictionary is created and returned. {expr1} remains |
Bram Moolenaar | dd60c36 | 2023-02-27 15:49:53 +0000 | [diff] [blame] | 2931 | unchanged. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2932 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 2933 | Return type: list<{type}> or dict<{type}> depending on {expr1} |
| 2934 | and {expr2}, in case of error: |Number| |
| 2935 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2936 | |
| 2937 | feedkeys({string} [, {mode}]) *feedkeys()* |
| 2938 | Characters in {string} are queued for processing as if they |
| 2939 | come from a mapping or were typed by the user. |
| 2940 | |
| 2941 | By default the string is added to the end of the typeahead |
| 2942 | buffer, thus if a mapping is still being executed the |
| 2943 | characters come after them. Use the 'i' flag to insert before |
| 2944 | other characters, they will be executed next, before any |
| 2945 | characters from a mapping. |
| 2946 | |
| 2947 | The function does not wait for processing of keys contained in |
| 2948 | {string}. |
| 2949 | |
| 2950 | To include special keys into {string}, use double-quotes |
| 2951 | and "\..." notation |expr-quote|. For example, |
| 2952 | feedkeys("\<CR>") simulates pressing of the <Enter> key. But |
| 2953 | feedkeys('\<CR>') pushes 5 characters. |
| 2954 | A special code that might be useful is <Ignore>, it exits the |
| 2955 | wait for a character without doing anything. *<Ignore>* |
| 2956 | |
| 2957 | {mode} is a String, which can contain these character flags: |
| 2958 | 'm' Remap keys. This is default. If {mode} is absent, |
| 2959 | keys are remapped. |
| 2960 | 'n' Do not remap keys. |
| 2961 | 't' Handle keys as if typed; otherwise they are handled as |
| 2962 | if coming from a mapping. This matters for undo, |
| 2963 | opening folds, etc. |
| 2964 | 'L' Lowlevel input. Only works for Unix or when using the |
| 2965 | GUI. Keys are used as if they were coming from the |
| 2966 | terminal. Other flags are not used. *E980* |
| 2967 | When a CTRL-C interrupts and 't' is included it sets |
| 2968 | the internal "got_int" flag. |
| 2969 | 'i' Insert the string instead of appending (see above). |
| 2970 | 'x' Execute commands until typeahead is empty. This is |
| 2971 | similar to using ":normal!". You can call feedkeys() |
| 2972 | several times without 'x' and then one time with 'x' |
| 2973 | (possibly with an empty {string}) to execute all the |
| 2974 | typeahead. Note that when Vim ends in Insert mode it |
| 2975 | will behave as if <Esc> is typed, to avoid getting |
| 2976 | stuck, waiting for a character to be typed before the |
| 2977 | script continues. |
| 2978 | Note that if you manage to call feedkeys() while |
| 2979 | executing commands, thus calling it recursively, then |
| 2980 | all typeahead will be consumed by the last call. |
Bram Moolenaar | a972522 | 2022-01-16 13:30:33 +0000 | [diff] [blame] | 2981 | 'c' Remove any script context when executing, so that |
| 2982 | legacy script syntax applies, "s:var" does not work, |
Bram Moolenaar | d899e51 | 2022-05-07 21:54:03 +0100 | [diff] [blame] | 2983 | etc. Note that if the string being fed sets a script |
Bram Moolenaar | ce001a3 | 2022-04-27 15:25:03 +0100 | [diff] [blame] | 2984 | context this still applies. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2985 | '!' When used with 'x' will not end Insert mode. Can be |
| 2986 | used in a test when a timer is set to exit Insert mode |
| 2987 | a little later. Useful for testing CursorHoldI. |
| 2988 | |
| 2989 | Return value is always 0. |
| 2990 | |
| 2991 | Can also be used as a |method|: > |
| 2992 | GetInput()->feedkeys() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 2993 | < |
| 2994 | Return type: |String| or list<string> depending on {list} |
| 2995 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 2996 | |
Shougo Matsushita | 60c8743 | 2024-06-03 22:59:27 +0200 | [diff] [blame] | 2997 | filecopy({from}, {to}) *filecopy()* |
| 2998 | Copy the file pointed to by the name {from} to {to}. The |
| 2999 | result is a Number, which is |TRUE| if the file was copied |
| 3000 | successfully, and |FALSE| when it failed. |
| 3001 | If a file with name {to} already exists, it will fail. |
| 3002 | Note that it does not handle directories (yet). |
| 3003 | |
| 3004 | This function is not available in the |sandbox|. |
| 3005 | |
| 3006 | Can also be used as a |method|: > |
| 3007 | GetOldName()->filecopy(newname) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 3008 | < |
| 3009 | Return type: |Number| |
| 3010 | |
Shougo Matsushita | 60c8743 | 2024-06-03 22:59:27 +0200 | [diff] [blame] | 3011 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3012 | filereadable({file}) *filereadable()* |
| 3013 | The result is a Number, which is |TRUE| when a file with the |
| 3014 | name {file} exists, and can be read. If {file} doesn't exist, |
| 3015 | or is a directory, the result is |FALSE|. {file} is any |
| 3016 | expression, which is used as a String. |
| 3017 | If you don't care about the file being readable you can use |
| 3018 | |glob()|. |
| 3019 | {file} is used as-is, you may want to expand wildcards first: > |
| 3020 | echo filereadable('~/.vimrc') |
| 3021 | 0 |
| 3022 | echo filereadable(expand('~/.vimrc')) |
| 3023 | 1 |
| 3024 | |
| 3025 | < Can also be used as a |method|: > |
| 3026 | GetName()->filereadable() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 3027 | < |
| 3028 | Return type: |Number| |
| 3029 | |
| 3030 | *file_readable()* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3031 | Obsolete name: file_readable(). |
| 3032 | |
| 3033 | |
| 3034 | filewritable({file}) *filewritable()* |
| 3035 | The result is a Number, which is 1 when a file with the |
| 3036 | name {file} exists, and can be written. If {file} doesn't |
| 3037 | exist, or is not writable, the result is 0. If {file} is a |
| 3038 | directory, and we can write to it, the result is 2. |
| 3039 | |
| 3040 | Can also be used as a |method|: > |
| 3041 | GetName()->filewritable() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 3042 | < |
| 3043 | Return type: |Number| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3044 | |
| 3045 | |
| 3046 | filter({expr1}, {expr2}) *filter()* |
| 3047 | {expr1} must be a |List|, |String|, |Blob| or |Dictionary|. |
| 3048 | For each item in {expr1} evaluate {expr2} and when the result |
| 3049 | is zero or false remove the item from the |List| or |
| 3050 | |Dictionary|. Similarly for each byte in a |Blob| and each |
Bram Moolenaar | 2f0936c | 2022-01-08 21:51:59 +0000 | [diff] [blame] | 3051 | character in a |String|. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3052 | |
| 3053 | {expr2} must be a |string| or |Funcref|. |
| 3054 | |
| 3055 | If {expr2} is a |string|, inside {expr2} |v:val| has the value |
| 3056 | of the current item. For a |Dictionary| |v:key| has the key |
| 3057 | of the current item and for a |List| |v:key| has the index of |
| 3058 | the current item. For a |Blob| |v:key| has the index of the |
| 3059 | current byte. For a |String| |v:key| has the index of the |
| 3060 | current character. |
| 3061 | Examples: > |
| 3062 | call filter(mylist, 'v:val !~ "OLD"') |
| 3063 | < Removes the items where "OLD" appears. > |
| 3064 | call filter(mydict, 'v:key >= 8') |
| 3065 | < Removes the items with a key below 8. > |
| 3066 | call filter(var, 0) |
| 3067 | < Removes all the items, thus clears the |List| or |Dictionary|. |
| 3068 | |
| 3069 | Note that {expr2} is the result of expression and is then |
| 3070 | used as an expression again. Often it is good to use a |
| 3071 | |literal-string| to avoid having to double backslashes. |
| 3072 | |
| 3073 | If {expr2} is a |Funcref| it must take two arguments: |
| 3074 | 1. the key or the index of the current item. |
| 3075 | 2. the value of the current item. |
| 3076 | The function must return |TRUE| if the item should be kept. |
| 3077 | Example that keeps the odd items of a list: > |
| 3078 | func Odd(idx, val) |
| 3079 | return a:idx % 2 == 1 |
| 3080 | endfunc |
| 3081 | call filter(mylist, function('Odd')) |
Bram Moolenaar | 2f0936c | 2022-01-08 21:51:59 +0000 | [diff] [blame] | 3082 | < It is shorter when using a |lambda|. In |Vim9| syntax: > |
| 3083 | call filter(myList, (idx, val) => idx * val <= 42) |
| 3084 | < In legacy script syntax: > |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3085 | call filter(myList, {idx, val -> idx * val <= 42}) |
| 3086 | < If you do not use "val" you can leave it out: > |
| 3087 | call filter(myList, {idx -> idx % 2 == 1}) |
| 3088 | < |
| 3089 | In |Vim9| script the result must be true, false, zero or one. |
| 3090 | Other values will result in a type error. |
| 3091 | |
| 3092 | For a |List| and a |Dictionary| the operation is done |
| 3093 | in-place. If you want it to remain unmodified make a copy |
| 3094 | first: > |
| 3095 | :let l = filter(copy(mylist), 'v:val =~ "KEEP"') |
| 3096 | |
| 3097 | < Returns {expr1}, the |List| or |Dictionary| that was filtered, |
naohiro ono | 56200ee | 2022-01-01 14:59:44 +0000 | [diff] [blame] | 3098 | or a new |Blob| or |String|. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3099 | When an error is encountered while evaluating {expr2} no |
| 3100 | further items in {expr1} are processed. |
| 3101 | When {expr2} is a Funcref errors inside a function are ignored, |
| 3102 | unless it was defined with the "abort" flag. |
| 3103 | |
| 3104 | Can also be used as a |method|: > |
| 3105 | mylist->filter(expr2) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 3106 | < |
| 3107 | Return type: |String|, |Blob|, list<{type}> or dict<{type}> |
| 3108 | depending on {expr1} |
| 3109 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3110 | |
| 3111 | finddir({name} [, {path} [, {count}]]) *finddir()* |
| 3112 | Find directory {name} in {path}. Supports both downwards and |
| 3113 | upwards recursive directory searches. See |file-searching| |
| 3114 | for the syntax of {path}. |
| 3115 | |
| 3116 | Returns the path of the first found match. When the found |
| 3117 | directory is below the current directory a relative path is |
| 3118 | returned. Otherwise a full path is returned. |
| 3119 | If {path} is omitted or empty then 'path' is used. |
| 3120 | |
| 3121 | If the optional {count} is given, find {count}'s occurrence of |
| 3122 | {name} in {path} instead of the first one. |
| 3123 | When {count} is negative return all the matches in a |List|. |
| 3124 | |
Bram Moolenaar | 016188f | 2022-06-06 20:52:59 +0100 | [diff] [blame] | 3125 | Returns an empty string if the directory is not found. |
| 3126 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3127 | This is quite similar to the ex-command `:find`. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3128 | |
| 3129 | Can also be used as a |method|: > |
| 3130 | GetName()->finddir() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 3131 | < |
| 3132 | Return type: |String| |
| 3133 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3134 | |
| 3135 | findfile({name} [, {path} [, {count}]]) *findfile()* |
| 3136 | Just like |finddir()|, but find a file instead of a directory. |
| 3137 | Uses 'suffixesadd'. |
| 3138 | Example: > |
| 3139 | :echo findfile("tags.vim", ".;") |
| 3140 | < Searches from the directory of the current file upwards until |
| 3141 | it finds the file "tags.vim". |
| 3142 | |
| 3143 | Can also be used as a |method|: > |
| 3144 | GetName()->findfile() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 3145 | < |
| 3146 | Return type: |String| |
| 3147 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3148 | |
| 3149 | flatten({list} [, {maxdepth}]) *flatten()* |
| 3150 | Flatten {list} up to {maxdepth} levels. Without {maxdepth} |
| 3151 | the result is a |List| without nesting, as if {maxdepth} is |
| 3152 | a very large number. |
| 3153 | The {list} is changed in place, use |flattennew()| if you do |
| 3154 | not want that. |
| 3155 | In Vim9 script flatten() cannot be used, you must always use |
Bram Moolenaar | a2baa73 | 2022-02-04 16:09:54 +0000 | [diff] [blame] | 3156 | |flattennew()|. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3157 | *E900* |
| 3158 | {maxdepth} means how deep in nested lists changes are made. |
| 3159 | {list} is not modified when {maxdepth} is 0. |
| 3160 | {maxdepth} must be positive number. |
| 3161 | |
| 3162 | If there is an error the number zero is returned. |
| 3163 | |
| 3164 | Example: > |
| 3165 | :echo flatten([1, [2, [3, 4]], 5]) |
| 3166 | < [1, 2, 3, 4, 5] > |
| 3167 | :echo flatten([1, [2, [3, 4]], 5], 1) |
| 3168 | < [1, 2, [3, 4], 5] |
| 3169 | |
| 3170 | Can also be used as a |method|: > |
| 3171 | mylist->flatten() |
| 3172 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 3173 | Return type: list<{type}> |
| 3174 | |
| 3175 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3176 | flattennew({list} [, {maxdepth}]) *flattennew()* |
| 3177 | Like |flatten()| but first make a copy of {list}. |
| 3178 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 3179 | Return type: list<{type}> |
| 3180 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3181 | |
| 3182 | float2nr({expr}) *float2nr()* |
| 3183 | Convert {expr} to a Number by omitting the part after the |
| 3184 | decimal point. |
Bram Moolenaar | 76db9e0 | 2022-11-09 21:21:04 +0000 | [diff] [blame] | 3185 | {expr} must evaluate to a |Float| or a |Number|. |
Bram Moolenaar | 016188f | 2022-06-06 20:52:59 +0100 | [diff] [blame] | 3186 | Returns 0 if {expr} is not a |Float| or a |Number|. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3187 | When the value of {expr} is out of range for a |Number| the |
| 3188 | result is truncated to 0x7fffffff or -0x7fffffff (or when |
| 3189 | 64-bit Number support is enabled, 0x7fffffffffffffff or |
| 3190 | -0x7fffffffffffffff). NaN results in -0x80000000 (or when |
| 3191 | 64-bit Number support is enabled, -0x8000000000000000). |
| 3192 | Examples: > |
| 3193 | echo float2nr(3.95) |
| 3194 | < 3 > |
| 3195 | echo float2nr(-23.45) |
| 3196 | < -23 > |
| 3197 | echo float2nr(1.0e100) |
| 3198 | < 2147483647 (or 9223372036854775807) > |
| 3199 | echo float2nr(-1.0e150) |
| 3200 | < -2147483647 (or -9223372036854775807) > |
| 3201 | echo float2nr(1.0e-100) |
| 3202 | < 0 |
| 3203 | |
| 3204 | Can also be used as a |method|: > |
| 3205 | Compute()->float2nr() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 3206 | < |
| 3207 | Return type: |Number| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3208 | |
| 3209 | |
| 3210 | floor({expr}) *floor()* |
| 3211 | Return the largest integral value less than or equal to |
| 3212 | {expr} as a |Float| (round down). |
| 3213 | {expr} must evaluate to a |Float| or a |Number|. |
Bram Moolenaar | 016188f | 2022-06-06 20:52:59 +0100 | [diff] [blame] | 3214 | Returns 0.0 if {expr} is not a |Float| or a |Number|. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3215 | Examples: > |
| 3216 | echo floor(1.856) |
| 3217 | < 1.0 > |
| 3218 | echo floor(-5.456) |
| 3219 | < -6.0 > |
| 3220 | echo floor(4.0) |
| 3221 | < 4.0 |
| 3222 | |
| 3223 | Can also be used as a |method|: > |
| 3224 | Compute()->floor() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 3225 | < |
| 3226 | Return type: |Float| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3227 | |
| 3228 | |
| 3229 | fmod({expr1}, {expr2}) *fmod()* |
| 3230 | Return the remainder of {expr1} / {expr2}, even if the |
| 3231 | division is not representable. Returns {expr1} - i * {expr2} |
| 3232 | for some integer i such that if {expr2} is non-zero, the |
| 3233 | result has the same sign as {expr1} and magnitude less than |
| 3234 | the magnitude of {expr2}. If {expr2} is zero, the value |
| 3235 | returned is zero. The value returned is a |Float|. |
| 3236 | {expr1} and {expr2} must evaluate to a |Float| or a |Number|. |
Bram Moolenaar | 016188f | 2022-06-06 20:52:59 +0100 | [diff] [blame] | 3237 | Returns 0.0 if {expr1} or {expr2} is not a |Float| or a |
| 3238 | |Number|. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3239 | Examples: > |
| 3240 | :echo fmod(12.33, 1.22) |
| 3241 | < 0.13 > |
| 3242 | :echo fmod(-12.33, 1.22) |
| 3243 | < -0.13 |
| 3244 | |
| 3245 | Can also be used as a |method|: > |
| 3246 | Compute()->fmod(1.22) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 3247 | < |
| 3248 | Return type: |Float| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3249 | |
| 3250 | |
| 3251 | fnameescape({string}) *fnameescape()* |
| 3252 | Escape {string} for use as file name command argument. All |
| 3253 | characters that have a special meaning, such as '%' and '|' |
| 3254 | are escaped with a backslash. |
| 3255 | For most systems the characters escaped are |
| 3256 | " \t\n*?[{`$\\%#'\"|!<". For systems where a backslash |
| 3257 | appears in a filename, it depends on the value of 'isfname'. |
| 3258 | A leading '+' and '>' is also escaped (special after |:edit| |
| 3259 | and |:write|). And a "-" by itself (special after |:cd|). |
Bram Moolenaar | 016188f | 2022-06-06 20:52:59 +0100 | [diff] [blame] | 3260 | Returns an empty string on error. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3261 | Example: > |
| 3262 | :let fname = '+some str%nge|name' |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 3263 | :exe "edit " .. fnameescape(fname) |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3264 | < results in executing: > |
| 3265 | edit \+some\ str\%nge\|name |
| 3266 | < |
| 3267 | Can also be used as a |method|: > |
| 3268 | GetName()->fnameescape() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 3269 | < |
| 3270 | Return type: |String| |
| 3271 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3272 | |
| 3273 | fnamemodify({fname}, {mods}) *fnamemodify()* |
| 3274 | Modify file name {fname} according to {mods}. {mods} is a |
| 3275 | string of characters like it is used for file names on the |
| 3276 | command line. See |filename-modifiers|. |
| 3277 | Example: > |
| 3278 | :echo fnamemodify("main.c", ":p:h") |
| 3279 | < results in: > |
Bram Moolenaar | d799daa | 2022-06-20 11:17:32 +0100 | [diff] [blame] | 3280 | /home/user/vim/vim/src |
Bram Moolenaar | 016188f | 2022-06-06 20:52:59 +0100 | [diff] [blame] | 3281 | < If {mods} is empty or an unsupported modifier is used then |
| 3282 | {fname} is returned. |
Bram Moolenaar | 5ed1153 | 2022-07-06 13:18:11 +0100 | [diff] [blame] | 3283 | When {fname} is empty then with {mods} ":h" returns ".", so |
| 3284 | that `:cd` can be used with it. This is different from |
| 3285 | expand('%:h') without a buffer name, which returns an empty |
| 3286 | string. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3287 | Note: Environment variables don't work in {fname}, use |
| 3288 | |expand()| first then. |
| 3289 | |
| 3290 | Can also be used as a |method|: > |
| 3291 | GetName()->fnamemodify(':p:h') |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 3292 | < |
| 3293 | Return type: |String| |
| 3294 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3295 | |
| 3296 | foldclosed({lnum}) *foldclosed()* |
| 3297 | The result is a Number. If the line {lnum} is in a closed |
| 3298 | fold, the result is the number of the first line in that fold. |
| 3299 | If the line {lnum} is not in a closed fold, -1 is returned. |
| 3300 | {lnum} is used like with |getline()|. Thus "." is the current |
| 3301 | line, "'m" mark m, etc. |
| 3302 | |
| 3303 | Can also be used as a |method|: > |
| 3304 | GetLnum()->foldclosed() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 3305 | < |
| 3306 | Return type: |Number| |
| 3307 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3308 | |
| 3309 | foldclosedend({lnum}) *foldclosedend()* |
| 3310 | The result is a Number. If the line {lnum} is in a closed |
| 3311 | fold, the result is the number of the last line in that fold. |
| 3312 | If the line {lnum} is not in a closed fold, -1 is returned. |
| 3313 | {lnum} is used like with |getline()|. Thus "." is the current |
| 3314 | line, "'m" mark m, etc. |
| 3315 | |
| 3316 | Can also be used as a |method|: > |
| 3317 | GetLnum()->foldclosedend() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 3318 | < |
| 3319 | Return type: |Number| |
| 3320 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3321 | |
| 3322 | foldlevel({lnum}) *foldlevel()* |
| 3323 | The result is a Number, which is the foldlevel of line {lnum} |
| 3324 | in the current buffer. For nested folds the deepest level is |
| 3325 | returned. If there is no fold at line {lnum}, zero is |
| 3326 | returned. It doesn't matter if the folds are open or closed. |
| 3327 | When used while updating folds (from 'foldexpr') -1 is |
| 3328 | returned for lines where folds are still to be updated and the |
| 3329 | foldlevel is unknown. As a special case the level of the |
| 3330 | previous line is usually available. |
| 3331 | {lnum} is used like with |getline()|. Thus "." is the current |
| 3332 | line, "'m" mark m, etc. |
| 3333 | |
| 3334 | Can also be used as a |method|: > |
| 3335 | GetLnum()->foldlevel() |
| 3336 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 3337 | Return type: |Number| |
| 3338 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3339 | *foldtext()* |
| 3340 | foldtext() Returns a String, to be displayed for a closed fold. This is |
| 3341 | the default function used for the 'foldtext' option and should |
| 3342 | only be called from evaluating 'foldtext'. It uses the |
| 3343 | |v:foldstart|, |v:foldend| and |v:folddashes| variables. |
| 3344 | The returned string looks like this: > |
| 3345 | +-- 45 lines: abcdef |
| 3346 | < The number of leading dashes depends on the foldlevel. The |
| 3347 | "45" is the number of lines in the fold. "abcdef" is the text |
| 3348 | in the first non-blank line of the fold. Leading white space, |
| 3349 | "//" or "/*" and the text from the 'foldmarker' and |
| 3350 | 'commentstring' options is removed. |
| 3351 | When used to draw the actual foldtext, the rest of the line |
| 3352 | will be filled with the fold char from the 'fillchars' |
| 3353 | setting. |
Bram Moolenaar | 016188f | 2022-06-06 20:52:59 +0100 | [diff] [blame] | 3354 | Returns an empty string when there is no fold. |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 3355 | |
| 3356 | Return type: |String| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3357 | {not available when compiled without the |+folding| feature} |
| 3358 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 3359 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3360 | foldtextresult({lnum}) *foldtextresult()* |
| 3361 | Returns the text that is displayed for the closed fold at line |
| 3362 | {lnum}. Evaluates 'foldtext' in the appropriate context. |
| 3363 | When there is no closed fold at {lnum} an empty string is |
| 3364 | returned. |
| 3365 | {lnum} is used like with |getline()|. Thus "." is the current |
| 3366 | line, "'m" mark m, etc. |
| 3367 | Useful when exporting folded text, e.g., to HTML. |
| 3368 | {not available when compiled without the |+folding| feature} |
| 3369 | |
| 3370 | |
| 3371 | Can also be used as a |method|: > |
| 3372 | GetLnum()->foldtextresult() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 3373 | < |
| 3374 | Return type: |String| |
| 3375 | |
Ernie Rael | e79e207 | 2024-01-13 11:47:33 +0100 | [diff] [blame] | 3376 | |
| 3377 | foreach({expr1}, {expr2}) *foreach()* |
| 3378 | {expr1} must be a |List|, |String|, |Blob| or |Dictionary|. |
| 3379 | For each item in {expr1} execute {expr2}. {expr1} is not |
errael | c92b8be | 2024-01-14 10:11:07 -0800 | [diff] [blame] | 3380 | modified; its values may be, as with |:lockvar| 1. |E741| |
Ernie Rael | e79e207 | 2024-01-13 11:47:33 +0100 | [diff] [blame] | 3381 | See |map()| and |filter()| to modify {expr1}. |
| 3382 | |
| 3383 | {expr2} must be a |string| or |Funcref|. |
| 3384 | |
| 3385 | If {expr2} is a |string|, inside {expr2} |v:val| has the value |
| 3386 | of the current item. For a |Dictionary| |v:key| has the key |
| 3387 | of the current item and for a |List| |v:key| has the index of |
| 3388 | the current item. For a |Blob| |v:key| has the index of the |
| 3389 | current byte. For a |String| |v:key| has the index of the |
| 3390 | current character. |
| 3391 | Examples: > |
| 3392 | call foreach(mylist, 'used[v:val] = true') |
| 3393 | < This records the items that are in the {expr1} list. |
| 3394 | |
| 3395 | Note that {expr2} is the result of expression and is then used |
| 3396 | as a command. Often it is good to use a |literal-string| to |
| 3397 | avoid having to double backslashes. |
| 3398 | |
| 3399 | If {expr2} is a |Funcref| it must take two arguments: |
| 3400 | 1. the key or the index of the current item. |
| 3401 | 2. the value of the current item. |
| 3402 | With a legacy script lambda you don't get an error if it only |
| 3403 | accepts one argument, but with a Vim9 lambda you get "E1106: |
| 3404 | One argument too many", the number of arguments must match. |
| 3405 | If the function returns a value, it is ignored. |
| 3406 | |
| 3407 | Returns {expr1} in all cases. |
| 3408 | When an error is encountered while executing {expr2} no |
| 3409 | further items in {expr1} are processed. |
| 3410 | When {expr2} is a Funcref errors inside a function are ignored, |
| 3411 | unless it was defined with the "abort" flag. |
| 3412 | |
| 3413 | Can also be used as a |method|: > |
| 3414 | mylist->foreach(expr2) |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3415 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 3416 | Return type: |String|, |Blob| list<{type}> or dict<{type}> |
| 3417 | depending on {expr1} |
| 3418 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3419 | *foreground()* |
| 3420 | foreground() Move the Vim window to the foreground. Useful when sent from |
| 3421 | a client to a Vim server. |remote_send()| |
| 3422 | On Win32 systems this might not work, the OS does not always |
| 3423 | allow a window to bring itself to the foreground. Use |
| 3424 | |remote_foreground()| instead. |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 3425 | |
| 3426 | Return type: |Number| |
Bram Moolenaar | cbaff5e | 2022-04-08 17:45:08 +0100 | [diff] [blame] | 3427 | {only in the Win32, Motif and GTK GUI versions and the |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3428 | Win32 console version} |
| 3429 | |
Bram Moolenaar | aa53414 | 2022-09-15 21:46:02 +0100 | [diff] [blame] | 3430 | fullcommand({name} [, {vim9}]) *fullcommand()* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3431 | Get the full command name from a short abbreviated command |
| 3432 | name; see |20.2| for details on command abbreviations. |
| 3433 | |
| 3434 | The string argument {name} may start with a `:` and can |
| 3435 | include a [range], these are skipped and not returned. |
Bram Moolenaar | aa53414 | 2022-09-15 21:46:02 +0100 | [diff] [blame] | 3436 | Returns an empty string if a command doesn't exist, if it's |
| 3437 | ambiguous (for user-defined commands) or cannot be shortened |
| 3438 | this way. |vim9-no-shorten| |
| 3439 | |
| 3440 | Without the {vim9} argument uses the current script version. |
| 3441 | If {vim9} is present and FALSE then legacy script rules are |
| 3442 | used. When {vim9} is present and TRUE then Vim9 rules are |
| 3443 | used, e.g. "en" is not a short form of "endif". |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3444 | |
| 3445 | For example `fullcommand('s')`, `fullcommand('sub')`, |
| 3446 | `fullcommand(':%substitute')` all return "substitute". |
| 3447 | |
| 3448 | Can also be used as a |method|: > |
| 3449 | GetName()->fullcommand() |
| 3450 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 3451 | Return type: |String| |
| 3452 | |
| 3453 | |
| 3454 | funcref({name} [, {arglist}] [, {dict}]) *funcref()* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3455 | Just like |function()|, but the returned Funcref will lookup |
| 3456 | the function by reference, not by name. This matters when the |
| 3457 | function {name} is redefined later. |
| 3458 | |
| 3459 | Unlike |function()|, {name} must be an existing user function. |
Bram Moolenaar | 2f0936c | 2022-01-08 21:51:59 +0000 | [diff] [blame] | 3460 | It only works for an autoloaded function if it has already |
| 3461 | been loaded (to avoid mistakenly loading the autoload script |
| 3462 | when only intending to use the function name, use |function()| |
| 3463 | instead). {name} cannot be a builtin function. |
Bram Moolenaar | 016188f | 2022-06-06 20:52:59 +0100 | [diff] [blame] | 3464 | Returns 0 on error. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3465 | |
| 3466 | Can also be used as a |method|: > |
| 3467 | GetFuncname()->funcref([arg]) |
| 3468 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 3469 | Return type: func(...): any or |Number| on error |
| 3470 | |
Dominique Pelle | e764d1b | 2023-03-12 21:20:59 +0000 | [diff] [blame] | 3471 | *function()* *partial* *E700* *E923* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3472 | function({name} [, {arglist}] [, {dict}]) |
| 3473 | Return a |Funcref| variable that refers to function {name}. |
| 3474 | {name} can be the name of a user defined function or an |
| 3475 | internal function. |
| 3476 | |
| 3477 | {name} can also be a Funcref or a partial. When it is a |
| 3478 | partial the dict stored in it will be used and the {dict} |
| 3479 | argument is not allowed. E.g.: > |
| 3480 | let FuncWithArg = function(dict.Func, [arg]) |
| 3481 | let Broken = function(dict.Func, [arg], dict) |
| 3482 | < |
| 3483 | When using the Funcref the function will be found by {name}, |
| 3484 | also when it was redefined later. Use |funcref()| to keep the |
| 3485 | same function. |
| 3486 | |
| 3487 | When {arglist} or {dict} is present this creates a partial. |
| 3488 | That means the argument list and/or the dictionary is stored in |
| 3489 | the Funcref and will be used when the Funcref is called. |
| 3490 | |
| 3491 | The arguments are passed to the function in front of other |
| 3492 | arguments, but after any argument from |method|. Example: > |
| 3493 | func Callback(arg1, arg2, name) |
| 3494 | ... |
| 3495 | let Partial = function('Callback', ['one', 'two']) |
| 3496 | ... |
| 3497 | call Partial('name') |
| 3498 | < Invokes the function as with: > |
| 3499 | call Callback('one', 'two', 'name') |
| 3500 | |
| 3501 | < With a |method|: > |
| 3502 | func Callback(one, two, three) |
| 3503 | ... |
| 3504 | let Partial = function('Callback', ['two']) |
| 3505 | ... |
| 3506 | eval 'one'->Partial('three') |
| 3507 | < Invokes the function as with: > |
| 3508 | call Callback('one', 'two', 'three') |
| 3509 | |
| 3510 | < The function() call can be nested to add more arguments to the |
| 3511 | Funcref. The extra arguments are appended to the list of |
| 3512 | arguments. Example: > |
| 3513 | func Callback(arg1, arg2, name) |
Bram Moolenaar | 0daafaa | 2022-09-04 17:45:43 +0100 | [diff] [blame] | 3514 | "... |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3515 | let Func = function('Callback', ['one']) |
| 3516 | let Func2 = function(Func, ['two']) |
Bram Moolenaar | 0daafaa | 2022-09-04 17:45:43 +0100 | [diff] [blame] | 3517 | "... |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3518 | call Func2('name') |
| 3519 | < Invokes the function as with: > |
| 3520 | call Callback('one', 'two', 'name') |
| 3521 | |
| 3522 | < The Dictionary is only useful when calling a "dict" function. |
| 3523 | In that case the {dict} is passed in as "self". Example: > |
| 3524 | function Callback() dict |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 3525 | echo "called for " .. self.name |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3526 | endfunction |
Bram Moolenaar | 0daafaa | 2022-09-04 17:45:43 +0100 | [diff] [blame] | 3527 | "... |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3528 | let context = {"name": "example"} |
| 3529 | let Func = function('Callback', context) |
Bram Moolenaar | 0daafaa | 2022-09-04 17:45:43 +0100 | [diff] [blame] | 3530 | "... |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3531 | call Func() " will echo: called for example |
| 3532 | < The use of function() is not needed when there are no extra |
Bram Moolenaar | 0daafaa | 2022-09-04 17:45:43 +0100 | [diff] [blame] | 3533 | arguments, these two are equivalent, if Callback() is defined |
| 3534 | as context.Callback(): > |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3535 | let Func = function('Callback', context) |
| 3536 | let Func = context.Callback |
| 3537 | |
| 3538 | < The argument list and the Dictionary can be combined: > |
| 3539 | function Callback(arg1, count) dict |
Bram Moolenaar | 0daafaa | 2022-09-04 17:45:43 +0100 | [diff] [blame] | 3540 | "... |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3541 | let context = {"name": "example"} |
| 3542 | let Func = function('Callback', ['one'], context) |
Bram Moolenaar | 0daafaa | 2022-09-04 17:45:43 +0100 | [diff] [blame] | 3543 | "... |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3544 | call Func(500) |
| 3545 | < Invokes the function as with: > |
| 3546 | call context.Callback('one', 500) |
| 3547 | < |
Bram Moolenaar | 016188f | 2022-06-06 20:52:59 +0100 | [diff] [blame] | 3548 | Returns 0 on error. |
| 3549 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3550 | Can also be used as a |method|: > |
| 3551 | GetFuncname()->function([arg]) |
| 3552 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 3553 | < |
| 3554 | Return type: func(...): any or |Number| on error |
| 3555 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3556 | |
| 3557 | garbagecollect([{atexit}]) *garbagecollect()* |
| 3558 | Cleanup unused |Lists|, |Dictionaries|, |Channels| and |Jobs| |
| 3559 | that have circular references. |
| 3560 | |
| 3561 | There is hardly ever a need to invoke this function, as it is |
| 3562 | automatically done when Vim runs out of memory or is waiting |
| 3563 | for the user to press a key after 'updatetime'. Items without |
| 3564 | circular references are always freed when they become unused. |
| 3565 | This is useful if you have deleted a very big |List| and/or |
| 3566 | |Dictionary| with circular references in a script that runs |
| 3567 | for a long time. |
| 3568 | |
| 3569 | When the optional {atexit} argument is one, garbage |
| 3570 | collection will also be done when exiting Vim, if it wasn't |
| 3571 | done before. This is useful when checking for memory leaks. |
| 3572 | |
| 3573 | The garbage collection is not done immediately but only when |
| 3574 | it's safe to perform. This is when waiting for the user to |
| 3575 | type a character. To force garbage collection immediately use |
| 3576 | |test_garbagecollect_now()|. |
| 3577 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 3578 | Return type: |String| |
| 3579 | |
| 3580 | |
LemonBoy | 48b7d05 | 2024-07-09 18:24:59 +0200 | [diff] [blame] | 3581 | get({list}, {idx} [, {default}]) *get()* *get()-list* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3582 | Get item {idx} from |List| {list}. When this item is not |
| 3583 | available return {default}. Return zero when {default} is |
| 3584 | omitted. |
| 3585 | Preferably used as a |method|: > |
| 3586 | mylist->get(idx) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 3587 | < |
| 3588 | Return type: any, depending on {list} |
| 3589 | |
LemonBoy | 48b7d05 | 2024-07-09 18:24:59 +0200 | [diff] [blame] | 3590 | get({blob}, {idx} [, {default}]) *get()-blob* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3591 | Get byte {idx} from |Blob| {blob}. When this byte is not |
| 3592 | available return {default}. Return -1 when {default} is |
| 3593 | omitted. |
| 3594 | Preferably used as a |method|: > |
| 3595 | myblob->get(idx) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 3596 | < |
| 3597 | Return type: |Number| |
| 3598 | |
LemonBoy | 48b7d05 | 2024-07-09 18:24:59 +0200 | [diff] [blame] | 3599 | get({dict}, {key} [, {default}]) *get()-dict* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3600 | Get item with key {key} from |Dictionary| {dict}. When this |
| 3601 | item is not available return {default}. Return zero when |
| 3602 | {default} is omitted. Useful example: > |
| 3603 | let val = get(g:, 'var_name', 'default') |
| 3604 | < This gets the value of g:var_name if it exists, and uses |
| 3605 | 'default' when it does not exist. |
| 3606 | Preferably used as a |method|: > |
| 3607 | mydict->get(key) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 3608 | < |
h-east | 84ac212 | 2024-06-17 18:12:30 +0200 | [diff] [blame] | 3609 | Return type: any, depending on {dict} |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 3610 | |
LemonBoy | 48b7d05 | 2024-07-09 18:24:59 +0200 | [diff] [blame] | 3611 | get({func}, {what}) *get()-func* |
| 3612 | Get item {what} from |Funcref| {func}. Possible values for |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3613 | {what} are: |
LemonBoy | 48b7d05 | 2024-07-09 18:24:59 +0200 | [diff] [blame] | 3614 | "name" The function name |
| 3615 | "func" The function |
| 3616 | "dict" The dictionary |
| 3617 | "args" The list with arguments |
| 3618 | "arity" A dictionary with information about the number of |
| 3619 | arguments accepted by the function (minus the |
| 3620 | {arglist}) with the following fields: |
| 3621 | required the number of positional arguments |
| 3622 | optional the number of optional arguments, |
| 3623 | in addition to the required ones |
| 3624 | varargs |TRUE| if the function accepts a |
| 3625 | variable number of arguments |...| |
| 3626 | |
| 3627 | Note: There is no error, if the {arglist} of |
| 3628 | the Funcref contains more arguments than the |
| 3629 | Funcref expects, it's not validated. |
| 3630 | |
Bram Moolenaar | 016188f | 2022-06-06 20:52:59 +0100 | [diff] [blame] | 3631 | Returns zero on error. |
LemonBoy | 48b7d05 | 2024-07-09 18:24:59 +0200 | [diff] [blame] | 3632 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3633 | Preferably used as a |method|: > |
| 3634 | myfunc->get(what) |
| 3635 | < |
LemonBoy | 48b7d05 | 2024-07-09 18:24:59 +0200 | [diff] [blame] | 3636 | Return type: any, depending on {func} and {what} |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 3637 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3638 | *getbufinfo()* |
| 3639 | getbufinfo([{buf}]) |
| 3640 | getbufinfo([{dict}]) |
| 3641 | Get information about buffers as a List of Dictionaries. |
| 3642 | |
| 3643 | Without an argument information about all the buffers is |
| 3644 | returned. |
| 3645 | |
| 3646 | When the argument is a |Dictionary| only the buffers matching |
| 3647 | the specified criteria are returned. The following keys can |
| 3648 | be specified in {dict}: |
| 3649 | buflisted include only listed buffers. |
| 3650 | bufloaded include only loaded buffers. |
| 3651 | bufmodified include only modified buffers. |
| 3652 | |
| 3653 | Otherwise, {buf} specifies a particular buffer to return |
| 3654 | information for. For the use of {buf}, see |bufname()| |
| 3655 | above. If the buffer is found the returned List has one item. |
| 3656 | Otherwise the result is an empty list. |
| 3657 | |
| 3658 | Each returned List item is a dictionary with the following |
| 3659 | entries: |
| 3660 | bufnr Buffer number. |
| 3661 | changed TRUE if the buffer is modified. |
| 3662 | changedtick Number of changes made to the buffer. |
Sean Dewar | 1fb4103 | 2023-08-16 17:15:05 +0100 | [diff] [blame] | 3663 | command TRUE if the buffer belongs to the |
| 3664 | command-line window |cmdwin|. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3665 | hidden TRUE if the buffer is hidden. |
| 3666 | lastused Timestamp in seconds, like |
| 3667 | |localtime()|, when the buffer was |
| 3668 | last used. |
| 3669 | {only with the |+viminfo| feature} |
| 3670 | listed TRUE if the buffer is listed. |
| 3671 | lnum Line number used for the buffer when |
| 3672 | opened in the current window. |
| 3673 | Only valid if the buffer has been |
| 3674 | displayed in the window in the past. |
| 3675 | If you want the line number of the |
| 3676 | last known cursor position in a given |
| 3677 | window, use |line()|: > |
| 3678 | :echo line('.', {winid}) |
| 3679 | < |
| 3680 | linecount Number of lines in the buffer (only |
| 3681 | valid when loaded) |
| 3682 | loaded TRUE if the buffer is loaded. |
| 3683 | name Full path to the file in the buffer. |
| 3684 | signs List of signs placed in the buffer. |
| 3685 | Each list item is a dictionary with |
| 3686 | the following fields: |
| 3687 | id sign identifier |
| 3688 | lnum line number |
| 3689 | name sign name |
| 3690 | variables A reference to the dictionary with |
| 3691 | buffer-local variables. |
| 3692 | windows List of |window-ID|s that display this |
| 3693 | buffer |
| 3694 | popups List of popup |window-ID|s that |
| 3695 | display this buffer |
| 3696 | |
| 3697 | Examples: > |
| 3698 | for buf in getbufinfo() |
| 3699 | echo buf.name |
| 3700 | endfor |
| 3701 | for buf in getbufinfo({'buflisted':1}) |
| 3702 | if buf.changed |
| 3703 | .... |
| 3704 | endif |
| 3705 | endfor |
| 3706 | < |
| 3707 | To get buffer-local options use: > |
| 3708 | getbufvar({bufnr}, '&option_name') |
| 3709 | < |
| 3710 | Can also be used as a |method|: > |
| 3711 | GetBufnr()->getbufinfo() |
| 3712 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 3713 | Return type: list<dict<any>> |
| 3714 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3715 | |
| 3716 | *getbufline()* |
| 3717 | getbufline({buf}, {lnum} [, {end}]) |
| 3718 | Return a |List| with the lines starting from {lnum} to {end} |
| 3719 | (inclusive) in the buffer {buf}. If {end} is omitted, a |
Bram Moolenaar | ce30ccc | 2022-11-21 19:57:04 +0000 | [diff] [blame] | 3720 | |List| with only the line {lnum} is returned. See |
| 3721 | `getbufoneline()` for only getting the line. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3722 | |
| 3723 | For the use of {buf}, see |bufname()| above. |
| 3724 | |
| 3725 | For {lnum} and {end} "$" can be used for the last line of the |
| 3726 | buffer. Otherwise a number must be used. |
| 3727 | |
| 3728 | When {lnum} is smaller than 1 or bigger than the number of |
| 3729 | lines in the buffer, an empty |List| is returned. |
| 3730 | |
| 3731 | When {end} is greater than the number of lines in the buffer, |
| 3732 | it is treated as {end} is set to the number of lines in the |
| 3733 | buffer. When {end} is before {lnum} an empty |List| is |
| 3734 | returned. |
| 3735 | |
| 3736 | This function works only for loaded buffers. For unloaded and |
| 3737 | non-existing buffers, an empty |List| is returned. |
| 3738 | |
| 3739 | Example: > |
| 3740 | :let lines = getbufline(bufnr("myfile"), 1, "$") |
| 3741 | |
| 3742 | < Can also be used as a |method|: > |
| 3743 | GetBufnr()->getbufline(lnum) |
Bram Moolenaar | ce30ccc | 2022-11-21 19:57:04 +0000 | [diff] [blame] | 3744 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 3745 | Return type: list<string> |
| 3746 | |
Bram Moolenaar | ce30ccc | 2022-11-21 19:57:04 +0000 | [diff] [blame] | 3747 | *getbufoneline()* |
| 3748 | getbufoneline({buf}, {lnum}) |
| 3749 | Just like `getbufline()` but only get one line and return it |
| 3750 | as a string. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3751 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 3752 | Return type: |String| |
| 3753 | |
| 3754 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3755 | getbufvar({buf}, {varname} [, {def}]) *getbufvar()* |
| 3756 | The result is the value of option or local buffer variable |
| 3757 | {varname} in buffer {buf}. Note that the name without "b:" |
| 3758 | must be used. |
| 3759 | The {varname} argument is a string. |
| 3760 | When {varname} is empty returns a |Dictionary| with all the |
| 3761 | buffer-local variables. |
| 3762 | When {varname} is equal to "&" returns a |Dictionary| with all |
| 3763 | the buffer-local options. |
| 3764 | Otherwise, when {varname} starts with "&" returns the value of |
| 3765 | a buffer-local option. |
| 3766 | This also works for a global or buffer-local option, but it |
| 3767 | doesn't work for a global variable, window-local variable or |
| 3768 | window-local option. |
| 3769 | For the use of {buf}, see |bufname()| above. |
| 3770 | When the buffer or variable doesn't exist {def} or an empty |
| 3771 | string is returned, there is no error message. |
| 3772 | Examples: > |
| 3773 | :let bufmodified = getbufvar(1, "&mod") |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 3774 | :echo "todo myvar = " .. getbufvar("todo", "myvar") |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3775 | |
| 3776 | < Can also be used as a |method|: > |
| 3777 | GetBufnr()->getbufvar(varname) |
| 3778 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 3779 | Return type: any, depending on {varname} |
| 3780 | |
| 3781 | |
Kota Kato | 66bb9ae | 2023-01-17 18:31:56 +0000 | [diff] [blame] | 3782 | getcellwidths() *getcellwidths()* |
| 3783 | Returns a |List| of cell widths of character ranges overridden |
| 3784 | by |setcellwidths()|. The format is equal to the argument of |
| 3785 | |setcellwidths()|. If no character ranges have their cell |
| 3786 | widths overridden, an empty List is returned. |
h-east | 84ac212 | 2024-06-17 18:12:30 +0200 | [diff] [blame] | 3787 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 3788 | Return type: list<any> |
Kota Kato | 66bb9ae | 2023-01-17 18:31:56 +0000 | [diff] [blame] | 3789 | |
| 3790 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3791 | getchangelist([{buf}]) *getchangelist()* |
| 3792 | Returns the |changelist| for the buffer {buf}. For the use |
| 3793 | of {buf}, see |bufname()| above. If buffer {buf} doesn't |
| 3794 | exist, an empty list is returned. |
| 3795 | |
| 3796 | The returned list contains two entries: a list with the change |
| 3797 | locations and the current position in the list. Each |
| 3798 | entry in the change list is a dictionary with the following |
| 3799 | entries: |
| 3800 | col column number |
| 3801 | coladd column offset for 'virtualedit' |
| 3802 | lnum line number |
| 3803 | If buffer {buf} is the current buffer, then the current |
| 3804 | position refers to the position in the list. For other |
| 3805 | buffers, it is set to the length of the list. |
| 3806 | |
| 3807 | Can also be used as a |method|: > |
| 3808 | GetBufnr()->getchangelist() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 3809 | < |
| 3810 | Return type: list<any> |
| 3811 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3812 | |
Doug Kearns | 9cd9e75 | 2024-04-07 17:42:17 +0200 | [diff] [blame] | 3813 | getchar([{expr}]) *getchar()* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3814 | Get a single character from the user or input stream. |
Doug Kearns | 9cd9e75 | 2024-04-07 17:42:17 +0200 | [diff] [blame] | 3815 | If {expr} is omitted, wait until a character is available. |
| 3816 | If {expr} is 0, only get a character when one is available. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3817 | Return zero otherwise. |
Doug Kearns | 9cd9e75 | 2024-04-07 17:42:17 +0200 | [diff] [blame] | 3818 | If {expr} is 1, only check if a character is available, it is |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3819 | not consumed. Return zero if no character available. |
| 3820 | If you prefer always getting a string use |getcharstr()|. |
| 3821 | |
Doug Kearns | 9cd9e75 | 2024-04-07 17:42:17 +0200 | [diff] [blame] | 3822 | Without {expr} and when {expr} is 0 a whole character or |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3823 | special key is returned. If it is a single character, the |
Bram Moolenaar | 2d8ed02 | 2022-05-21 13:08:16 +0100 | [diff] [blame] | 3824 | result is a Number. Use |nr2char()| to convert it to a String. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3825 | Otherwise a String is returned with the encoded character. |
| 3826 | For a special key it's a String with a sequence of bytes |
| 3827 | starting with 0x80 (decimal: 128). This is the same value as |
| 3828 | the String "\<Key>", e.g., "\<Left>". The returned value is |
| 3829 | also a String when a modifier (shift, control, alt) was used |
| 3830 | that is not included in the character. |
| 3831 | |
Doug Kearns | 9cd9e75 | 2024-04-07 17:42:17 +0200 | [diff] [blame] | 3832 | When {expr} is 0 and Esc is typed, there will be a short delay |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3833 | while Vim waits to see if this is the start of an escape |
| 3834 | sequence. |
| 3835 | |
Doug Kearns | 9cd9e75 | 2024-04-07 17:42:17 +0200 | [diff] [blame] | 3836 | When {expr} is 1 only the first byte is returned. For a |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3837 | one-byte character it is the character itself as a number. |
| 3838 | Use nr2char() to convert it to a String. |
| 3839 | |
| 3840 | Use getcharmod() to obtain any additional modifiers. |
| 3841 | |
| 3842 | When the user clicks a mouse button, the mouse event will be |
| 3843 | returned. The position can then be found in |v:mouse_col|, |
| 3844 | |v:mouse_lnum|, |v:mouse_winid| and |v:mouse_win|. |
| 3845 | |getmousepos()| can also be used. Mouse move events will be |
| 3846 | ignored. |
| 3847 | This example positions the mouse as it would normally happen: > |
| 3848 | let c = getchar() |
| 3849 | if c == "\<LeftMouse>" && v:mouse_win > 0 |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 3850 | exe v:mouse_win .. "wincmd w" |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3851 | exe v:mouse_lnum |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 3852 | exe "normal " .. v:mouse_col .. "|" |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3853 | endif |
| 3854 | < |
| 3855 | When using bracketed paste only the first character is |
| 3856 | returned, the rest of the pasted text is dropped. |
| 3857 | |xterm-bracketed-paste|. |
| 3858 | |
| 3859 | There is no prompt, you will somehow have to make clear to the |
| 3860 | user that a character has to be typed. The screen is not |
| 3861 | redrawn, e.g. when resizing the window. When using a popup |
| 3862 | window it should work better with a |popup-filter|. |
| 3863 | |
| 3864 | There is no mapping for the character. |
| 3865 | Key codes are replaced, thus when the user presses the <Del> |
| 3866 | key you get the code for the <Del> key, not the raw character |
| 3867 | sequence. Examples: > |
| 3868 | getchar() == "\<Del>" |
| 3869 | getchar() == "\<S-Left>" |
| 3870 | < This example redefines "f" to ignore case: > |
| 3871 | :nmap f :call FindChar()<CR> |
| 3872 | :function FindChar() |
| 3873 | : let c = nr2char(getchar()) |
| 3874 | : while col('.') < col('$') - 1 |
| 3875 | : normal l |
| 3876 | : if getline('.')[col('.') - 1] ==? c |
| 3877 | : break |
| 3878 | : endif |
| 3879 | : endwhile |
| 3880 | :endfunction |
| 3881 | < |
| 3882 | You may also receive synthetic characters, such as |
| 3883 | |<CursorHold>|. Often you will want to ignore this and get |
| 3884 | another character: > |
| 3885 | :function GetKey() |
| 3886 | : let c = getchar() |
| 3887 | : while c == "\<CursorHold>" |
| 3888 | : let c = getchar() |
| 3889 | : endwhile |
| 3890 | : return c |
| 3891 | :endfunction |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 3892 | < |
| 3893 | Return type: |Number| or |String| |
| 3894 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3895 | |
| 3896 | getcharmod() *getcharmod()* |
| 3897 | The result is a Number which is the state of the modifiers for |
| 3898 | the last obtained character with getchar() or in another way. |
| 3899 | These values are added together: |
| 3900 | 2 shift |
| 3901 | 4 control |
| 3902 | 8 alt (meta) |
| 3903 | 16 meta (when it's different from ALT) |
| 3904 | 32 mouse double click |
| 3905 | 64 mouse triple click |
| 3906 | 96 mouse quadruple click (== 32 + 64) |
Casey Tucker | 92e90a1 | 2024-01-25 22:44:00 +0100 | [diff] [blame] | 3907 | 128 command (Mac) or super (GTK) |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3908 | Only the modifiers that have not been included in the |
| 3909 | character itself are obtained. Thus Shift-a results in "A" |
Bram Moolenaar | 016188f | 2022-06-06 20:52:59 +0100 | [diff] [blame] | 3910 | without a modifier. Returns 0 if no modifiers are used. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3911 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 3912 | Return type: |Number| |
| 3913 | |
| 3914 | |
| 3915 | getcharpos({expr}) *getcharpos()* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3916 | Get the position for String {expr}. Same as |getpos()| but the |
| 3917 | column number in the returned List is a character index |
| 3918 | instead of a byte index. |
naohiro ono | 56200ee | 2022-01-01 14:59:44 +0000 | [diff] [blame] | 3919 | If |getpos()| returns a very large column number, equal to |
| 3920 | |v:maxcol|, then getcharpos() will return the character index |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3921 | of the last character. |
| 3922 | |
| 3923 | Example: |
| 3924 | With the cursor on '세' in line 5 with text "여보세요": > |
| 3925 | getcharpos('.') returns [0, 5, 3, 0] |
| 3926 | getpos('.') returns [0, 5, 7, 0] |
| 3927 | < |
| 3928 | Can also be used as a |method|: > |
| 3929 | GetMark()->getcharpos() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 3930 | < |
| 3931 | Return type: list<number> |
| 3932 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3933 | |
| 3934 | getcharsearch() *getcharsearch()* |
| 3935 | Return the current character search information as a {dict} |
| 3936 | with the following entries: |
| 3937 | |
| 3938 | char character previously used for a character |
| 3939 | search (|t|, |f|, |T|, or |F|); empty string |
| 3940 | if no character search has been performed |
| 3941 | forward direction of character search; 1 for forward, |
| 3942 | 0 for backward |
| 3943 | until type of character search; 1 for a |t| or |T| |
| 3944 | character search, 0 for an |f| or |F| |
| 3945 | character search |
| 3946 | |
| 3947 | This can be useful to always have |;| and |,| search |
| 3948 | forward/backward regardless of the direction of the previous |
| 3949 | character search: > |
| 3950 | :nnoremap <expr> ; getcharsearch().forward ? ';' : ',' |
| 3951 | :nnoremap <expr> , getcharsearch().forward ? ',' : ';' |
| 3952 | < Also see |setcharsearch()|. |
| 3953 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 3954 | Return type: dict<any> |
| 3955 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3956 | |
Doug Kearns | 9cd9e75 | 2024-04-07 17:42:17 +0200 | [diff] [blame] | 3957 | getcharstr([{expr}]) *getcharstr()* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3958 | Get a single character from the user or input stream as a |
| 3959 | string. |
Doug Kearns | 9cd9e75 | 2024-04-07 17:42:17 +0200 | [diff] [blame] | 3960 | If {expr} is omitted, wait until a character is available. |
| 3961 | If {expr} is 0 or false, only get a character when one is |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3962 | available. Return an empty string otherwise. |
Doug Kearns | 9cd9e75 | 2024-04-07 17:42:17 +0200 | [diff] [blame] | 3963 | If {expr} is 1 or true, only check if a character is |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3964 | available, it is not consumed. Return an empty string |
| 3965 | if no character is available. |
| 3966 | Otherwise this works like |getchar()|, except that a number |
| 3967 | result is converted to a string. |
| 3968 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 3969 | Return type: |String| |
| 3970 | |
| 3971 | |
Shougo Matsushita | 79d599b | 2022-05-07 12:48:29 +0100 | [diff] [blame] | 3972 | getcmdcompltype() *getcmdcompltype()* |
| 3973 | Return the type of the current command-line completion. |
| 3974 | Only works when the command line is being edited, thus |
| 3975 | requires use of |c_CTRL-\_e| or |c_CTRL-R_=|. |
Bram Moolenaar | 921bde8 | 2022-05-09 19:50:35 +0100 | [diff] [blame] | 3976 | See |:command-completion| for the return string. |
Shougo Matsushita | 07ea5f1 | 2022-08-27 12:22:25 +0100 | [diff] [blame] | 3977 | Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()| and |
| 3978 | |setcmdline()|. |
Shougo Matsushita | 79d599b | 2022-05-07 12:48:29 +0100 | [diff] [blame] | 3979 | Returns an empty string when completion is not defined. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3980 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 3981 | Return type: |String| |
| 3982 | |
| 3983 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3984 | getcmdline() *getcmdline()* |
| 3985 | Return the current command-line. Only works when the command |
| 3986 | line is being edited, thus requires use of |c_CTRL-\_e| or |
| 3987 | |c_CTRL-R_=|. |
| 3988 | Example: > |
| 3989 | :cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR> |
Shougo Matsushita | 07ea5f1 | 2022-08-27 12:22:25 +0100 | [diff] [blame] | 3990 | < Also see |getcmdtype()|, |getcmdpos()|, |setcmdpos()| and |
| 3991 | |setcmdline()|. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3992 | Returns an empty string when entering a password or using |
| 3993 | |inputsecret()|. |
| 3994 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 3995 | Return type: |String| |
| 3996 | |
| 3997 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 3998 | getcmdpos() *getcmdpos()* |
| 3999 | Return the position of the cursor in the command line as a |
| 4000 | byte count. The first column is 1. |
| 4001 | Only works when editing the command line, thus requires use of |
| 4002 | |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping. |
| 4003 | Returns 0 otherwise. |
Shougo Matsushita | 07ea5f1 | 2022-08-27 12:22:25 +0100 | [diff] [blame] | 4004 | Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()| and |
| 4005 | |setcmdline()|. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4006 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 4007 | Return type: |Number| |
| 4008 | |
| 4009 | |
Shougo Matsushita | 79d599b | 2022-05-07 12:48:29 +0100 | [diff] [blame] | 4010 | getcmdscreenpos() *getcmdscreenpos()* |
| 4011 | Return the screen position of the cursor in the command line |
| 4012 | as a byte count. The first column is 1. |
| 4013 | Instead of |getcmdpos()|, it adds the prompt position. |
| 4014 | Only works when editing the command line, thus requires use of |
| 4015 | |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping. |
| 4016 | Returns 0 otherwise. |
Shougo Matsushita | 07ea5f1 | 2022-08-27 12:22:25 +0100 | [diff] [blame] | 4017 | Also see |getcmdpos()|, |setcmdpos()|, |getcmdline()| and |
| 4018 | |setcmdline()|. |
Shougo Matsushita | 79d599b | 2022-05-07 12:48:29 +0100 | [diff] [blame] | 4019 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 4020 | Return type: |Number| |
| 4021 | |
| 4022 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4023 | getcmdtype() *getcmdtype()* |
| 4024 | Return the current command-line type. Possible return values |
| 4025 | are: |
| 4026 | : normal Ex command |
| 4027 | > debug mode command |debug-mode| |
| 4028 | / forward search command |
| 4029 | ? backward search command |
| 4030 | @ |input()| command |
| 4031 | - |:insert| or |:append| command |
| 4032 | = |i_CTRL-R_=| |
| 4033 | Only works when editing the command line, thus requires use of |
| 4034 | |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping. |
| 4035 | Returns an empty string otherwise. |
| 4036 | Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|. |
| 4037 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 4038 | Return type: |String| |
| 4039 | |
| 4040 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4041 | getcmdwintype() *getcmdwintype()* |
| 4042 | Return the current |command-line-window| type. Possible return |
| 4043 | values are the same as |getcmdtype()|. Returns an empty string |
| 4044 | when not in the command-line window. |
| 4045 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 4046 | Return type: |String| |
| 4047 | |
| 4048 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4049 | getcompletion({pat}, {type} [, {filtered}]) *getcompletion()* |
| 4050 | Return a list of command-line completion matches. The String |
| 4051 | {type} argument specifies what for. The following completion |
| 4052 | types are supported: |
| 4053 | |
| 4054 | arglist file names in argument list |
| 4055 | augroup autocmd groups |
| 4056 | buffer buffer names |
Bram Moolenaar | 6e2e2cc | 2022-03-14 19:24:46 +0000 | [diff] [blame] | 4057 | behave |:behave| suboptions |
| 4058 | breakpoint |:breakadd| and |:breakdel| suboptions |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4059 | color color schemes |
| 4060 | command Ex command |
| 4061 | cmdline |cmdline-completion| result |
| 4062 | compiler compilers |
| 4063 | cscope |:cscope| suboptions |
Shougo Matsushita | 92997dd | 2023-08-20 20:55:55 +0200 | [diff] [blame] | 4064 | custom,{func} custom completion, defined via {func} |
| 4065 | customlist,{func} custom completion, defined via {func} |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4066 | diff_buffer |:diffget| and |:diffput| completion |
| 4067 | dir directory names |
LemonBoy | a20bf69 | 2024-07-11 22:35:53 +0200 | [diff] [blame] | 4068 | dir_in_path directory names in |'cdpath'| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4069 | environment environment variable names |
| 4070 | event autocommand events |
| 4071 | expression Vim expression |
| 4072 | file file and directory names |
| 4073 | file_in_path file and directory names in |'path'| |
| 4074 | filetype filetype names |'filetype'| |
| 4075 | function function name |
| 4076 | help help subjects |
| 4077 | highlight highlight groups |
Bram Moolenaar | 6e2e2cc | 2022-03-14 19:24:46 +0000 | [diff] [blame] | 4078 | history |:history| suboptions |
Doug Kearns | 81642d9 | 2024-01-04 22:37:44 +0100 | [diff] [blame] | 4079 | keymap keyboard mappings |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4080 | locale locale names (as output of locale -a) |
| 4081 | mapclear buffer argument |
| 4082 | mapping mapping name |
| 4083 | menu menus |
| 4084 | messages |:messages| suboptions |
| 4085 | option options |
| 4086 | packadd optional package |pack-add| names |
zeertzjq | 5c8771b | 2023-01-24 12:34:03 +0000 | [diff] [blame] | 4087 | runtime |:runtime| completion |
Yegappan Lakshmanan | 454ce67 | 2022-03-24 11:22:13 +0000 | [diff] [blame] | 4088 | scriptnames sourced script names |:scriptnames| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4089 | shellcmd Shell command |
| 4090 | sign |:sign| suboptions |
| 4091 | syntax syntax file names |'syntax'| |
| 4092 | syntime |:syntime| suboptions |
| 4093 | tag tags |
| 4094 | tag_listfiles tags, file names |
| 4095 | user user names |
| 4096 | var user variables |
| 4097 | |
| 4098 | If {pat} is an empty string, then all the matches are |
| 4099 | returned. Otherwise only items matching {pat} are returned. |
| 4100 | See |wildcards| for the use of special characters in {pat}. |
| 4101 | |
| 4102 | If the optional {filtered} flag is set to 1, then 'wildignore' |
| 4103 | is applied to filter the results. Otherwise all the matches |
| 4104 | are returned. The 'wildignorecase' option always applies. |
| 4105 | |
Yegappan Lakshmanan | e7dd0fa | 2022-03-22 16:06:31 +0000 | [diff] [blame] | 4106 | If the 'wildoptions' option contains 'fuzzy', then fuzzy |
| 4107 | matching is used to get the completion matches. Otherwise |
Yegappan Lakshmanan | 454ce67 | 2022-03-24 11:22:13 +0000 | [diff] [blame] | 4108 | regular expression matching is used. Thus this function |
| 4109 | follows the user preference, what happens on the command line. |
| 4110 | If you do not want this you can make 'wildoptions' empty |
| 4111 | before calling getcompletion() and restore it afterwards. |
Yegappan Lakshmanan | e7dd0fa | 2022-03-22 16:06:31 +0000 | [diff] [blame] | 4112 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4113 | If {type} is "cmdline", then the |cmdline-completion| result is |
| 4114 | returned. For example, to complete the possible values after |
| 4115 | a ":call" command: > |
| 4116 | echo getcompletion('call ', 'cmdline') |
| 4117 | < |
| 4118 | If there are no matches, an empty list is returned. An |
| 4119 | invalid value for {type} produces an error. |
| 4120 | |
| 4121 | Can also be used as a |method|: > |
| 4122 | GetPattern()->getcompletion('color') |
| 4123 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 4124 | Return type: list<string> |
| 4125 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4126 | *getcurpos()* |
| 4127 | getcurpos([{winid}]) |
| 4128 | Get the position of the cursor. This is like getpos('.'), but |
| 4129 | includes an extra "curswant" item in the list: |
| 4130 | [0, lnum, col, off, curswant] ~ |
| 4131 | The "curswant" number is the preferred column when moving the |
naohiro ono | 56200ee | 2022-01-01 14:59:44 +0000 | [diff] [blame] | 4132 | cursor vertically. After |$| command it will be a very large |
| 4133 | number equal to |v:maxcol|. Also see |getcursorcharpos()| and |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4134 | |getpos()|. |
| 4135 | The first "bufnum" item is always zero. The byte position of |
| 4136 | the cursor is returned in 'col'. To get the character |
| 4137 | position, use |getcursorcharpos()|. |
| 4138 | |
| 4139 | The optional {winid} argument can specify the window. It can |
| 4140 | be the window number or the |window-ID|. The last known |
| 4141 | cursor position is returned, this may be invalid for the |
| 4142 | current value of the buffer if it is not the current window. |
| 4143 | If {winid} is invalid a list with zeroes is returned. |
| 4144 | |
| 4145 | This can be used to save and restore the cursor position: > |
| 4146 | let save_cursor = getcurpos() |
| 4147 | MoveTheCursorAround |
| 4148 | call setpos('.', save_cursor) |
| 4149 | < Note that this only works within the window. See |
| 4150 | |winrestview()| for restoring more state. |
| 4151 | |
| 4152 | Can also be used as a |method|: > |
| 4153 | GetWinid()->getcurpos() |
| 4154 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 4155 | Return type: list<number> |
| 4156 | |
| 4157 | |
| 4158 | getcursorcharpos([{winid}]) *getcursorcharpos()* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4159 | Same as |getcurpos()| but the column number in the returned |
| 4160 | List is a character index instead of a byte index. |
| 4161 | |
| 4162 | Example: |
| 4163 | With the cursor on '보' in line 3 with text "여보세요": > |
| 4164 | getcursorcharpos() returns [0, 3, 2, 0, 3] |
| 4165 | getcurpos() returns [0, 3, 4, 0, 3] |
| 4166 | < |
| 4167 | Can also be used as a |method|: > |
| 4168 | GetWinid()->getcursorcharpos() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 4169 | < |
| 4170 | Return type: list<number> |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4171 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 4172 | |
| 4173 | getcwd([{winnr} [, {tabnr}]]) *getcwd()* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4174 | The result is a String, which is the name of the current |
| 4175 | working directory. 'autochdir' is ignored. |
| 4176 | |
| 4177 | With {winnr} return the local current directory of this window |
| 4178 | in the current tab page. {winnr} can be the window number or |
| 4179 | the |window-ID|. |
| 4180 | If {winnr} is -1 return the name of the global working |
| 4181 | directory. See also |haslocaldir()|. |
| 4182 | |
| 4183 | With {winnr} and {tabnr} return the local current directory of |
| 4184 | the window in the specified tab page. If {winnr} is -1 return |
| 4185 | the working directory of the tabpage. |
| 4186 | If {winnr} is zero use the current window, if {tabnr} is zero |
| 4187 | use the current tabpage. |
| 4188 | Without any arguments, return the actual working directory of |
| 4189 | the current window. |
| 4190 | Return an empty string if the arguments are invalid. |
| 4191 | |
| 4192 | Examples: > |
| 4193 | " Get the working directory of the current window |
| 4194 | :echo getcwd() |
| 4195 | :echo getcwd(0) |
| 4196 | :echo getcwd(0, 0) |
| 4197 | " Get the working directory of window 3 in tabpage 2 |
| 4198 | :echo getcwd(3, 2) |
| 4199 | " Get the global working directory |
| 4200 | :echo getcwd(-1) |
| 4201 | " Get the working directory of tabpage 3 |
| 4202 | :echo getcwd(-1, 3) |
| 4203 | " Get the working directory of current tabpage |
| 4204 | :echo getcwd(-1, 0) |
| 4205 | |
| 4206 | < Can also be used as a |method|: > |
| 4207 | GetWinnr()->getcwd() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 4208 | < |
| 4209 | Return type: |String| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4210 | |
| 4211 | getenv({name}) *getenv()* |
| 4212 | Return the value of environment variable {name}. The {name} |
| 4213 | argument is a string, without a leading '$'. Example: > |
| 4214 | myHome = getenv('HOME') |
| 4215 | |
| 4216 | < When the variable does not exist |v:null| is returned. That |
| 4217 | is different from a variable set to an empty string, although |
| 4218 | some systems interpret the empty value as the variable being |
| 4219 | deleted. See also |expr-env|. |
| 4220 | |
| 4221 | Can also be used as a |method|: > |
| 4222 | GetVarname()->getenv() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 4223 | < |
| 4224 | Return type: |String| or |Number| |
| 4225 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4226 | |
| 4227 | getfontname([{name}]) *getfontname()* |
| 4228 | Without an argument returns the name of the normal font being |
| 4229 | used. Like what is used for the Normal highlight group |
| 4230 | |hl-Normal|. |
| 4231 | With an argument a check is done whether String {name} is a |
| 4232 | valid font name. If not then an empty string is returned. |
| 4233 | Otherwise the actual font name is returned, or {name} if the |
| 4234 | GUI does not support obtaining the real name. |
| 4235 | Only works when the GUI is running, thus not in your vimrc or |
| 4236 | gvimrc file. Use the |GUIEnter| autocommand to use this |
| 4237 | function just after the GUI has started. |
| 4238 | Note that the GTK GUI accepts any font name, thus checking for |
| 4239 | a valid name does not work. |
| 4240 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 4241 | Return type: |String| |
| 4242 | |
| 4243 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4244 | getfperm({fname}) *getfperm()* |
| 4245 | The result is a String, which is the read, write, and execute |
| 4246 | permissions of the given file {fname}. |
| 4247 | If {fname} does not exist or its directory cannot be read, an |
| 4248 | empty string is returned. |
| 4249 | The result is of the form "rwxrwxrwx", where each group of |
| 4250 | "rwx" flags represent, in turn, the permissions of the owner |
| 4251 | of the file, the group the file belongs to, and other users. |
| 4252 | If a user does not have a given permission the flag for this |
| 4253 | is replaced with the string "-". Examples: > |
| 4254 | :echo getfperm("/etc/passwd") |
| 4255 | :echo getfperm(expand("~/.vimrc")) |
| 4256 | < This will hopefully (from a security point of view) display |
| 4257 | the string "rw-r--r--" or even "rw-------". |
| 4258 | |
| 4259 | Can also be used as a |method|: > |
| 4260 | GetFilename()->getfperm() |
| 4261 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 4262 | Return type: |String| |
| 4263 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4264 | For setting permissions use |setfperm()|. |
| 4265 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 4266 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4267 | getfsize({fname}) *getfsize()* |
| 4268 | The result is a Number, which is the size in bytes of the |
| 4269 | given file {fname}. |
| 4270 | If {fname} is a directory, 0 is returned. |
| 4271 | If the file {fname} can't be found, -1 is returned. |
| 4272 | If the size of {fname} is too big to fit in a Number then -2 |
| 4273 | is returned. |
| 4274 | |
| 4275 | Can also be used as a |method|: > |
| 4276 | GetFilename()->getfsize() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 4277 | < |
| 4278 | Return type: |Number| |
| 4279 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4280 | |
| 4281 | getftime({fname}) *getftime()* |
| 4282 | The result is a Number, which is the last modification time of |
| 4283 | the given file {fname}. The value is measured as seconds |
| 4284 | since 1st Jan 1970, and may be passed to strftime(). See also |
| 4285 | |localtime()| and |strftime()|. |
| 4286 | If the file {fname} can't be found -1 is returned. |
| 4287 | |
| 4288 | Can also be used as a |method|: > |
| 4289 | GetFilename()->getftime() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 4290 | < |
| 4291 | Return type: |Number| |
| 4292 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4293 | |
| 4294 | getftype({fname}) *getftype()* |
| 4295 | The result is a String, which is a description of the kind of |
| 4296 | file of the given file {fname}. |
| 4297 | If {fname} does not exist an empty string is returned. |
| 4298 | Here is a table over different kinds of files and their |
| 4299 | results: |
| 4300 | Normal file "file" |
| 4301 | Directory "dir" |
| 4302 | Symbolic link "link" |
| 4303 | Block device "bdev" |
| 4304 | Character device "cdev" |
| 4305 | Socket "socket" |
| 4306 | FIFO "fifo" |
| 4307 | All other "other" |
| 4308 | Example: > |
| 4309 | getftype("/home") |
| 4310 | < Note that a type such as "link" will only be returned on |
| 4311 | systems that support it. On some systems only "dir" and |
| 4312 | "file" are returned. On MS-Windows a symbolic link to a |
| 4313 | directory returns "dir" instead of "link". |
| 4314 | |
| 4315 | Can also be used as a |method|: > |
| 4316 | GetFilename()->getftype() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 4317 | < |
| 4318 | Return type: |String| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4319 | |
| 4320 | getimstatus() *getimstatus()* |
| 4321 | The result is a Number, which is |TRUE| when the IME status is |
Bram Moolenaar | 016188f | 2022-06-06 20:52:59 +0100 | [diff] [blame] | 4322 | active and |FALSE| otherwise. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4323 | See 'imstatusfunc'. |
| 4324 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 4325 | Return type: |Number| |
| 4326 | |
| 4327 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4328 | getjumplist([{winnr} [, {tabnr}]]) *getjumplist()* |
| 4329 | Returns the |jumplist| for the specified window. |
| 4330 | |
| 4331 | Without arguments use the current window. |
| 4332 | With {winnr} only use this window in the current tab page. |
| 4333 | {winnr} can also be a |window-ID|. |
| 4334 | With {winnr} and {tabnr} use the window in the specified tab |
Bram Moolenaar | 016188f | 2022-06-06 20:52:59 +0100 | [diff] [blame] | 4335 | page. If {winnr} or {tabnr} is invalid, an empty list is |
| 4336 | returned. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4337 | |
| 4338 | The returned list contains two entries: a list with the jump |
| 4339 | locations and the last used jump position number in the list. |
| 4340 | Each entry in the jump location list is a dictionary with |
| 4341 | the following entries: |
| 4342 | bufnr buffer number |
| 4343 | col column number |
| 4344 | coladd column offset for 'virtualedit' |
| 4345 | filename filename if available |
| 4346 | lnum line number |
| 4347 | |
| 4348 | Can also be used as a |method|: > |
| 4349 | GetWinnr()->getjumplist() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 4350 | < |
| 4351 | Return type: list<any> |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4352 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 4353 | *getline()* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4354 | getline({lnum} [, {end}]) |
| 4355 | Without {end} the result is a String, which is line {lnum} |
| 4356 | from the current buffer. Example: > |
| 4357 | getline(1) |
| 4358 | < When {lnum} is a String that doesn't start with a |
| 4359 | digit, |line()| is called to translate the String into a Number. |
| 4360 | To get the line under the cursor: > |
| 4361 | getline(".") |
| 4362 | < When {lnum} is a number smaller than 1 or bigger than the |
| 4363 | number of lines in the buffer, an empty string is returned. |
| 4364 | |
| 4365 | When {end} is given the result is a |List| where each item is |
| 4366 | a line from the current buffer in the range {lnum} to {end}, |
| 4367 | including line {end}. |
| 4368 | {end} is used in the same way as {lnum}. |
| 4369 | Non-existing lines are silently omitted. |
| 4370 | When {end} is before {lnum} an empty |List| is returned. |
| 4371 | Example: > |
| 4372 | :let start = line('.') |
| 4373 | :let end = search("^$") - 1 |
| 4374 | :let lines = getline(start, end) |
| 4375 | |
| 4376 | < Can also be used as a |method|: > |
| 4377 | ComputeLnum()->getline() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 4378 | < |
| 4379 | Return type: list<string> or |String| depending on {end} |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4380 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 4381 | To get lines from another buffer see |getbufline()| and |
Bram Moolenaar | ce30ccc | 2022-11-21 19:57:04 +0000 | [diff] [blame] | 4382 | |getbufoneline()| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4383 | |
| 4384 | getloclist({nr} [, {what}]) *getloclist()* |
| 4385 | Returns a |List| with all the entries in the location list for |
| 4386 | window {nr}. {nr} can be the window number or the |window-ID|. |
| 4387 | When {nr} is zero the current window is used. |
| 4388 | |
| 4389 | For a location list window, the displayed location list is |
| 4390 | returned. For an invalid window number {nr}, an empty list is |
| 4391 | returned. Otherwise, same as |getqflist()|. |
| 4392 | |
| 4393 | If the optional {what} dictionary argument is supplied, then |
| 4394 | returns the items listed in {what} as a dictionary. Refer to |
| 4395 | |getqflist()| for the supported items in {what}. |
| 4396 | |
| 4397 | In addition to the items supported by |getqflist()| in {what}, |
| 4398 | the following item is supported by |getloclist()|: |
| 4399 | |
| 4400 | filewinid id of the window used to display files |
| 4401 | from the location list. This field is |
| 4402 | applicable only when called from a |
| 4403 | location list window. See |
| 4404 | |location-list-file-window| for more |
| 4405 | details. |
| 4406 | |
| 4407 | Returns a |Dictionary| with default values if there is no |
| 4408 | location list for the window {nr}. |
| 4409 | Returns an empty Dictionary if window {nr} does not exist. |
| 4410 | |
| 4411 | Examples (See also |getqflist-examples|): > |
| 4412 | :echo getloclist(3, {'all': 0}) |
| 4413 | :echo getloclist(5, {'filewinid': 0}) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 4414 | < |
| 4415 | Return type: list<dict<any>> or list<any> |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4416 | |
| 4417 | |
| 4418 | getmarklist([{buf}]) *getmarklist()* |
| 4419 | Without the {buf} argument returns a |List| with information |
| 4420 | about all the global marks. |mark| |
| 4421 | |
| 4422 | If the optional {buf} argument is specified, returns the |
| 4423 | local marks defined in buffer {buf}. For the use of {buf}, |
Bram Moolenaar | 016188f | 2022-06-06 20:52:59 +0100 | [diff] [blame] | 4424 | see |bufname()|. If {buf} is invalid, an empty list is |
| 4425 | returned. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4426 | |
| 4427 | Each item in the returned List is a |Dict| with the following: |
| 4428 | mark name of the mark prefixed by "'" |
| 4429 | pos a |List| with the position of the mark: |
| 4430 | [bufnum, lnum, col, off] |
| 4431 | Refer to |getpos()| for more information. |
| 4432 | file file name |
| 4433 | |
| 4434 | Refer to |getpos()| for getting information about a specific |
| 4435 | mark. |
| 4436 | |
| 4437 | Can also be used as a |method|: > |
| 4438 | GetBufnr()->getmarklist() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 4439 | < |
| 4440 | Return type: list<dict<any>> or list<any> |
| 4441 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4442 | |
| 4443 | getmatches([{win}]) *getmatches()* |
| 4444 | Returns a |List| with all matches previously defined for the |
| 4445 | current window by |matchadd()| and the |:match| commands. |
| 4446 | |getmatches()| is useful in combination with |setmatches()|, |
| 4447 | as |setmatches()| can restore a list of matches saved by |
| 4448 | |getmatches()|. |
| 4449 | If {win} is specified, use the window with this number or |
Bram Moolenaar | 016188f | 2022-06-06 20:52:59 +0100 | [diff] [blame] | 4450 | window ID instead of the current window. If {win} is invalid, |
| 4451 | an empty list is returned. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4452 | Example: > |
| 4453 | :echo getmatches() |
| 4454 | < [{'group': 'MyGroup1', 'pattern': 'TODO', |
| 4455 | 'priority': 10, 'id': 1}, {'group': 'MyGroup2', |
| 4456 | 'pattern': 'FIXME', 'priority': 10, 'id': 2}] > |
| 4457 | :let m = getmatches() |
| 4458 | :call clearmatches() |
| 4459 | :echo getmatches() |
| 4460 | < [] > |
| 4461 | :call setmatches(m) |
| 4462 | :echo getmatches() |
| 4463 | < [{'group': 'MyGroup1', 'pattern': 'TODO', |
| 4464 | 'priority': 10, 'id': 1}, {'group': 'MyGroup2', |
| 4465 | 'pattern': 'FIXME', 'priority': 10, 'id': 2}] > |
| 4466 | :unlet m |
| 4467 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 4468 | Return type: list<dict<any>> or list<any> |
| 4469 | |
| 4470 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4471 | getmousepos() *getmousepos()* |
| 4472 | Returns a |Dictionary| with the last known position of the |
| 4473 | mouse. This can be used in a mapping for a mouse click or in |
| 4474 | a filter of a popup window. The items are: |
| 4475 | screenrow screen row |
| 4476 | screencol screen column |
| 4477 | winid Window ID of the click |
| 4478 | winrow row inside "winid" |
| 4479 | wincol column inside "winid" |
| 4480 | line text line inside "winid" |
| 4481 | column text column inside "winid" |
zeertzjq | f5a94d5 | 2023-10-15 10:03:30 +0200 | [diff] [blame] | 4482 | coladd offset (in screen columns) from the |
| 4483 | start of the clicked char |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4484 | All numbers are 1-based. |
| 4485 | |
| 4486 | If not over a window, e.g. when in the command line, then only |
| 4487 | "screenrow" and "screencol" are valid, the others are zero. |
| 4488 | |
| 4489 | When on the status line below a window or the vertical |
| 4490 | separator right of a window, the "line" and "column" values |
| 4491 | are zero. |
| 4492 | |
| 4493 | When the position is after the text then "column" is the |
| 4494 | length of the text in bytes plus one. |
| 4495 | |
| 4496 | If the mouse is over a popup window then that window is used. |
| 4497 | |
| 4498 | When using |getchar()| the Vim variables |v:mouse_lnum|, |
| 4499 | |v:mouse_col| and |v:mouse_winid| also provide these values. |
| 4500 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 4501 | Return type: dict<number> |
| 4502 | |
| 4503 | |
Bram Moolenaar | 24dc19c | 2022-11-14 19:49:15 +0000 | [diff] [blame] | 4504 | getmouseshape() *getmouseshape()* |
| 4505 | Returns the name of the currently showing mouse pointer. |
| 4506 | When the |+mouseshape| feature is not supported or the shape |
| 4507 | is unknown an empty string is returned. |
| 4508 | This function is mainly intended for testing. |
| 4509 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 4510 | Return type: |String| |
| 4511 | |
| 4512 | |
| 4513 | getpid() *getpid()* |
| 4514 | Return a Number which is the process ID of the Vim process. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4515 | On Unix and MS-Windows this is a unique number, until Vim |
| 4516 | exits. |
| 4517 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 4518 | Return type: |Number| |
| 4519 | |
| 4520 | |
| 4521 | getpos({expr}) *getpos()* |
zeertzjq | 02f3eba | 2024-06-12 20:45:24 +0200 | [diff] [blame] | 4522 | Get the position for String {expr}. |
| 4523 | The accepted values for {expr} are: *E1209* |
| 4524 | . The cursor position. |
| 4525 | $ The last line in the current buffer. |
| 4526 | 'x Position of mark x (if the mark is not set, 0 is |
zeertzjq | d353d27 | 2024-06-13 23:00:25 +0800 | [diff] [blame] | 4527 | returned for all values). |
zeertzjq | 02f3eba | 2024-06-12 20:45:24 +0200 | [diff] [blame] | 4528 | w0 First line visible in current window (one if the |
| 4529 | display isn't updated, e.g. in silent Ex mode). |
| 4530 | w$ Last line visible in current window (this is one |
| 4531 | less than "w0" if no lines are visible). |
| 4532 | v When not in Visual mode, returns the cursor |
| 4533 | position. In Visual mode, returns the other end |
| 4534 | of the Visual area. A good way to think about |
| 4535 | this is that in Visual mode "v" and "." complement |
| 4536 | each other. While "." refers to the cursor |
| 4537 | position, "v" refers to where |v_o| would move the |
| 4538 | cursor. As a result, you can use "v" and "." |
| 4539 | together to work on all of a selection in |
| 4540 | characterwise Visual mode. If the cursor is at |
| 4541 | the end of a characterwise Visual area, "v" refers |
| 4542 | to the start of the same Visual area. And if the |
| 4543 | cursor is at the start of a characterwise Visual |
| 4544 | area, "v" refers to the end of the same Visual |
| 4545 | area. "v" differs from |'<| and |'>| in that it's |
| 4546 | updated right away. |
| 4547 | Note that a mark in another file can be used. The line number |
| 4548 | then applies to another buffer. |
| 4549 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4550 | The result is a |List| with four numbers: |
| 4551 | [bufnum, lnum, col, off] |
| 4552 | "bufnum" is zero, unless a mark like '0 or 'A is used, then it |
| 4553 | is the buffer number of the mark. |
| 4554 | "lnum" and "col" are the position in the buffer. The first |
| 4555 | column is 1. |
| 4556 | The "off" number is zero, unless 'virtualedit' is used. Then |
| 4557 | it is the offset in screen columns from the start of the |
| 4558 | character. E.g., a position within a <Tab> or after the last |
| 4559 | character. |
zeertzjq | 02f3eba | 2024-06-12 20:45:24 +0200 | [diff] [blame] | 4560 | |
| 4561 | For getting the cursor position see |getcurpos()|. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4562 | The column number in the returned List is the byte position |
| 4563 | within the line. To get the character position in the line, |
| 4564 | use |getcharpos()|. |
zeertzjq | 02f3eba | 2024-06-12 20:45:24 +0200 | [diff] [blame] | 4565 | |
| 4566 | Note that for '< and '> Visual mode matters: when it is "V" |
| 4567 | (visual line mode) the column of '< is zero and the column of |
| 4568 | '> is a large number equal to |v:maxcol|. |
naohiro ono | 56200ee | 2022-01-01 14:59:44 +0000 | [diff] [blame] | 4569 | A very large column number equal to |v:maxcol| can be returned, |
| 4570 | in which case it means "after the end of the line". |
Bram Moolenaar | 016188f | 2022-06-06 20:52:59 +0100 | [diff] [blame] | 4571 | If {expr} is invalid, returns a list with all zeros. |
zeertzjq | 02f3eba | 2024-06-12 20:45:24 +0200 | [diff] [blame] | 4572 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4573 | This can be used to save and restore the position of a mark: > |
| 4574 | let save_a_mark = getpos("'a") |
| 4575 | ... |
| 4576 | call setpos("'a", save_a_mark) |
zeertzjq | d353d27 | 2024-06-13 23:00:25 +0800 | [diff] [blame] | 4577 | < |
| 4578 | Also see |getcharpos()|, |getcurpos()| and |setpos()|. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4579 | |
| 4580 | Can also be used as a |method|: > |
| 4581 | GetMark()->getpos() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 4582 | < |
| 4583 | Return type: list<number> |
| 4584 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4585 | |
| 4586 | getqflist([{what}]) *getqflist()* |
| 4587 | Returns a |List| with all the current quickfix errors. Each |
| 4588 | list item is a dictionary with these entries: |
| 4589 | bufnr number of buffer that has the file name, use |
| 4590 | bufname() to get the name |
| 4591 | module module name |
| 4592 | lnum line number in the buffer (first line is 1) |
| 4593 | end_lnum |
| 4594 | end of line number if the item is multiline |
| 4595 | col column number (first column is 1) |
| 4596 | end_col end of column number if the item has range |
| 4597 | vcol |TRUE|: "col" is visual column |
| 4598 | |FALSE|: "col" is byte index |
| 4599 | nr error number |
h-east | 84ac212 | 2024-06-17 18:12:30 +0200 | [diff] [blame] | 4600 | pattern search pattern used to locate the error |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4601 | text description of the error |
| 4602 | type type of the error, 'E', '1', etc. |
| 4603 | valid |TRUE|: recognized error message |
h_east | 596a9f2 | 2023-11-21 21:24:23 +0900 | [diff] [blame] | 4604 | user_data |
| 4605 | custom data associated with the item, can be |
Tom Praschan | ca6ac99 | 2023-08-11 23:26:12 +0200 | [diff] [blame] | 4606 | any type. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4607 | |
| 4608 | When there is no error list or it's empty, an empty list is |
| 4609 | returned. Quickfix list entries with a non-existing buffer |
| 4610 | number are returned with "bufnr" set to zero (Note: some |
| 4611 | functions accept buffer number zero for the alternate buffer, |
| 4612 | you may need to explicitly check for zero). |
| 4613 | |
| 4614 | Useful application: Find pattern matches in multiple files and |
| 4615 | do something with them: > |
| 4616 | :vimgrep /theword/jg *.c |
| 4617 | :for d in getqflist() |
| 4618 | : echo bufname(d.bufnr) ':' d.lnum '=' d.text |
| 4619 | :endfor |
| 4620 | < |
| 4621 | If the optional {what} dictionary argument is supplied, then |
| 4622 | returns only the items listed in {what} as a dictionary. The |
| 4623 | following string items are supported in {what}: |
| 4624 | changedtick get the total number of changes made |
| 4625 | to the list |quickfix-changedtick| |
| 4626 | context get the |quickfix-context| |
| 4627 | efm errorformat to use when parsing "lines". If |
| 4628 | not present, then the 'errorformat' option |
| 4629 | value is used. |
| 4630 | id get information for the quickfix list with |
| 4631 | |quickfix-ID|; zero means the id for the |
| 4632 | current list or the list specified by "nr" |
| 4633 | idx get information for the quickfix entry at this |
| 4634 | index in the list specified by 'id' or 'nr'. |
| 4635 | If set to zero, then uses the current entry. |
| 4636 | See |quickfix-index| |
| 4637 | items quickfix list entries |
| 4638 | lines parse a list of lines using 'efm' and return |
| 4639 | the resulting entries. Only a |List| type is |
| 4640 | accepted. The current quickfix list is not |
| 4641 | modified. See |quickfix-parse|. |
| 4642 | nr get information for this quickfix list; zero |
| 4643 | means the current quickfix list and "$" means |
| 4644 | the last quickfix list |
| 4645 | qfbufnr number of the buffer displayed in the quickfix |
| 4646 | window. Returns 0 if the quickfix buffer is |
| 4647 | not present. See |quickfix-buffer|. |
| 4648 | size number of entries in the quickfix list |
| 4649 | title get the list title |quickfix-title| |
| 4650 | winid get the quickfix |window-ID| |
| 4651 | all all of the above quickfix properties |
| 4652 | Non-string items in {what} are ignored. To get the value of a |
| 4653 | particular item, set it to zero. |
| 4654 | If "nr" is not present then the current quickfix list is used. |
| 4655 | If both "nr" and a non-zero "id" are specified, then the list |
| 4656 | specified by "id" is used. |
| 4657 | To get the number of lists in the quickfix stack, set "nr" to |
| 4658 | "$" in {what}. The "nr" value in the returned dictionary |
| 4659 | contains the quickfix stack size. |
| 4660 | When "lines" is specified, all the other items except "efm" |
| 4661 | are ignored. The returned dictionary contains the entry |
| 4662 | "items" with the list of entries. |
| 4663 | |
| 4664 | The returned dictionary contains the following entries: |
| 4665 | changedtick total number of changes made to the |
| 4666 | list |quickfix-changedtick| |
| 4667 | context quickfix list context. See |quickfix-context| |
| 4668 | If not present, set to "". |
| 4669 | id quickfix list ID |quickfix-ID|. If not |
| 4670 | present, set to 0. |
| 4671 | idx index of the quickfix entry in the list. If not |
| 4672 | present, set to 0. |
| 4673 | items quickfix list entries. If not present, set to |
| 4674 | an empty list. |
| 4675 | nr quickfix list number. If not present, set to 0 |
| 4676 | qfbufnr number of the buffer displayed in the quickfix |
| 4677 | window. If not present, set to 0. |
| 4678 | size number of entries in the quickfix list. If not |
| 4679 | present, set to 0. |
| 4680 | title quickfix list title text. If not present, set |
| 4681 | to "". |
| 4682 | winid quickfix |window-ID|. If not present, set to 0 |
| 4683 | |
| 4684 | Examples (See also |getqflist-examples|): > |
| 4685 | :echo getqflist({'all': 1}) |
| 4686 | :echo getqflist({'nr': 2, 'title': 1}) |
| 4687 | :echo getqflist({'lines' : ["F1:10:L10"]}) |
| 4688 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 4689 | Return type: list<dict<any>> or list<any> |
| 4690 | |
| 4691 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4692 | getreg([{regname} [, 1 [, {list}]]]) *getreg()* |
| 4693 | The result is a String, which is the contents of register |
| 4694 | {regname}. Example: > |
| 4695 | :let cliptext = getreg('*') |
| 4696 | < When register {regname} was not set the result is an empty |
| 4697 | string. |
Bram Moolenaar | a2baa73 | 2022-02-04 16:09:54 +0000 | [diff] [blame] | 4698 | The {regname} argument must be a string. *E1162* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4699 | |
| 4700 | getreg('=') returns the last evaluated value of the expression |
| 4701 | register. (For use in maps.) |
| 4702 | getreg('=', 1) returns the expression itself, so that it can |
| 4703 | be restored with |setreg()|. For other registers the extra |
| 4704 | argument is ignored, thus you can always give it. |
| 4705 | |
| 4706 | If {list} is present and |TRUE|, the result type is changed |
| 4707 | to |List|. Each list item is one text line. Use it if you care |
| 4708 | about zero bytes possibly present inside register: without |
| 4709 | third argument both NLs and zero bytes are represented as NLs |
| 4710 | (see |NL-used-for-Nul|). |
| 4711 | When the register was not set an empty list is returned. |
| 4712 | |
| 4713 | If {regname} is "", the unnamed register '"' is used. |
| 4714 | If {regname} is not specified, |v:register| is used. |
| 4715 | In |Vim9-script| {regname} must be one character. |
| 4716 | |
| 4717 | Can also be used as a |method|: > |
| 4718 | GetRegname()->getreg() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 4719 | < |
| 4720 | Return type: |String| |
| 4721 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4722 | |
| 4723 | getreginfo([{regname}]) *getreginfo()* |
| 4724 | Returns detailed information about register {regname} as a |
| 4725 | Dictionary with the following entries: |
| 4726 | regcontents List of lines contained in register |
| 4727 | {regname}, like |
| 4728 | |getreg|({regname}, 1, 1). |
| 4729 | regtype the type of register {regname}, as in |
| 4730 | |getregtype()|. |
| 4731 | isunnamed Boolean flag, v:true if this register |
| 4732 | is currently pointed to by the unnamed |
| 4733 | register. |
| 4734 | points_to for the unnamed register, gives the |
| 4735 | single letter name of the register |
| 4736 | currently pointed to (see |quotequote|). |
| 4737 | For example, after deleting a line |
| 4738 | with `dd`, this field will be "1", |
| 4739 | which is the register that got the |
| 4740 | deleted text. |
| 4741 | |
| 4742 | The {regname} argument is a string. If {regname} is invalid |
| 4743 | or not set, an empty Dictionary will be returned. |
| 4744 | If {regname} is "" or "@", the unnamed register '"' is used. |
| 4745 | If {regname} is not specified, |v:register| is used. |
| 4746 | The returned Dictionary can be passed to |setreg()|. |
| 4747 | In |Vim9-script| {regname} must be one character. |
| 4748 | |
| 4749 | Can also be used as a |method|: > |
| 4750 | GetRegname()->getreginfo() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 4751 | < |
| 4752 | Return type: dict<any> |
| 4753 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4754 | |
Shougo Matsushita | 19b7188 | 2024-02-28 22:48:12 +0100 | [diff] [blame] | 4755 | getregion({pos1}, {pos2} [, {opts}]) *getregion()* |
Shougo Matsushita | 84bf6e6 | 2024-03-06 21:10:18 +0100 | [diff] [blame] | 4756 | Returns the list of strings from {pos1} to {pos2} from a |
Shougo Matsushita | 19b7188 | 2024-02-28 22:48:12 +0100 | [diff] [blame] | 4757 | buffer. |
| 4758 | |
| 4759 | {pos1} and {pos2} must both be |List|s with four numbers. |
Shougo Matsushita | 84bf6e6 | 2024-03-06 21:10:18 +0100 | [diff] [blame] | 4760 | See |getpos()| for the format of the list. It's possible |
| 4761 | to specify positions from a different buffer, but please |
zeertzjq | 0df8f93 | 2024-03-07 21:40:53 +0100 | [diff] [blame] | 4762 | note the limitations at |getregion-notes|. |
Shougo Matsushita | 19b7188 | 2024-02-28 22:48:12 +0100 | [diff] [blame] | 4763 | |
| 4764 | The optional argument {opts} is a Dict and supports the |
| 4765 | following items: |
| 4766 | |
zeertzjq | afc2295 | 2024-05-24 19:07:12 +0200 | [diff] [blame] | 4767 | type Specify the region's selection type. |
| 4768 | See |getregtype()| for possible values, |
zeertzjq | dff55a3 | 2024-05-25 10:25:36 +0200 | [diff] [blame] | 4769 | except that the width can be omitted |
| 4770 | and an empty string cannot be used. |
zeertzjq | afc2295 | 2024-05-24 19:07:12 +0200 | [diff] [blame] | 4771 | (default: "v") |
Shougo Matsushita | 19b7188 | 2024-02-28 22:48:12 +0100 | [diff] [blame] | 4772 | |
zeertzjq | 87410ab | 2024-03-02 06:00:23 +0800 | [diff] [blame] | 4773 | exclusive If |TRUE|, use exclusive selection |
zeertzjq | afc2295 | 2024-05-24 19:07:12 +0200 | [diff] [blame] | 4774 | for the end position. |
zeertzjq | 87410ab | 2024-03-02 06:00:23 +0800 | [diff] [blame] | 4775 | (default: follow 'selection') |
Shougo Matsushita | 19b7188 | 2024-02-28 22:48:12 +0100 | [diff] [blame] | 4776 | |
Shougo Matsushita | 3f905ab | 2024-02-21 00:02:45 +0100 | [diff] [blame] | 4777 | You can get the last selection type by |visualmode()|. |
| 4778 | If Visual mode is active, use |mode()| to get the Visual mode |
| 4779 | (e.g., in a |:vmap|). |
zeertzjq | 87410ab | 2024-03-02 06:00:23 +0800 | [diff] [blame] | 4780 | This function is useful to get text starting and ending in |
| 4781 | different columns, such as a |characterwise-visual| selection. |
Shougo Matsushita | 3f905ab | 2024-02-21 00:02:45 +0100 | [diff] [blame] | 4782 | |
Shougo Matsushita | 84bf6e6 | 2024-03-06 21:10:18 +0100 | [diff] [blame] | 4783 | *getregion-notes* |
Shougo Matsushita | 3f905ab | 2024-02-21 00:02:45 +0100 | [diff] [blame] | 4784 | Note that: |
| 4785 | - Order of {pos1} and {pos2} doesn't matter, it will always |
| 4786 | return content from the upper left position to the lower |
| 4787 | right position. |
zeertzjq | 87410ab | 2024-03-02 06:00:23 +0800 | [diff] [blame] | 4788 | - If 'virtualedit' is enabled and the region is past the end |
| 4789 | of the lines, resulting lines are padded with spaces. |
| 4790 | - If the region is blockwise and it starts or ends in the |
| 4791 | middle of a multi-cell character, it is not included but |
| 4792 | its selected part is substituted with spaces. |
Shougo Matsushita | 84bf6e6 | 2024-03-06 21:10:18 +0100 | [diff] [blame] | 4793 | - If {pos1} and {pos2} are not in the same buffer, an empty |
zeertzjq | 421b597 | 2024-02-22 19:48:06 +0100 | [diff] [blame] | 4794 | list is returned. |
Shougo Matsushita | 84bf6e6 | 2024-03-06 21:10:18 +0100 | [diff] [blame] | 4795 | - {pos1} and {pos2} must belong to a |bufloaded()| buffer. |
zeertzjq | 0df8f93 | 2024-03-07 21:40:53 +0100 | [diff] [blame] | 4796 | - It is evaluated in current window context, which makes a |
| 4797 | difference if the buffer is displayed in a window with |
| 4798 | different 'virtualedit' or 'list' values. |
Shougo Matsushita | 3f905ab | 2024-02-21 00:02:45 +0100 | [diff] [blame] | 4799 | |
| 4800 | Examples: > |
| 4801 | :xnoremap <CR> |
Shougo Matsushita | 19b7188 | 2024-02-28 22:48:12 +0100 | [diff] [blame] | 4802 | \ <Cmd>echow getregion( |
| 4803 | \ getpos('v'), getpos('.'), #{ type: mode() })<CR> |
Shougo Matsushita | 3f905ab | 2024-02-21 00:02:45 +0100 | [diff] [blame] | 4804 | < |
| 4805 | Can also be used as a |method|: > |
Shougo Matsushita | 19b7188 | 2024-02-28 22:48:12 +0100 | [diff] [blame] | 4806 | getpos('.')->getregion(getpos("'a")) |
zeertzjq | d4d1207 | 2024-07-16 20:34:16 +0200 | [diff] [blame] | 4807 | < |
| 4808 | Return type: list<string> |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 4809 | |
Shougo Matsushita | 3f905ab | 2024-02-21 00:02:45 +0100 | [diff] [blame] | 4810 | < |
Shougo Matsushita | b4757e6 | 2024-05-07 20:49:24 +0200 | [diff] [blame] | 4811 | getregionpos({pos1}, {pos2} [, {opts}]) *getregionpos()* |
| 4812 | Same as |getregion()|, but returns a list of positions |
| 4813 | describing the buffer text segments bound by {pos1} and |
| 4814 | {pos2}. |
| 4815 | The segments are a pair of positions for every line: > |
| 4816 | [[{start_pos}, {end_pos}], ...] |
| 4817 | < |
| 4818 | The position is a |List| with four numbers: |
| 4819 | [bufnum, lnum, col, off] |
| 4820 | "bufnum" is the buffer number. |
| 4821 | "lnum" and "col" are the position in the buffer. The first |
| 4822 | column is 1. |
zeertzjq | c95e64f | 2024-05-20 14:00:31 +0200 | [diff] [blame] | 4823 | If the "off" number of a starting position is non-zero, it is |
| 4824 | the offset in screen columns from the start of the character. |
| 4825 | E.g., a position within a <Tab> or after the last character. |
| 4826 | If the "off" number of an ending position is non-zero, it is |
zeertzjq | 52a6f34 | 2024-05-22 16:42:44 +0200 | [diff] [blame] | 4827 | the offset of the character's first cell not included in the |
| 4828 | selection, otherwise all its cells are included. |
Shougo Matsushita | b4757e6 | 2024-05-07 20:49:24 +0200 | [diff] [blame] | 4829 | |
zeertzjq | 2b09de9 | 2024-05-24 07:48:51 +0200 | [diff] [blame] | 4830 | Apart from the options supported by |getregion()|, {opts} also |
| 4831 | supports the following: |
| 4832 | |
| 4833 | eol If |TRUE|, indicate positions beyond |
| 4834 | the end of a line with "col" values |
| 4835 | one more than the length of the line. |
| 4836 | If |FALSE|, positions are limited |
| 4837 | within their lines, and if a line is |
| 4838 | empty or the selection is entirely |
| 4839 | beyond the end of a line, a "col" |
| 4840 | value of 0 is used for both positions. |
| 4841 | (default: |FALSE|) |
| 4842 | |
Shougo Matsushita | b4757e6 | 2024-05-07 20:49:24 +0200 | [diff] [blame] | 4843 | Can also be used as a |method|: > |
| 4844 | getpos('.')->getregionpos(getpos("'a")) |
| 4845 | < |
zeertzjq | d4d1207 | 2024-07-16 20:34:16 +0200 | [diff] [blame] | 4846 | Return type: list<list<list<number>>> |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 4847 | |
| 4848 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4849 | getregtype([{regname}]) *getregtype()* |
| 4850 | The result is a String, which is type of register {regname}. |
| 4851 | The value will be one of: |
| 4852 | "v" for |characterwise| text |
| 4853 | "V" for |linewise| text |
| 4854 | "<CTRL-V>{width}" for |blockwise-visual| text |
| 4855 | "" for an empty or unknown register |
| 4856 | <CTRL-V> is one character with value 0x16. |
| 4857 | The {regname} argument is a string. If {regname} is "", the |
| 4858 | unnamed register '"' is used. If {regname} is not specified, |
| 4859 | |v:register| is used. |
| 4860 | In |Vim9-script| {regname} must be one character. |
| 4861 | |
| 4862 | Can also be used as a |method|: > |
| 4863 | GetRegname()->getregtype() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 4864 | < |
| 4865 | Return type: |String| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4866 | |
Bram Moolenaar | 71badf9 | 2023-04-22 22:40:14 +0100 | [diff] [blame] | 4867 | getscriptinfo([{opts}]) *getscriptinfo()* |
Yegappan Lakshmanan | f768c3d | 2022-08-22 13:15:13 +0100 | [diff] [blame] | 4868 | Returns a |List| with information about all the sourced Vim |
Bram Moolenaar | 753885b | 2022-08-24 16:30:36 +0100 | [diff] [blame] | 4869 | scripts in the order they were sourced, like what |
| 4870 | `:scriptnames` shows. |
Yegappan Lakshmanan | f768c3d | 2022-08-22 13:15:13 +0100 | [diff] [blame] | 4871 | |
Yegappan Lakshmanan | 2f892d8 | 2022-08-28 18:52:10 +0100 | [diff] [blame] | 4872 | The optional Dict argument {opts} supports the following |
| 4873 | optional items: |
| 4874 | name Script name match pattern. If specified, |
| 4875 | and "sid" is not specified, information about |
Bram Moolenaar | 71badf9 | 2023-04-22 22:40:14 +0100 | [diff] [blame] | 4876 | scripts with a name that match the pattern |
Yegappan Lakshmanan | 2f892d8 | 2022-08-28 18:52:10 +0100 | [diff] [blame] | 4877 | "name" are returned. |
| 4878 | sid Script ID |<SID>|. If specified, only |
| 4879 | information about the script with ID "sid" is |
| 4880 | returned and "name" is ignored. |
| 4881 | |
Yegappan Lakshmanan | f768c3d | 2022-08-22 13:15:13 +0100 | [diff] [blame] | 4882 | Each item in the returned List is a |Dict| with the following |
| 4883 | items: |
Yegappan Lakshmanan | 2f892d8 | 2022-08-28 18:52:10 +0100 | [diff] [blame] | 4884 | autoload Set to TRUE for a script that was used with |
Bram Moolenaar | 753885b | 2022-08-24 16:30:36 +0100 | [diff] [blame] | 4885 | `import autoload` but was not actually sourced |
| 4886 | yet (see |import-autoload|). |
Yegappan Lakshmanan | 2f892d8 | 2022-08-28 18:52:10 +0100 | [diff] [blame] | 4887 | functions List of script-local function names defined in |
| 4888 | the script. Present only when a particular |
| 4889 | script is specified using the "sid" item in |
| 4890 | {opts}. |
| 4891 | name Vim script file name. |
| 4892 | sid Script ID |<SID>|. |
| 4893 | sourced Script ID of the actually sourced script that |
Bram Moolenaar | fd99945 | 2022-08-24 18:30:14 +0100 | [diff] [blame] | 4894 | this script name links to, if any, otherwise |
| 4895 | zero |
Yegappan Lakshmanan | 2f892d8 | 2022-08-28 18:52:10 +0100 | [diff] [blame] | 4896 | variables A dictionary with the script-local variables. |
Bram Moolenaar | f1dcd14 | 2022-12-31 15:30:45 +0000 | [diff] [blame] | 4897 | Present only when a particular script is |
Yegappan Lakshmanan | 2f892d8 | 2022-08-28 18:52:10 +0100 | [diff] [blame] | 4898 | specified using the "sid" item in {opts}. |
| 4899 | Note that this is a copy, the value of |
| 4900 | script-local variables cannot be changed using |
| 4901 | this dictionary. |
h_east | 5985879 | 2023-10-25 22:47:05 +0900 | [diff] [blame] | 4902 | version Vim script version (|scriptversion|) |
Yegappan Lakshmanan | 520f6ef | 2022-08-25 17:40:40 +0100 | [diff] [blame] | 4903 | |
Yegappan Lakshmanan | 2f892d8 | 2022-08-28 18:52:10 +0100 | [diff] [blame] | 4904 | Examples: > |
| 4905 | :echo getscriptinfo({'name': 'myscript'}) |
zeertzjq | ad4881c | 2024-05-04 15:35:30 +0800 | [diff] [blame] | 4906 | :echo getscriptinfo({'sid': 15})[0].variables |
Yegappan Lakshmanan | 2f892d8 | 2022-08-28 18:52:10 +0100 | [diff] [blame] | 4907 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 4908 | Return type: list<dict<any>> |
| 4909 | |
| 4910 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4911 | gettabinfo([{tabnr}]) *gettabinfo()* |
| 4912 | If {tabnr} is not specified, then information about all the |
| 4913 | tab pages is returned as a |List|. Each List item is a |
| 4914 | |Dictionary|. Otherwise, {tabnr} specifies the tab page |
| 4915 | number and information about that one is returned. If the tab |
| 4916 | page does not exist an empty List is returned. |
| 4917 | |
| 4918 | Each List item is a |Dictionary| with the following entries: |
| 4919 | tabnr tab page number. |
| 4920 | variables a reference to the dictionary with |
| 4921 | tabpage-local variables |
| 4922 | windows List of |window-ID|s in the tab page. |
| 4923 | |
| 4924 | Can also be used as a |method|: > |
| 4925 | GetTabnr()->gettabinfo() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 4926 | < |
| 4927 | Return type: list<dict<any>> |
| 4928 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4929 | |
| 4930 | gettabvar({tabnr}, {varname} [, {def}]) *gettabvar()* |
| 4931 | Get the value of a tab-local variable {varname} in tab page |
| 4932 | {tabnr}. |t:var| |
| 4933 | Tabs are numbered starting with one. |
| 4934 | The {varname} argument is a string. When {varname} is empty a |
| 4935 | dictionary with all tab-local variables is returned. |
| 4936 | Note that the name without "t:" must be used. |
| 4937 | When the tab or variable doesn't exist {def} or an empty |
| 4938 | string is returned, there is no error message. |
| 4939 | |
| 4940 | Can also be used as a |method|: > |
| 4941 | GetTabnr()->gettabvar(varname) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 4942 | < |
| 4943 | Return type: any, depending on {varname} |
| 4944 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4945 | |
| 4946 | gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()* |
| 4947 | Get the value of window-local variable {varname} in window |
| 4948 | {winnr} in tab page {tabnr}. |
| 4949 | The {varname} argument is a string. When {varname} is empty a |
| 4950 | dictionary with all window-local variables is returned. |
| 4951 | When {varname} is equal to "&" get the values of all |
| 4952 | window-local options in a |Dictionary|. |
| 4953 | Otherwise, when {varname} starts with "&" get the value of a |
| 4954 | window-local option. |
| 4955 | Note that {varname} must be the name without "w:". |
| 4956 | Tabs are numbered starting with one. For the current tabpage |
| 4957 | use |getwinvar()|. |
| 4958 | {winnr} can be the window number or the |window-ID|. |
| 4959 | When {winnr} is zero the current window is used. |
| 4960 | This also works for a global option, buffer-local option and |
| 4961 | window-local option, but it doesn't work for a global variable |
| 4962 | or buffer-local variable. |
| 4963 | When the tab, window or variable doesn't exist {def} or an |
| 4964 | empty string is returned, there is no error message. |
| 4965 | Examples: > |
| 4966 | :let list_is_on = gettabwinvar(1, 2, '&list') |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 4967 | :echo "myvar = " .. gettabwinvar(3, 1, 'myvar') |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4968 | < |
| 4969 | To obtain all window-local variables use: > |
| 4970 | gettabwinvar({tabnr}, {winnr}, '&') |
| 4971 | |
| 4972 | < Can also be used as a |method|: > |
| 4973 | GetTabnr()->gettabwinvar(winnr, varname) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 4974 | < |
| 4975 | Return type: any, depending on {varname} |
| 4976 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 4977 | |
| 4978 | gettagstack([{winnr}]) *gettagstack()* |
| 4979 | The result is a Dict, which is the tag stack of window {winnr}. |
| 4980 | {winnr} can be the window number or the |window-ID|. |
| 4981 | When {winnr} is not specified, the current window is used. |
| 4982 | When window {winnr} doesn't exist, an empty Dict is returned. |
| 4983 | |
| 4984 | The returned dictionary contains the following entries: |
| 4985 | curidx Current index in the stack. When at |
| 4986 | top of the stack, set to (length + 1). |
| 4987 | Index of bottom of the stack is 1. |
| 4988 | items List of items in the stack. Each item |
| 4989 | is a dictionary containing the |
| 4990 | entries described below. |
| 4991 | length Number of entries in the stack. |
| 4992 | |
| 4993 | Each item in the stack is a dictionary with the following |
| 4994 | entries: |
| 4995 | bufnr buffer number of the current jump |
| 4996 | from cursor position before the tag jump. |
| 4997 | See |getpos()| for the format of the |
| 4998 | returned list. |
| 4999 | matchnr current matching tag number. Used when |
| 5000 | multiple matching tags are found for a |
| 5001 | name. |
| 5002 | tagname name of the tag |
| 5003 | |
| 5004 | See |tagstack| for more information about the tag stack. |
| 5005 | |
| 5006 | Can also be used as a |method|: > |
| 5007 | GetWinnr()->gettagstack() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 5008 | < |
| 5009 | Return type: dict<any> |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5010 | |
| 5011 | |
Christ van Willegen | ce0ef91 | 2024-06-20 23:41:59 +0200 | [diff] [blame] | 5012 | gettext({text} [, {package}]) *gettext()* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5013 | Translate String {text} if possible. |
RestorerZ | 9650910 | 2024-07-11 21:14:15 +0200 | [diff] [blame] | 5014 | This is intended for use in Vim scripts. When generating |
| 5015 | message translations the {text} is extracted by `xgettext`, |
| 5016 | the translator can add translated messages into the .po file |
| 5017 | and Vim will lookup the translation when gettext() is called. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5018 | For {text} double quoted strings are preferred, because |
RestorerZ | 9650910 | 2024-07-11 21:14:15 +0200 | [diff] [blame] | 5019 | `xgettext` does not support single quoted escaped text. |
| 5020 | |
Christ van Willegen | ce0ef91 | 2024-06-20 23:41:59 +0200 | [diff] [blame] | 5021 | When the {package} is specified, the translation is looked up |
RestorerZ | 9650910 | 2024-07-11 21:14:15 +0200 | [diff] [blame] | 5022 | for that specific package. This is mainly required for |
| 5023 | third-party Vim scripts. You need to specify a path to the |
| 5024 | translations with the |bindtextdomain()| function before |
| 5025 | using the gettext() function. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5026 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 5027 | Return type: |String| |
| 5028 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5029 | |
| 5030 | getwininfo([{winid}]) *getwininfo()* |
| 5031 | Returns information about windows as a |List| with Dictionaries. |
| 5032 | |
| 5033 | If {winid} is given Information about the window with that ID |
| 5034 | is returned, as a |List| with one item. If the window does not |
| 5035 | exist the result is an empty list. |
| 5036 | |
| 5037 | Without {winid} information about all the windows in all the |
| 5038 | tab pages is returned. |
| 5039 | |
| 5040 | Each List item is a |Dictionary| with the following entries: |
| 5041 | botline last complete displayed buffer line |
| 5042 | bufnr number of buffer in the window |
| 5043 | height window height (excluding winbar) |
| 5044 | loclist 1 if showing a location list |
| 5045 | {only with the +quickfix feature} |
| 5046 | quickfix 1 if quickfix or location list window |
| 5047 | {only with the +quickfix feature} |
| 5048 | terminal 1 if a terminal window |
| 5049 | {only with the +terminal feature} |
| 5050 | tabnr tab page number |
| 5051 | topline first displayed buffer line |
| 5052 | variables a reference to the dictionary with |
| 5053 | window-local variables |
| 5054 | width window width |
| 5055 | winbar 1 if the window has a toolbar, 0 |
| 5056 | otherwise |
| 5057 | wincol leftmost screen column of the window; |
| 5058 | "col" from |win_screenpos()| |
| 5059 | textoff number of columns occupied by any |
| 5060 | 'foldcolumn', 'signcolumn' and line |
| 5061 | number in front of the text |
| 5062 | winid |window-ID| |
| 5063 | winnr window number |
| 5064 | winrow topmost screen line of the window; |
| 5065 | "row" from |win_screenpos()| |
| 5066 | |
| 5067 | Can also be used as a |method|: > |
| 5068 | GetWinnr()->getwininfo() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 5069 | < |
| 5070 | Return type: list<dict<any>> |
| 5071 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5072 | |
| 5073 | getwinpos([{timeout}]) *getwinpos()* |
| 5074 | The result is a |List| with two numbers, the result of |
| 5075 | |getwinposx()| and |getwinposy()| combined: |
| 5076 | [x-pos, y-pos] |
| 5077 | {timeout} can be used to specify how long to wait in msec for |
| 5078 | a response from the terminal. When omitted 100 msec is used. |
| 5079 | Use a longer time for a remote terminal. |
| 5080 | When using a value less than 10 and no response is received |
| 5081 | within that time, a previously reported position is returned, |
| 5082 | if available. This can be used to poll for the position and |
| 5083 | do some work in the meantime: > |
| 5084 | while 1 |
| 5085 | let res = getwinpos(1) |
| 5086 | if res[0] >= 0 |
| 5087 | break |
| 5088 | endif |
| 5089 | " Do some work here |
| 5090 | endwhile |
| 5091 | < |
| 5092 | |
| 5093 | Can also be used as a |method|: > |
| 5094 | GetTimeout()->getwinpos() |
| 5095 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 5096 | Return type: list<number> |
| 5097 | |
| 5098 | |
| 5099 | getwinposx() *getwinposx()* |
| 5100 | The result is a Number, which is the X coordinate in pixels of |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5101 | the left hand side of the GUI Vim window. Also works for an |
| 5102 | xterm (uses a timeout of 100 msec). |
lilydjwg | 6e0a18f | 2024-01-29 20:54:28 +0100 | [diff] [blame] | 5103 | The result will be -1 if the information is not available |
| 5104 | (e.g. on the Wayland backend). |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5105 | The value can be used with `:winpos`. |
| 5106 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 5107 | Return type: |Number| |
| 5108 | |
| 5109 | |
| 5110 | getwinposy() *getwinposy()* |
| 5111 | The result is a Number, which is the Y coordinate in pixels of |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5112 | the top of the GUI Vim window. Also works for an xterm (uses |
| 5113 | a timeout of 100 msec). |
lilydjwg | 6e0a18f | 2024-01-29 20:54:28 +0100 | [diff] [blame] | 5114 | The result will be -1 if the information is not available |
| 5115 | (e.g. on the Wayland backend). |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5116 | The value can be used with `:winpos`. |
| 5117 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 5118 | Return type: |Number| |
| 5119 | |
| 5120 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5121 | getwinvar({winnr}, {varname} [, {def}]) *getwinvar()* |
| 5122 | Like |gettabwinvar()| for the current tabpage. |
| 5123 | Examples: > |
| 5124 | :let list_is_on = getwinvar(2, '&list') |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 5125 | :echo "myvar = " .. getwinvar(1, 'myvar') |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5126 | |
| 5127 | < Can also be used as a |method|: > |
| 5128 | GetWinnr()->getwinvar(varname) |
| 5129 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 5130 | Return type: any, depending on {varname} |
| 5131 | |
| 5132 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5133 | glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()* |
| 5134 | Expand the file wildcards in {expr}. See |wildcards| for the |
| 5135 | use of special characters. |
| 5136 | |
| 5137 | Unless the optional {nosuf} argument is given and is |TRUE|, |
| 5138 | the 'suffixes' and 'wildignore' options apply: Names matching |
| 5139 | one of the patterns in 'wildignore' will be skipped and |
| 5140 | 'suffixes' affect the ordering of matches. |
| 5141 | 'wildignorecase' always applies. |
| 5142 | |
| 5143 | When {list} is present and it is |TRUE| the result is a |List| |
| 5144 | with all matching files. The advantage of using a List is, |
| 5145 | you also get filenames containing newlines correctly. |
| 5146 | Otherwise the result is a String and when there are several |
| 5147 | matches, they are separated by <NL> characters. |
| 5148 | |
| 5149 | If the expansion fails, the result is an empty String or List. |
| 5150 | |
| 5151 | You can also use |readdir()| if you need to do complicated |
| 5152 | things, such as limiting the number of matches. |
| 5153 | |
| 5154 | A name for a non-existing file is not included. A symbolic |
| 5155 | link is only included if it points to an existing file. |
| 5156 | However, when the {alllinks} argument is present and it is |
| 5157 | |TRUE| then all symbolic links are included. |
| 5158 | |
| 5159 | For most systems backticks can be used to get files names from |
| 5160 | any external command. Example: > |
| 5161 | :let tagfiles = glob("`find . -name tags -print`") |
| 5162 | :let &tags = substitute(tagfiles, "\n", ",", "g") |
| 5163 | < The result of the program inside the backticks should be one |
| 5164 | item per line. Spaces inside an item are allowed. |
| 5165 | |
| 5166 | See |expand()| for expanding special Vim variables. See |
| 5167 | |system()| for getting the raw output of an external command. |
| 5168 | |
| 5169 | Can also be used as a |method|: > |
| 5170 | GetExpr()->glob() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 5171 | < |
| 5172 | Return type: |String| or list<string> or list<any> depending |
| 5173 | on {list} |
| 5174 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5175 | |
| 5176 | glob2regpat({string}) *glob2regpat()* |
| 5177 | Convert a file pattern, as used by glob(), into a search |
| 5178 | pattern. The result can be used to match with a string that |
| 5179 | is a file name. E.g. > |
| 5180 | if filename =~ glob2regpat('Make*.mak') |
| 5181 | < This is equivalent to: > |
| 5182 | if filename =~ '^Make.*\.mak$' |
| 5183 | < When {string} is an empty string the result is "^$", match an |
| 5184 | empty string. |
| 5185 | Note that the result depends on the system. On MS-Windows |
| 5186 | a backslash usually means a path separator. |
| 5187 | |
| 5188 | Can also be used as a |method|: > |
| 5189 | GetExpr()->glob2regpat() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 5190 | < |
| 5191 | Return type: |String| |
| 5192 | |
| 5193 | *globpath()* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5194 | globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]]) |
| 5195 | Perform glob() for String {expr} on all directories in {path} |
| 5196 | and concatenate the results. Example: > |
| 5197 | :echo globpath(&rtp, "syntax/c.vim") |
| 5198 | < |
| 5199 | {path} is a comma-separated list of directory names. Each |
| 5200 | directory name is prepended to {expr} and expanded like with |
| 5201 | |glob()|. A path separator is inserted when needed. |
| 5202 | To add a comma inside a directory name escape it with a |
| 5203 | backslash. Note that on MS-Windows a directory may have a |
| 5204 | trailing backslash, remove it if you put a comma after it. |
| 5205 | If the expansion fails for one of the directories, there is no |
| 5206 | error message. |
| 5207 | |
| 5208 | Unless the optional {nosuf} argument is given and is |TRUE|, |
| 5209 | the 'suffixes' and 'wildignore' options apply: Names matching |
| 5210 | one of the patterns in 'wildignore' will be skipped and |
| 5211 | 'suffixes' affect the ordering of matches. |
| 5212 | |
| 5213 | When {list} is present and it is |TRUE| the result is a |List| |
| 5214 | with all matching files. The advantage of using a List is, you |
| 5215 | also get filenames containing newlines correctly. Otherwise |
| 5216 | the result is a String and when there are several matches, |
| 5217 | they are separated by <NL> characters. Example: > |
| 5218 | :echo globpath(&rtp, "syntax/c.vim", 0, 1) |
| 5219 | < |
| 5220 | {alllinks} is used as with |glob()|. |
| 5221 | |
| 5222 | The "**" item can be used to search in a directory tree. |
| 5223 | For example, to find all "README.txt" files in the directories |
| 5224 | in 'runtimepath' and below: > |
| 5225 | :echo globpath(&rtp, "**/README.txt") |
| 5226 | < Upwards search and limiting the depth of "**" is not |
| 5227 | supported, thus using 'path' will not always work properly. |
| 5228 | |
| 5229 | Can also be used as a |method|, the base is passed as the |
| 5230 | second argument: > |
| 5231 | GetExpr()->globpath(&rtp) |
| 5232 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 5233 | Return type: |String| or list<string> or list<any> depending |
| 5234 | on {list} |
| 5235 | |
| 5236 | |
| 5237 | has({feature} [, {check}]) *has()* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5238 | When {check} is omitted or is zero: The result is a Number, |
| 5239 | which is 1 if the feature {feature} is supported, zero |
| 5240 | otherwise. The {feature} argument is a string, case is |
| 5241 | ignored. See |feature-list| below. |
| 5242 | |
| 5243 | When {check} is present and not zero: The result is a Number, |
| 5244 | which is 1 if the feature {feature} could ever be supported, |
| 5245 | zero otherwise. This is useful to check for a typo in |
| 5246 | {feature} and to detect dead code. Keep in mind that an older |
| 5247 | Vim version will not know about a feature added later and |
| 5248 | features that have been abandoned will not be known by the |
| 5249 | current Vim version. |
| 5250 | |
| 5251 | Also see |exists()| and |exists_compiled()|. |
| 5252 | |
| 5253 | Note that to skip code that has a syntax error when the |
| 5254 | feature is not available, Vim may skip the rest of the line |
| 5255 | and miss a following `endif`. Therefore put the `endif` on a |
| 5256 | separate line: > |
| 5257 | if has('feature') |
| 5258 | let x = this->breaks->without->the->feature |
| 5259 | endif |
| 5260 | < If the `endif` would be moved to the second line as "| endif" it |
| 5261 | would not be found. |
| 5262 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 5263 | Return type: |Number| |
| 5264 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5265 | |
| 5266 | has_key({dict}, {key}) *has_key()* |
| 5267 | The result is a Number, which is TRUE if |Dictionary| {dict} |
Bram Moolenaar | e800864 | 2022-08-19 17:15:35 +0100 | [diff] [blame] | 5268 | has an entry with key {key}. FALSE otherwise. |
| 5269 | The {key} argument is a string. In |Vim9| script a number is |
| 5270 | also accepted (and converted to a string) but no other types. |
| 5271 | In legacy script the usual automatic conversion to string is |
| 5272 | done. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5273 | |
| 5274 | Can also be used as a |method|: > |
| 5275 | mydict->has_key(key) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 5276 | < |
| 5277 | Return type: |Number| |
| 5278 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5279 | |
| 5280 | haslocaldir([{winnr} [, {tabnr}]]) *haslocaldir()* |
| 5281 | The result is a Number: |
| 5282 | 1 when the window has set a local directory via |:lcd| |
| 5283 | 2 when the tab-page has set a local directory via |:tcd| |
| 5284 | 0 otherwise. |
| 5285 | |
| 5286 | Without arguments use the current window. |
| 5287 | With {winnr} use this window in the current tab page. |
| 5288 | With {winnr} and {tabnr} use the window in the specified tab |
| 5289 | page. |
| 5290 | {winnr} can be the window number or the |window-ID|. |
| 5291 | If {winnr} is -1 it is ignored and only the tabpage is used. |
| 5292 | Return 0 if the arguments are invalid. |
| 5293 | Examples: > |
| 5294 | if haslocaldir() == 1 |
| 5295 | " window local directory case |
| 5296 | elseif haslocaldir() == 2 |
| 5297 | " tab-local directory case |
| 5298 | else |
| 5299 | " global directory case |
| 5300 | endif |
| 5301 | |
| 5302 | " current window |
| 5303 | :echo haslocaldir() |
| 5304 | :echo haslocaldir(0) |
| 5305 | :echo haslocaldir(0, 0) |
| 5306 | " window n in current tab page |
| 5307 | :echo haslocaldir(n) |
| 5308 | :echo haslocaldir(n, 0) |
| 5309 | " window n in tab page m |
| 5310 | :echo haslocaldir(n, m) |
| 5311 | " tab page m |
| 5312 | :echo haslocaldir(-1, m) |
| 5313 | < |
| 5314 | Can also be used as a |method|: > |
| 5315 | GetWinnr()->haslocaldir() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 5316 | < |
| 5317 | Return type: |Number| |
| 5318 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5319 | |
| 5320 | hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()* |
| 5321 | The result is a Number, which is TRUE if there is a mapping |
| 5322 | that contains {what} in somewhere in the rhs (what it is |
| 5323 | mapped to) and this mapping exists in one of the modes |
| 5324 | indicated by {mode}. |
| 5325 | The arguments {what} and {mode} are strings. |
| 5326 | When {abbr} is there and it is |TRUE| use abbreviations |
| 5327 | instead of mappings. Don't forget to specify Insert and/or |
| 5328 | Command-line mode. |
| 5329 | Both the global mappings and the mappings local to the current |
| 5330 | buffer are checked for a match. |
| 5331 | If no matching mapping is found FALSE is returned. |
| 5332 | The following characters are recognized in {mode}: |
| 5333 | n Normal mode |
| 5334 | v Visual and Select mode |
| 5335 | x Visual mode |
| 5336 | s Select mode |
| 5337 | o Operator-pending mode |
| 5338 | i Insert mode |
| 5339 | l Language-Argument ("r", "f", "t", etc.) |
| 5340 | c Command-line mode |
| 5341 | When {mode} is omitted, "nvo" is used. |
| 5342 | |
| 5343 | This function is useful to check if a mapping already exists |
| 5344 | to a function in a Vim script. Example: > |
| 5345 | :if !hasmapto('\ABCdoit') |
| 5346 | : map <Leader>d \ABCdoit |
| 5347 | :endif |
| 5348 | < This installs the mapping to "\ABCdoit" only if there isn't |
| 5349 | already a mapping to "\ABCdoit". |
| 5350 | |
| 5351 | Can also be used as a |method|: > |
| 5352 | GetRHS()->hasmapto() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 5353 | < |
| 5354 | Return type: |Number| |
| 5355 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5356 | |
| 5357 | histadd({history}, {item}) *histadd()* |
| 5358 | Add the String {item} to the history {history} which can be |
| 5359 | one of: *hist-names* |
| 5360 | "cmd" or ":" command line history |
| 5361 | "search" or "/" search pattern history |
| 5362 | "expr" or "=" typed expression history |
| 5363 | "input" or "@" input line history |
| 5364 | "debug" or ">" debug command history |
| 5365 | empty the current or last used history |
| 5366 | The {history} string does not need to be the whole name, one |
| 5367 | character is sufficient. |
| 5368 | If {item} does already exist in the history, it will be |
| 5369 | shifted to become the newest entry. |
| 5370 | The result is a Number: TRUE if the operation was successful, |
| 5371 | otherwise FALSE is returned. |
| 5372 | |
| 5373 | Example: > |
| 5374 | :call histadd("input", strftime("%Y %b %d")) |
| 5375 | :let date=input("Enter date: ") |
| 5376 | < This function is not available in the |sandbox|. |
| 5377 | |
| 5378 | Can also be used as a |method|, the base is passed as the |
| 5379 | second argument: > |
| 5380 | GetHistory()->histadd('search') |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 5381 | < |
| 5382 | Return type: |Number| |
| 5383 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5384 | |
| 5385 | histdel({history} [, {item}]) *histdel()* |
| 5386 | Clear {history}, i.e. delete all its entries. See |hist-names| |
| 5387 | for the possible values of {history}. |
| 5388 | |
| 5389 | If the parameter {item} evaluates to a String, it is used as a |
| 5390 | regular expression. All entries matching that expression will |
| 5391 | be removed from the history (if there are any). |
| 5392 | Upper/lowercase must match, unless "\c" is used |/\c|. |
| 5393 | If {item} evaluates to a Number, it will be interpreted as |
| 5394 | an index, see |:history-indexing|. The respective entry will |
| 5395 | be removed if it exists. |
| 5396 | |
| 5397 | The result is TRUE for a successful operation, otherwise FALSE |
| 5398 | is returned. |
| 5399 | |
| 5400 | Examples: |
| 5401 | Clear expression register history: > |
| 5402 | :call histdel("expr") |
| 5403 | < |
| 5404 | Remove all entries starting with "*" from the search history: > |
| 5405 | :call histdel("/", '^\*') |
| 5406 | < |
| 5407 | The following three are equivalent: > |
| 5408 | :call histdel("search", histnr("search")) |
| 5409 | :call histdel("search", -1) |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 5410 | :call histdel("search", '^' .. histget("search", -1) .. '$') |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5411 | < |
| 5412 | To delete the last search pattern and use the last-but-one for |
| 5413 | the "n" command and 'hlsearch': > |
| 5414 | :call histdel("search", -1) |
| 5415 | :let @/ = histget("search", -1) |
| 5416 | < |
| 5417 | Can also be used as a |method|: > |
| 5418 | GetHistory()->histdel() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 5419 | < |
| 5420 | Return type: |Number| |
| 5421 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5422 | |
| 5423 | histget({history} [, {index}]) *histget()* |
| 5424 | The result is a String, the entry with Number {index} from |
| 5425 | {history}. See |hist-names| for the possible values of |
| 5426 | {history}, and |:history-indexing| for {index}. If there is |
| 5427 | no such entry, an empty String is returned. When {index} is |
| 5428 | omitted, the most recent item from the history is used. |
| 5429 | |
| 5430 | Examples: |
| 5431 | Redo the second last search from history. > |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 5432 | :execute '/' .. histget("search", -2) |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5433 | |
| 5434 | < Define an Ex command ":H {num}" that supports re-execution of |
| 5435 | the {num}th entry from the output of |:history|. > |
| 5436 | :command -nargs=1 H execute histget("cmd", 0+<args>) |
| 5437 | < |
| 5438 | Can also be used as a |method|: > |
| 5439 | GetHistory()->histget() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 5440 | < |
| 5441 | Return type: |String| |
| 5442 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5443 | |
| 5444 | histnr({history}) *histnr()* |
| 5445 | The result is the Number of the current entry in {history}. |
| 5446 | See |hist-names| for the possible values of {history}. |
| 5447 | If an error occurred, -1 is returned. |
| 5448 | |
| 5449 | Example: > |
| 5450 | :let inp_index = histnr("expr") |
| 5451 | |
| 5452 | < Can also be used as a |method|: > |
| 5453 | GetHistory()->histnr() |
| 5454 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 5455 | Return type: |Number| |
| 5456 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5457 | hlexists({name}) *hlexists()* |
| 5458 | The result is a Number, which is TRUE if a highlight group |
| 5459 | called {name} exists. This is when the group has been |
| 5460 | defined in some way. Not necessarily when highlighting has |
| 5461 | been defined for it, it may also have been used for a syntax |
| 5462 | item. |
| 5463 | *highlight_exists()* |
| 5464 | Obsolete name: highlight_exists(). |
| 5465 | |
| 5466 | Can also be used as a |method|: > |
| 5467 | GetName()->hlexists() |
| 5468 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 5469 | Return type: |Number| |
| 5470 | |
| 5471 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5472 | hlget([{name} [, {resolve}]]) *hlget()* |
| 5473 | Returns a List of all the highlight group attributes. If the |
| 5474 | optional {name} is specified, then returns a List with only |
| 5475 | the attributes of the specified highlight group. Returns an |
| 5476 | empty List if the highlight group {name} is not present. |
| 5477 | |
| 5478 | If the optional {resolve} argument is set to v:true and the |
| 5479 | highlight group {name} is linked to another group, then the |
| 5480 | link is resolved recursively and the attributes of the |
| 5481 | resolved highlight group are returned. |
| 5482 | |
| 5483 | Each entry in the returned List is a Dictionary with the |
| 5484 | following items: |
| 5485 | cleared boolean flag, set to v:true if the highlight |
| 5486 | group attributes are cleared or not yet |
| 5487 | specified. See |highlight-clear|. |
| 5488 | cterm cterm attributes. See |highlight-cterm|. |
| 5489 | ctermbg cterm background color. |
| 5490 | See |highlight-ctermbg|. |
| 5491 | ctermfg cterm foreground color. |
| 5492 | See |highlight-ctermfg|. |
| 5493 | ctermul cterm underline color. See |highlight-ctermul|. |
| 5494 | default boolean flag, set to v:true if the highlight |
| 5495 | group link is a default link. See |
| 5496 | |highlight-default|. |
| 5497 | font highlight group font. See |highlight-font|. |
| 5498 | gui gui attributes. See |highlight-gui|. |
| 5499 | guibg gui background color. See |highlight-guibg|. |
| 5500 | guifg gui foreground color. See |highlight-guifg|. |
| 5501 | guisp gui special color. See |highlight-guisp|. |
| 5502 | id highlight group ID. |
| 5503 | linksto linked highlight group name. |
| 5504 | See |:highlight-link|. |
| 5505 | name highlight group name. See |group-name|. |
| 5506 | start start terminal keycode. See |highlight-start|. |
| 5507 | stop stop terminal keycode. See |highlight-stop|. |
| 5508 | term term attributes. See |highlight-term|. |
| 5509 | |
| 5510 | The 'term', 'cterm' and 'gui' items in the above Dictionary |
| 5511 | have a dictionary value with the following optional boolean |
| 5512 | items: 'bold', 'standout', 'underline', 'undercurl', 'italic', |
| 5513 | 'reverse', 'inverse' and 'strikethrough'. |
| 5514 | |
| 5515 | Example(s): > |
| 5516 | :echo hlget() |
| 5517 | :echo hlget('ModeMsg') |
| 5518 | :echo hlget('Number', v:true) |
| 5519 | < |
| 5520 | Can also be used as a |method|: > |
| 5521 | GetName()->hlget() |
| 5522 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 5523 | Return type: list<dict<any>> |
| 5524 | |
| 5525 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5526 | hlset({list}) *hlset()* |
| 5527 | Creates or modifies the attributes of a List of highlight |
| 5528 | groups. Each item in {list} is a dictionary containing the |
| 5529 | attributes of a highlight group. See |hlget()| for the list of |
| 5530 | supported items in this dictionary. |
| 5531 | |
| 5532 | In addition to the items described in |hlget()|, the following |
| 5533 | additional items are supported in the dictionary: |
| 5534 | |
| 5535 | force boolean flag to force the creation of |
| 5536 | a link for an existing highlight group |
| 5537 | with attributes. |
| 5538 | |
| 5539 | The highlight group is identified using the 'name' item and |
| 5540 | the 'id' item (if supplied) is ignored. If a highlight group |
| 5541 | with a specified name doesn't exist, then it is created. |
| 5542 | Otherwise the attributes of an existing highlight group are |
| 5543 | modified. |
| 5544 | |
| 5545 | If an empty dictionary value is used for the 'term' or 'cterm' |
| 5546 | or 'gui' entries, then the corresponding attributes are |
| 5547 | cleared. If the 'cleared' item is set to v:true, then all the |
| 5548 | attributes of the highlight group are cleared. |
| 5549 | |
| 5550 | The 'linksto' item can be used to link a highlight group to |
| 5551 | another highlight group. See |:highlight-link|. |
| 5552 | |
| 5553 | Returns zero for success, -1 for failure. |
| 5554 | |
| 5555 | Example(s): > |
| 5556 | " add bold attribute to the Visual highlight group |
| 5557 | :call hlset([#{name: 'Visual', |
| 5558 | \ term: #{reverse: 1 , bold: 1}}]) |
| 5559 | :call hlset([#{name: 'Type', guifg: 'DarkGreen'}]) |
| 5560 | :let l = hlget() |
| 5561 | :call hlset(l) |
| 5562 | " clear the Search highlight group |
| 5563 | :call hlset([#{name: 'Search', cleared: v:true}]) |
| 5564 | " clear the 'term' attributes for a highlight group |
| 5565 | :call hlset([#{name: 'Title', term: {}}]) |
| 5566 | " create the MyHlg group linking it to DiffAdd |
| 5567 | :call hlset([#{name: 'MyHlg', linksto: 'DiffAdd'}]) |
| 5568 | " remove the MyHlg group link |
| 5569 | :call hlset([#{name: 'MyHlg', linksto: 'NONE'}]) |
| 5570 | " clear the attributes and a link |
| 5571 | :call hlset([#{name: 'MyHlg', cleared: v:true, |
| 5572 | \ linksto: 'NONE'}]) |
| 5573 | < |
| 5574 | Can also be used as a |method|: > |
| 5575 | GetAttrList()->hlset() |
| 5576 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 5577 | Return type: |Number| |
| 5578 | |
| 5579 | hlID({name}) *hlID()* |
| 5580 | The result is a Number, which is the ID of the highlight group |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5581 | with name {name}. When the highlight group doesn't exist, |
| 5582 | zero is returned. |
| 5583 | This can be used to retrieve information about the highlight |
| 5584 | group. For example, to get the background color of the |
| 5585 | "Comment" group: > |
| 5586 | :echo synIDattr(synIDtrans(hlID("Comment")), "bg") |
| 5587 | < *highlightID()* |
| 5588 | Obsolete name: highlightID(). |
| 5589 | |
| 5590 | Can also be used as a |method|: > |
| 5591 | GetName()->hlID() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 5592 | < |
| 5593 | Return type: |Number| |
| 5594 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5595 | |
| 5596 | hostname() *hostname()* |
| 5597 | The result is a String, which is the name of the machine on |
| 5598 | which Vim is currently running. Machine names greater than |
| 5599 | 256 characters long are truncated. |
| 5600 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 5601 | Return type: |String| |
| 5602 | |
| 5603 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5604 | iconv({string}, {from}, {to}) *iconv()* |
| 5605 | The result is a String, which is the text {string} converted |
| 5606 | from encoding {from} to encoding {to}. |
| 5607 | When the conversion completely fails an empty string is |
| 5608 | returned. When some characters could not be converted they |
| 5609 | are replaced with "?". |
| 5610 | The encoding names are whatever the iconv() library function |
| 5611 | can accept, see ":!man 3 iconv". |
| 5612 | Most conversions require Vim to be compiled with the |+iconv| |
| 5613 | feature. Otherwise only UTF-8 to latin1 conversion and back |
| 5614 | can be done. |
| 5615 | This can be used to display messages with special characters, |
| 5616 | no matter what 'encoding' is set to. Write the message in |
| 5617 | UTF-8 and use: > |
| 5618 | echo iconv(utf8_str, "utf-8", &enc) |
| 5619 | < Note that Vim uses UTF-8 for all Unicode encodings, conversion |
| 5620 | from/to UCS-2 is automatically changed to use UTF-8. You |
| 5621 | cannot use UCS-2 in a string anyway, because of the NUL bytes. |
| 5622 | |
| 5623 | Can also be used as a |method|: > |
| 5624 | GetText()->iconv('latin1', 'utf-8') |
| 5625 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 5626 | Return type: |String| |
| 5627 | |
| 5628 | |
Ernie Rael | c8e158b | 2024-07-09 18:39:52 +0200 | [diff] [blame] | 5629 | id({item}) *id()* |
| 5630 | The result is a unique String associated with the {item} and |
| 5631 | not with the {item}'s contents. It is only valid while the |
| 5632 | {item} exists and is referenced. It is valid only in the |
| 5633 | instance of vim that produces the result. The whole idea is |
| 5634 | that `id({item})` does not change if the contents of {item} |
| 5635 | changes. This is useful as a `key` for creating an identity |
| 5636 | dictionary, rather than one based on equals. |
| 5637 | |
| 5638 | This operation does not reference {item} and there is no |
| 5639 | function to convert the `id` to the {item}. It may be useful to |
| 5640 | have a map of `id` to {item}. The following > |
| 5641 | var referenceMap: dict<any> |
| 5642 | var id = item->id() |
| 5643 | referenceMap[id] = item |
| 5644 | < prevents {item} from being garbage collected and provides a |
| 5645 | way to get the {item} from the `id`. |
| 5646 | |
| 5647 | {item} may be a List, Dictionary, Object, Job, Channel or |
| 5648 | Blob. If the item is not a permitted type, or it is a null |
| 5649 | value, then an empty String is returned. |
| 5650 | |
| 5651 | Can also be used as a |method|: > |
| 5652 | GetItem()->id() |
| 5653 | < |
| 5654 | Return type: |String| |
| 5655 | |
| 5656 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 5657 | indent({lnum}) *indent()* |
| 5658 | The result is a Number, which is indent of line {lnum} in the |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5659 | current buffer. The indent is counted in spaces, the value |
| 5660 | of 'tabstop' is relevant. {lnum} is used just like in |
| 5661 | |getline()|. |
| 5662 | When {lnum} is invalid -1 is returned. In |Vim9| script an |
| 5663 | error is given. |
| 5664 | |
| 5665 | Can also be used as a |method|: > |
| 5666 | GetLnum()->indent() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 5667 | < |
| 5668 | Return type: |Number| |
| 5669 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5670 | |
| 5671 | index({object}, {expr} [, {start} [, {ic}]]) *index()* |
Yegappan Lakshmanan | b218655 | 2022-08-13 13:09:20 +0100 | [diff] [blame] | 5672 | Find {expr} in {object} and return its index. See |
Yegappan Lakshmanan | 3fbf6cd | 2022-08-13 21:35:13 +0100 | [diff] [blame] | 5673 | |indexof()| for using a lambda to select the item. |
Yegappan Lakshmanan | b218655 | 2022-08-13 13:09:20 +0100 | [diff] [blame] | 5674 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5675 | If {object} is a |List| return the lowest index where the item |
| 5676 | has a value equal to {expr}. There is no automatic |
| 5677 | conversion, so the String "4" is different from the Number 4. |
| 5678 | And the number 4 is different from the Float 4.0. The value |
Yegappan Lakshmanan | b218655 | 2022-08-13 13:09:20 +0100 | [diff] [blame] | 5679 | of 'ignorecase' is not used here, case matters as indicated by |
| 5680 | the {ic} argument. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5681 | |
| 5682 | If {object} is |Blob| return the lowest index where the byte |
| 5683 | value is equal to {expr}. |
| 5684 | |
| 5685 | If {start} is given then start looking at the item with index |
| 5686 | {start} (may be negative for an item relative to the end). |
Yegappan Lakshmanan | b218655 | 2022-08-13 13:09:20 +0100 | [diff] [blame] | 5687 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5688 | When {ic} is given and it is |TRUE|, ignore case. Otherwise |
| 5689 | case must match. |
Yegappan Lakshmanan | b218655 | 2022-08-13 13:09:20 +0100 | [diff] [blame] | 5690 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5691 | -1 is returned when {expr} is not found in {object}. |
| 5692 | Example: > |
| 5693 | :let idx = index(words, "the") |
| 5694 | :if index(numbers, 123) >= 0 |
| 5695 | |
| 5696 | < Can also be used as a |method|: > |
| 5697 | GetObject()->index(what) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 5698 | < |
| 5699 | Return type: |Number| |
| 5700 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5701 | |
Yegappan Lakshmanan | 3fbf6cd | 2022-08-13 21:35:13 +0100 | [diff] [blame] | 5702 | indexof({object}, {expr} [, {opts}]) *indexof()* |
| 5703 | Returns the index of an item in {object} where {expr} is |
| 5704 | v:true. {object} must be a |List| or a |Blob|. |
| 5705 | |
Yegappan Lakshmanan | b218655 | 2022-08-13 13:09:20 +0100 | [diff] [blame] | 5706 | If {object} is a |List|, evaluate {expr} for each item in the |
Yegappan Lakshmanan | 3fbf6cd | 2022-08-13 21:35:13 +0100 | [diff] [blame] | 5707 | List until the expression is v:true and return the index of |
| 5708 | this item. |
Yegappan Lakshmanan | b218655 | 2022-08-13 13:09:20 +0100 | [diff] [blame] | 5709 | |
| 5710 | If {object} is a |Blob| evaluate {expr} for each byte in the |
Yegappan Lakshmanan | 3fbf6cd | 2022-08-13 21:35:13 +0100 | [diff] [blame] | 5711 | Blob until the expression is v:true and return the index of |
| 5712 | this byte. |
Yegappan Lakshmanan | b218655 | 2022-08-13 13:09:20 +0100 | [diff] [blame] | 5713 | |
| 5714 | {expr} must be a |string| or |Funcref|. |
| 5715 | |
| 5716 | If {expr} is a |string|: If {object} is a |List|, inside |
| 5717 | {expr} |v:key| has the index of the current List item and |
| 5718 | |v:val| has the value of the item. If {object} is a |Blob|, |
| 5719 | inside {expr} |v:key| has the index of the current byte and |
| 5720 | |v:val| has the byte value. |
| 5721 | |
| 5722 | If {expr} is a |Funcref| it must take two arguments: |
| 5723 | 1. the key or the index of the current item. |
| 5724 | 2. the value of the current item. |
| 5725 | The function must return |TRUE| if the item is found and the |
| 5726 | search should stop. |
| 5727 | |
Yegappan Lakshmanan | 3fbf6cd | 2022-08-13 21:35:13 +0100 | [diff] [blame] | 5728 | The optional argument {opts} is a Dict and supports the |
Yegappan Lakshmanan | b218655 | 2022-08-13 13:09:20 +0100 | [diff] [blame] | 5729 | following items: |
Yegappan Lakshmanan | 3fbf6cd | 2022-08-13 21:35:13 +0100 | [diff] [blame] | 5730 | startidx start evaluating {expr} at the item with this |
| 5731 | index; may be negative for an item relative to |
| 5732 | the end |
Yegappan Lakshmanan | b218655 | 2022-08-13 13:09:20 +0100 | [diff] [blame] | 5733 | Returns -1 when {expr} evaluates to v:false for all the items. |
| 5734 | Example: > |
Yegappan Lakshmanan | 3fbf6cd | 2022-08-13 21:35:13 +0100 | [diff] [blame] | 5735 | :let l = [#{n: 10}, #{n: 20}, #{n: 30}] |
| 5736 | :echo indexof(l, "v:val.n == 20") |
| 5737 | :echo indexof(l, {i, v -> v.n == 30}) |
| 5738 | :echo indexof(l, "v:val.n == 20", #{startidx: 1}) |
Yegappan Lakshmanan | b218655 | 2022-08-13 13:09:20 +0100 | [diff] [blame] | 5739 | |
| 5740 | < Can also be used as a |method|: > |
| 5741 | mylist->indexof(expr) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 5742 | < |
| 5743 | Return type: |Number| |
| 5744 | |
Yegappan Lakshmanan | b218655 | 2022-08-13 13:09:20 +0100 | [diff] [blame] | 5745 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5746 | input({prompt} [, {text} [, {completion}]]) *input()* |
| 5747 | The result is a String, which is whatever the user typed on |
| 5748 | the command-line. The {prompt} argument is either a prompt |
| 5749 | string, or a blank string (for no prompt). A '\n' can be used |
| 5750 | in the prompt to start a new line. |
| 5751 | The highlighting set with |:echohl| is used for the prompt. |
| 5752 | The input is entered just like a command-line, with the same |
| 5753 | editing commands and mappings. There is a separate history |
| 5754 | for lines typed for input(). |
| 5755 | Example: > |
| 5756 | :if input("Coffee or beer? ") == "beer" |
| 5757 | : echo "Cheers!" |
| 5758 | :endif |
| 5759 | < |
| 5760 | If the optional {text} argument is present and not empty, this |
| 5761 | is used for the default reply, as if the user typed this. |
| 5762 | Example: > |
| 5763 | :let color = input("Color? ", "white") |
| 5764 | |
| 5765 | < The optional {completion} argument specifies the type of |
| 5766 | completion supported for the input. Without it completion is |
| 5767 | not performed. The supported completion types are the same as |
| 5768 | that can be supplied to a user-defined command using the |
| 5769 | "-complete=" argument. Refer to |:command-completion| for |
| 5770 | more information. Example: > |
| 5771 | let fname = input("File: ", "", "file") |
| 5772 | < |
| 5773 | NOTE: This function must not be used in a startup file, for |
| 5774 | the versions that only run in GUI mode (e.g., the Win32 GUI). |
| 5775 | Note: When input() is called from within a mapping it will |
| 5776 | consume remaining characters from that mapping, because a |
| 5777 | mapping is handled like the characters were typed. |
| 5778 | Use |inputsave()| before input() and |inputrestore()| |
| 5779 | after input() to avoid that. Another solution is to avoid |
| 5780 | that further characters follow in the mapping, e.g., by using |
| 5781 | |:execute| or |:normal|. |
| 5782 | |
| 5783 | Example with a mapping: > |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 5784 | :nmap \x :call GetFoo()<CR>:exe "/" .. Foo<CR> |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5785 | :function GetFoo() |
| 5786 | : call inputsave() |
| 5787 | : let g:Foo = input("enter search pattern: ") |
| 5788 | : call inputrestore() |
| 5789 | :endfunction |
| 5790 | |
| 5791 | < Can also be used as a |method|: > |
| 5792 | GetPrompt()->input() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 5793 | < |
| 5794 | Return type: |String| |
| 5795 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5796 | |
| 5797 | inputdialog({prompt} [, {text} [, {cancelreturn}]]) *inputdialog()* |
| 5798 | Like |input()|, but when the GUI is running and text dialogs |
| 5799 | are supported, a dialog window pops up to input the text. |
| 5800 | Example: > |
| 5801 | :let n = inputdialog("value for shiftwidth", shiftwidth()) |
| 5802 | :if n != "" |
| 5803 | : let &sw = n |
| 5804 | :endif |
| 5805 | < When the dialog is cancelled {cancelreturn} is returned. When |
| 5806 | omitted an empty string is returned. |
| 5807 | Hitting <Enter> works like pressing the OK button. Hitting |
| 5808 | <Esc> works like pressing the Cancel button. |
| 5809 | NOTE: Command-line completion is not supported. |
| 5810 | |
| 5811 | Can also be used as a |method|: > |
| 5812 | GetPrompt()->inputdialog() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 5813 | < |
| 5814 | Return type: |String| |
| 5815 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5816 | |
| 5817 | inputlist({textlist}) *inputlist()* |
| 5818 | {textlist} must be a |List| of strings. This |List| is |
| 5819 | displayed, one string per line. The user will be prompted to |
| 5820 | enter a number, which is returned. |
| 5821 | The user can also select an item by clicking on it with the |
| 5822 | mouse, if the mouse is enabled in the command line ('mouse' is |
| 5823 | "a" or includes "c"). For the first string 0 is returned. |
| 5824 | When clicking above the first item a negative number is |
| 5825 | returned. When clicking on the prompt one more than the |
| 5826 | length of {textlist} is returned. |
| 5827 | Make sure {textlist} has less than 'lines' entries, otherwise |
| 5828 | it won't work. It's a good idea to put the entry number at |
| 5829 | the start of the string. And put a prompt in the first item. |
| 5830 | Example: > |
| 5831 | let color = inputlist(['Select color:', '1. red', |
| 5832 | \ '2. green', '3. blue']) |
| 5833 | |
| 5834 | < Can also be used as a |method|: > |
| 5835 | GetChoices()->inputlist() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 5836 | < |
| 5837 | Return type: |Number| |
| 5838 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5839 | |
| 5840 | inputrestore() *inputrestore()* |
| 5841 | Restore typeahead that was saved with a previous |inputsave()|. |
| 5842 | Should be called the same number of times inputsave() is |
| 5843 | called. Calling it more often is harmless though. |
| 5844 | Returns TRUE when there is nothing to restore, FALSE otherwise. |
| 5845 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 5846 | Return type: |Number| |
| 5847 | |
| 5848 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5849 | inputsave() *inputsave()* |
| 5850 | Preserve typeahead (also from mappings) and clear it, so that |
| 5851 | a following prompt gets input from the user. Should be |
| 5852 | followed by a matching inputrestore() after the prompt. Can |
| 5853 | be used several times, in which case there must be just as |
| 5854 | many inputrestore() calls. |
| 5855 | Returns TRUE when out of memory, FALSE otherwise. |
| 5856 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 5857 | Return type: |Number| |
| 5858 | |
| 5859 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5860 | inputsecret({prompt} [, {text}]) *inputsecret()* |
| 5861 | This function acts much like the |input()| function with but |
| 5862 | two exceptions: |
| 5863 | a) the user's response will be displayed as a sequence of |
| 5864 | asterisks ("*") thereby keeping the entry secret, and |
| 5865 | b) the user's response will not be recorded on the input |
| 5866 | |history| stack. |
| 5867 | The result is a String, which is whatever the user actually |
| 5868 | typed on the command-line in response to the issued prompt. |
| 5869 | NOTE: Command-line completion is not supported. |
| 5870 | |
| 5871 | Can also be used as a |method|: > |
| 5872 | GetPrompt()->inputsecret() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 5873 | < |
| 5874 | Return type: |String| |
| 5875 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5876 | |
| 5877 | insert({object}, {item} [, {idx}]) *insert()* |
| 5878 | When {object} is a |List| or a |Blob| insert {item} at the start |
| 5879 | of it. |
| 5880 | |
| 5881 | If {idx} is specified insert {item} before the item with index |
| 5882 | {idx}. If {idx} is zero it goes before the first item, just |
| 5883 | like omitting {idx}. A negative {idx} is also possible, see |
| 5884 | |list-index|. -1 inserts just before the last item. |
| 5885 | |
| 5886 | Returns the resulting |List| or |Blob|. Examples: > |
| 5887 | :let mylist = insert([2, 3, 5], 1) |
| 5888 | :call insert(mylist, 4, -1) |
| 5889 | :call insert(mylist, 6, len(mylist)) |
| 5890 | < The last example can be done simpler with |add()|. |
| 5891 | Note that when {item} is a |List| it is inserted as a single |
| 5892 | item. Use |extend()| to concatenate |Lists|. |
| 5893 | |
| 5894 | Can also be used as a |method|: > |
| 5895 | mylist->insert(item) |
Yegappan Lakshmanan | cd39b69 | 2023-10-02 12:50:45 -0700 | [diff] [blame] | 5896 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 5897 | Return type: |Number| |
| 5898 | |
| 5899 | |
Yegappan Lakshmanan | cd39b69 | 2023-10-02 12:50:45 -0700 | [diff] [blame] | 5900 | *instanceof()* *E614* *E616* *E693* |
| 5901 | instanceof({object}, {class}) |
| 5902 | The result is a Number, which is |TRUE| when the {object} |
Ernie Rael | 2025af1 | 2023-12-12 16:58:00 +0100 | [diff] [blame] | 5903 | argument is a direct or indirect instance of a |Class|, |
| 5904 | |Interface|, or class |:type| alias specified by {class}. |
| 5905 | If {class} is varargs, the function returns |TRUE| when |
Yegappan Lakshmanan | cd39b69 | 2023-10-02 12:50:45 -0700 | [diff] [blame] | 5906 | {object} is an instance of any of the specified classes. |
LemonBoy | afe0466 | 2023-08-23 21:08:11 +0200 | [diff] [blame] | 5907 | Example: > |
Ernie Rael | 2025af1 | 2023-12-12 16:58:00 +0100 | [diff] [blame] | 5908 | instanceof(animal, Dog, Cat) |
LemonBoy | afe0466 | 2023-08-23 21:08:11 +0200 | [diff] [blame] | 5909 | |
| 5910 | < Can also be used as a |method|: > |
| 5911 | myobj->instanceof(mytype) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 5912 | < |
| 5913 | Return type: |Number| |
LemonBoy | afe0466 | 2023-08-23 21:08:11 +0200 | [diff] [blame] | 5914 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5915 | interrupt() *interrupt()* |
| 5916 | Interrupt script execution. It works more or less like the |
| 5917 | user typing CTRL-C, most commands won't execute and control |
| 5918 | returns to the user. This is useful to abort execution |
| 5919 | from lower down, e.g. in an autocommand. Example: > |
| 5920 | :function s:check_typoname(file) |
| 5921 | : if fnamemodify(a:file, ':t') == '[' |
| 5922 | : echomsg 'Maybe typo' |
| 5923 | : call interrupt() |
| 5924 | : endif |
| 5925 | :endfunction |
| 5926 | :au BufWritePre * call s:check_typoname(expand('<amatch>')) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 5927 | < |
| 5928 | Return type: void |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5929 | |
| 5930 | invert({expr}) *invert()* |
| 5931 | Bitwise invert. The argument is converted to a number. A |
| 5932 | List, Dict or Float argument causes an error. Example: > |
| 5933 | :let bits = invert(bits) |
| 5934 | < Can also be used as a |method|: > |
| 5935 | :let bits = bits->invert() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 5936 | < |
| 5937 | Return type: |Number| |
| 5938 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5939 | |
Bram Moolenaar | 8a3b805 | 2022-06-26 12:21:15 +0100 | [diff] [blame] | 5940 | isabsolutepath({path}) *isabsolutepath()* |
LemonBoy | dca1d40 | 2022-04-28 15:26:33 +0100 | [diff] [blame] | 5941 | The result is a Number, which is |TRUE| when {path} is an |
| 5942 | absolute path. |
Bram Moolenaar | 8a3b805 | 2022-06-26 12:21:15 +0100 | [diff] [blame] | 5943 | On Unix, a path is considered absolute when it starts with '/'. |
LemonBoy | dca1d40 | 2022-04-28 15:26:33 +0100 | [diff] [blame] | 5944 | On MS-Windows, it is considered absolute when it starts with an |
| 5945 | optional drive prefix and is followed by a '\' or '/'. UNC paths |
| 5946 | are always absolute. |
| 5947 | Example: > |
| 5948 | echo isabsolutepath('/usr/share/') " 1 |
| 5949 | echo isabsolutepath('./foobar') " 0 |
| 5950 | echo isabsolutepath('C:\Windows') " 1 |
| 5951 | echo isabsolutepath('foobar') " 0 |
| 5952 | echo isabsolutepath('\\remote\file') " 1 |
Bram Moolenaar | 8a3b805 | 2022-06-26 12:21:15 +0100 | [diff] [blame] | 5953 | < |
LemonBoy | dca1d40 | 2022-04-28 15:26:33 +0100 | [diff] [blame] | 5954 | Can also be used as a |method|: > |
| 5955 | GetName()->isabsolutepath() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 5956 | < |
| 5957 | Return type: |Number| |
LemonBoy | dca1d40 | 2022-04-28 15:26:33 +0100 | [diff] [blame] | 5958 | |
| 5959 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5960 | isdirectory({directory}) *isdirectory()* |
| 5961 | The result is a Number, which is |TRUE| when a directory |
| 5962 | with the name {directory} exists. If {directory} doesn't |
| 5963 | exist, or isn't a directory, the result is |FALSE|. {directory} |
| 5964 | is any expression, which is used as a String. |
| 5965 | |
| 5966 | Can also be used as a |method|: > |
| 5967 | GetName()->isdirectory() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 5968 | < |
| 5969 | Return type: |Number| |
| 5970 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5971 | |
| 5972 | isinf({expr}) *isinf()* |
| 5973 | Return 1 if {expr} is a positive infinity, or -1 a negative |
| 5974 | infinity, otherwise 0. > |
| 5975 | :echo isinf(1.0 / 0.0) |
| 5976 | < 1 > |
| 5977 | :echo isinf(-1.0 / 0.0) |
| 5978 | < -1 |
| 5979 | |
| 5980 | Can also be used as a |method|: > |
| 5981 | Compute()->isinf() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 5982 | < |
| 5983 | Return type: |Number| |
| 5984 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 5985 | |
| 5986 | islocked({expr}) *islocked()* *E786* |
| 5987 | The result is a Number, which is |TRUE| when {expr} is the |
| 5988 | name of a locked variable. |
| 5989 | The string argument {expr} must be the name of a variable, |
| 5990 | |List| item or |Dictionary| entry, not the variable itself! |
| 5991 | Example: > |
| 5992 | :let alist = [0, ['a', 'b'], 2, 3] |
| 5993 | :lockvar 1 alist |
| 5994 | :echo islocked('alist') " 1 |
| 5995 | :echo islocked('alist[1]') " 0 |
| 5996 | |
Bram Moolenaar | 9da17d7 | 2022-02-09 21:50:44 +0000 | [diff] [blame] | 5997 | < When {expr} is a variable that does not exist -1 is returned. |
| 5998 | If {expr} uses a range, list or dict index that is out of |
| 5999 | range or does not exist you get an error message. Use |
| 6000 | |exists()| to check for existence. |
| 6001 | In Vim9 script it does not work for local function variables. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6002 | |
| 6003 | Can also be used as a |method|: > |
| 6004 | GetName()->islocked() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 6005 | < |
| 6006 | Return type: |Number| |
| 6007 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6008 | |
| 6009 | isnan({expr}) *isnan()* |
| 6010 | Return |TRUE| if {expr} is a float with value NaN. > |
| 6011 | echo isnan(0.0 / 0.0) |
| 6012 | < 1 |
| 6013 | |
| 6014 | Can also be used as a |method|: > |
| 6015 | Compute()->isnan() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 6016 | < |
| 6017 | Return type: |Number| |
| 6018 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6019 | |
| 6020 | items({dict}) *items()* |
| 6021 | Return a |List| with all the key-value pairs of {dict}. Each |
| 6022 | |List| item is a list with two items: the key of a {dict} |
| 6023 | entry and the value of this entry. The |List| is in arbitrary |
| 6024 | order. Also see |keys()| and |values()|. |
| 6025 | Example: > |
| 6026 | for [key, value] in items(mydict) |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 6027 | echo key .. ': ' .. value |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6028 | endfor |
Yegappan Lakshmanan | 49cdd62 | 2023-12-24 11:01:23 +0100 | [diff] [blame] | 6029 | < |
| 6030 | A List or a String argument is also supported. In these |
| 6031 | cases, items() returns a List with the index and the value at |
| 6032 | the index. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6033 | |
Yegappan Lakshmanan | 49cdd62 | 2023-12-24 11:01:23 +0100 | [diff] [blame] | 6034 | Can also be used as a |method|: > |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6035 | mydict->items() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 6036 | < |
| 6037 | Return type: list<list<any>> or list<any> |
| 6038 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6039 | |
| 6040 | job_ functions are documented here: |job-functions-details| |
| 6041 | |
| 6042 | |
| 6043 | join({list} [, {sep}]) *join()* |
| 6044 | Join the items in {list} together into one String. |
| 6045 | When {sep} is specified it is put in between the items. If |
| 6046 | {sep} is omitted a single space is used. |
| 6047 | Note that {sep} is not added at the end. You might want to |
| 6048 | add it there too: > |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 6049 | let lines = join(mylist, "\n") .. "\n" |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6050 | < String items are used as-is. |Lists| and |Dictionaries| are |
| 6051 | converted into a string like with |string()|. |
| 6052 | The opposite function is |split()|. |
| 6053 | |
| 6054 | Can also be used as a |method|: > |
| 6055 | mylist->join() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 6056 | < |
| 6057 | Return type: |String| |
| 6058 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6059 | |
| 6060 | js_decode({string}) *js_decode()* |
| 6061 | This is similar to |json_decode()| with these differences: |
| 6062 | - Object key names do not have to be in quotes. |
| 6063 | - Strings can be in single quotes. |
| 6064 | - Empty items in an array (between two commas) are allowed and |
| 6065 | result in v:none items. |
| 6066 | |
| 6067 | Can also be used as a |method|: > |
| 6068 | ReadObject()->js_decode() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 6069 | < |
| 6070 | Return type: any, depending on {varname} |
| 6071 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6072 | |
| 6073 | js_encode({expr}) *js_encode()* |
| 6074 | This is similar to |json_encode()| with these differences: |
| 6075 | - Object key names are not in quotes. |
| 6076 | - v:none items in an array result in an empty item between |
| 6077 | commas. |
| 6078 | For example, the Vim object: |
| 6079 | [1,v:none,{"one":1},v:none] ~ |
| 6080 | Will be encoded as: |
| 6081 | [1,,{one:1},,] ~ |
| 6082 | While json_encode() would produce: |
| 6083 | [1,null,{"one":1},null] ~ |
| 6084 | This encoding is valid for JavaScript. It is more efficient |
| 6085 | than JSON, especially when using an array with optional items. |
| 6086 | |
| 6087 | Can also be used as a |method|: > |
| 6088 | GetObject()->js_encode() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 6089 | < |
| 6090 | Return type: |String| |
| 6091 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6092 | |
Bram Moolenaar | 2f0936c | 2022-01-08 21:51:59 +0000 | [diff] [blame] | 6093 | json_decode({string}) *json_decode()* *E491* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6094 | This parses a JSON formatted string and returns the equivalent |
| 6095 | in Vim values. See |json_encode()| for the relation between |
| 6096 | JSON and Vim values. |
| 6097 | The decoding is permissive: |
| 6098 | - A trailing comma in an array and object is ignored, e.g. |
| 6099 | "[1, 2, ]" is the same as "[1, 2]". |
| 6100 | - Integer keys are accepted in objects, e.g. {1:2} is the |
| 6101 | same as {"1":2}. |
| 6102 | - More floating point numbers are recognized, e.g. "1." for |
| 6103 | "1.0", or "001.2" for "1.2". Special floating point values |
| 6104 | "Infinity", "-Infinity" and "NaN" (capitalization ignored) |
| 6105 | are accepted. |
| 6106 | - Leading zeroes in integer numbers are ignored, e.g. "012" |
| 6107 | for "12" or "-012" for "-12". |
| 6108 | - Capitalization is ignored in literal names null, true or |
| 6109 | false, e.g. "NULL" for "null", "True" for "true". |
| 6110 | - Control characters U+0000 through U+001F which are not |
| 6111 | escaped in strings are accepted, e.g. " " (tab |
| 6112 | character in string) for "\t". |
| 6113 | - An empty JSON expression or made of only spaces is accepted |
| 6114 | and results in v:none. |
| 6115 | - Backslash in an invalid 2-character sequence escape is |
| 6116 | ignored, e.g. "\a" is decoded as "a". |
| 6117 | - A correct surrogate pair in JSON strings should normally be |
| 6118 | a 12 character sequence such as "\uD834\uDD1E", but |
| 6119 | json_decode() silently accepts truncated surrogate pairs |
| 6120 | such as "\uD834" or "\uD834\u" |
| 6121 | *E938* |
| 6122 | A duplicate key in an object, valid in rfc7159, is not |
| 6123 | accepted by json_decode() as the result must be a valid Vim |
| 6124 | type, e.g. this fails: {"a":"b", "a":"c"} |
| 6125 | |
| 6126 | Can also be used as a |method|: > |
| 6127 | ReadObject()->json_decode() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 6128 | < |
| 6129 | Return type: any, depending on {varname} |
| 6130 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6131 | |
| 6132 | json_encode({expr}) *json_encode()* |
| 6133 | Encode {expr} as JSON and return this as a string. |
| 6134 | The encoding is specified in: |
| 6135 | https://tools.ietf.org/html/rfc7159.html |
Bram Moolenaar | a2baa73 | 2022-02-04 16:09:54 +0000 | [diff] [blame] | 6136 | Vim values are converted as follows: *E1161* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6137 | |Number| decimal number |
| 6138 | |Float| floating point number |
| 6139 | Float nan "NaN" |
| 6140 | Float inf "Infinity" |
| 6141 | Float -inf "-Infinity" |
| 6142 | |String| in double quotes (possibly null) |
| 6143 | |Funcref| not possible, error |
| 6144 | |List| as an array (possibly null); when |
| 6145 | used recursively: [] |
| 6146 | |Dict| as an object (possibly null); when |
| 6147 | used recursively: {} |
| 6148 | |Blob| as an array of the individual bytes |
| 6149 | v:false "false" |
| 6150 | v:true "true" |
| 6151 | v:none "null" |
| 6152 | v:null "null" |
| 6153 | Note that NaN and Infinity are passed on as values. This is |
| 6154 | missing in the JSON standard, but several implementations do |
| 6155 | allow it. If not then you will get an error. |
Bram Moolenaar | cbaff5e | 2022-04-08 17:45:08 +0100 | [diff] [blame] | 6156 | If a string contains an illegal character then the replacement |
| 6157 | character 0xfffd is used. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6158 | |
| 6159 | Can also be used as a |method|: > |
| 6160 | GetObject()->json_encode() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 6161 | < |
| 6162 | Return type: |String| |
| 6163 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6164 | |
| 6165 | keys({dict}) *keys()* |
| 6166 | Return a |List| with all the keys of {dict}. The |List| is in |
| 6167 | arbitrary order. Also see |items()| and |values()|. |
| 6168 | |
| 6169 | Can also be used as a |method|: > |
| 6170 | mydict->keys() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 6171 | < |
| 6172 | Return type: list<string> |
| 6173 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6174 | |
zeertzjq | cdc8393 | 2022-09-12 13:38:41 +0100 | [diff] [blame] | 6175 | keytrans({string}) *keytrans()* |
| 6176 | Turn the internal byte representation of keys into a form that |
| 6177 | can be used for |:map|. E.g. > |
| 6178 | :let xx = "\<C-Home>" |
| 6179 | :echo keytrans(xx) |
| 6180 | < <C-Home> |
| 6181 | |
| 6182 | Can also be used as a |method|: > |
| 6183 | "\<C-Home>"->keytrans() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 6184 | < |
| 6185 | Return type: |String| |
zeertzjq | cdc8393 | 2022-09-12 13:38:41 +0100 | [diff] [blame] | 6186 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 6187 | |
| 6188 | len({expr}) *len()* *E701* |
| 6189 | The result is a Number, which is the length of the argument. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6190 | When {expr} is a String or a Number the length in bytes is |
| 6191 | used, as with |strlen()|. |
| 6192 | When {expr} is a |List| the number of items in the |List| is |
| 6193 | returned. |
| 6194 | When {expr} is a |Blob| the number of bytes is returned. |
| 6195 | When {expr} is a |Dictionary| the number of entries in the |
| 6196 | |Dictionary| is returned. |
mityu | 7f0bba2 | 2024-03-29 10:14:41 +0100 | [diff] [blame] | 6197 | When {expr} is an |Object|, invokes the len() method in the |
| 6198 | object (if present) to get the length (|object-len()|). |
| 6199 | Otherwise returns zero. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6200 | |
| 6201 | Can also be used as a |method|: > |
| 6202 | mylist->len() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 6203 | < |
| 6204 | Return type: |Number| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6205 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 6206 | |
| 6207 | *libcall()* *E364* *E368* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6208 | libcall({libname}, {funcname}, {argument}) |
| 6209 | Call function {funcname} in the run-time library {libname} |
| 6210 | with single argument {argument}. |
| 6211 | This is useful to call functions in a library that you |
| 6212 | especially made to be used with Vim. Since only one argument |
| 6213 | is possible, calling standard library functions is rather |
| 6214 | limited. |
| 6215 | The result is the String returned by the function. If the |
| 6216 | function returns NULL, this will appear as an empty string "" |
| 6217 | to Vim. |
| 6218 | If the function returns a number, use libcallnr()! |
| 6219 | If {argument} is a number, it is passed to the function as an |
| 6220 | int; if {argument} is a string, it is passed as a |
| 6221 | null-terminated string. |
| 6222 | This function will fail in |restricted-mode|. |
| 6223 | |
| 6224 | libcall() allows you to write your own 'plug-in' extensions to |
| 6225 | Vim without having to recompile the program. It is NOT a |
| 6226 | means to call system functions! If you try to do so Vim will |
| 6227 | very probably crash. |
| 6228 | |
| 6229 | For Win32, the functions you write must be placed in a DLL |
| 6230 | and use the normal C calling convention (NOT Pascal which is |
| 6231 | used in Windows System DLLs). The function must take exactly |
| 6232 | one parameter, either a character pointer or a long integer, |
| 6233 | and must return a character pointer or NULL. The character |
| 6234 | pointer returned must point to memory that will remain valid |
| 6235 | after the function has returned (e.g. in static data in the |
| 6236 | DLL). If it points to allocated memory, that memory will |
| 6237 | leak away. Using a static buffer in the function should work, |
| 6238 | it's then freed when the DLL is unloaded. |
| 6239 | |
| 6240 | WARNING: If the function returns a non-valid pointer, Vim may |
| 6241 | crash! This also happens if the function returns a number, |
| 6242 | because Vim thinks it's a pointer. |
| 6243 | For Win32 systems, {libname} should be the filename of the DLL |
| 6244 | without the ".DLL" suffix. A full path is only required if |
| 6245 | the DLL is not in the usual places. |
| 6246 | For Unix: When compiling your own plugins, remember that the |
| 6247 | object code must be compiled as position-independent ('PIC'). |
| 6248 | {only in Win32 and some Unix versions, when the |+libcall| |
| 6249 | feature is present} |
| 6250 | Examples: > |
| 6251 | :echo libcall("libc.so", "getenv", "HOME") |
| 6252 | |
| 6253 | < Can also be used as a |method|, the base is passed as the |
| 6254 | third argument: > |
| 6255 | GetValue()->libcall("libc.so", "getenv") |
| 6256 | < |
| 6257 | *libcallnr()* |
| 6258 | libcallnr({libname}, {funcname}, {argument}) |
| 6259 | Just like |libcall()|, but used for a function that returns an |
| 6260 | int instead of a string. |
| 6261 | {only in Win32 on some Unix versions, when the |+libcall| |
| 6262 | feature is present} |
| 6263 | Examples: > |
| 6264 | :echo libcallnr("/usr/lib/libc.so", "getpid", "") |
| 6265 | :call libcallnr("libc.so", "printf", "Hello World!\n") |
| 6266 | :call libcallnr("libc.so", "sleep", 10) |
| 6267 | < |
| 6268 | Can also be used as a |method|, the base is passed as the |
| 6269 | third argument: > |
| 6270 | GetValue()->libcallnr("libc.so", "printf") |
| 6271 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 6272 | Return type: |String| |
| 6273 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6274 | |
| 6275 | line({expr} [, {winid}]) *line()* |
| 6276 | The result is a Number, which is the line number of the file |
| 6277 | position given with {expr}. The {expr} argument is a string. |
zeertzjq | 02f3eba | 2024-06-12 20:45:24 +0200 | [diff] [blame] | 6278 | See |getpos()| for accepted positions. |
| 6279 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6280 | To get the column number use |col()|. To get both use |
| 6281 | |getpos()|. |
zeertzjq | 02f3eba | 2024-06-12 20:45:24 +0200 | [diff] [blame] | 6282 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6283 | With the optional {winid} argument the values are obtained for |
| 6284 | that window instead of the current window. |
zeertzjq | 02f3eba | 2024-06-12 20:45:24 +0200 | [diff] [blame] | 6285 | |
Bram Moolenaar | 6ba83ba | 2022-06-12 22:15:57 +0100 | [diff] [blame] | 6286 | Returns 0 for invalid values of {expr} and {winid}. |
zeertzjq | 02f3eba | 2024-06-12 20:45:24 +0200 | [diff] [blame] | 6287 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6288 | Examples: > |
| 6289 | line(".") line number of the cursor |
| 6290 | line(".", winid) idem, in window "winid" |
| 6291 | line("'t") line number of mark t |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 6292 | line("'" .. marker) line number of mark marker |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6293 | < |
| 6294 | To jump to the last known position when opening a file see |
| 6295 | |last-position-jump|. |
| 6296 | |
| 6297 | Can also be used as a |method|: > |
| 6298 | GetValue()->line() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 6299 | < |
| 6300 | Return type: |Number| |
| 6301 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6302 | |
| 6303 | line2byte({lnum}) *line2byte()* |
| 6304 | Return the byte count from the start of the buffer for line |
| 6305 | {lnum}. This includes the end-of-line character, depending on |
| 6306 | the 'fileformat' option for the current buffer. The first |
| 6307 | line returns 1. 'encoding' matters, 'fileencoding' is ignored. |
| 6308 | This can also be used to get the byte count for the line just |
| 6309 | below the last line: > |
| 6310 | line2byte(line("$") + 1) |
| 6311 | < This is the buffer size plus one. If 'fileencoding' is empty |
| 6312 | it is the file size plus one. {lnum} is used like with |
| 6313 | |getline()|. When {lnum} is invalid, or the |+byte_offset| |
| 6314 | feature has been disabled at compile time, -1 is returned. |
| 6315 | Also see |byte2line()|, |go| and |:goto|. |
| 6316 | |
| 6317 | Can also be used as a |method|: > |
| 6318 | GetLnum()->line2byte() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 6319 | < |
| 6320 | Return type: |Number| |
| 6321 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6322 | |
| 6323 | lispindent({lnum}) *lispindent()* |
| 6324 | Get the amount of indent for line {lnum} according the lisp |
| 6325 | indenting rules, as with 'lisp'. |
| 6326 | The indent is counted in spaces, the value of 'tabstop' is |
| 6327 | relevant. {lnum} is used just like in |getline()|. |
Bram Moolenaar | 8e145b8 | 2022-05-21 20:17:31 +0100 | [diff] [blame] | 6328 | When {lnum} is invalid -1 is returned. In |Vim9| script an |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6329 | error is given. |
| 6330 | |
| 6331 | Can also be used as a |method|: > |
| 6332 | GetLnum()->lispindent() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 6333 | < |
| 6334 | Return type: |Number| |
| 6335 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6336 | |
| 6337 | list2blob({list}) *list2blob()* |
| 6338 | Return a Blob concatenating all the number values in {list}. |
| 6339 | Examples: > |
| 6340 | list2blob([1, 2, 3, 4]) returns 0z01020304 |
| 6341 | list2blob([]) returns 0z |
| 6342 | < Returns an empty Blob on error. If one of the numbers is |
| 6343 | negative or more than 255 error *E1239* is given. |
| 6344 | |
| 6345 | |blob2list()| does the opposite. |
| 6346 | |
| 6347 | Can also be used as a |method|: > |
| 6348 | GetList()->list2blob() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 6349 | < |
| 6350 | Return type: |Blob| |
| 6351 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6352 | |
| 6353 | list2str({list} [, {utf8}]) *list2str()* |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 6354 | Convert each number in {list} to a character string and |
| 6355 | concatenates them all. Examples: > |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6356 | list2str([32]) returns " " |
| 6357 | list2str([65, 66, 67]) returns "ABC" |
| 6358 | < The same can be done (slowly) with: > |
| 6359 | join(map(list, {nr, val -> nr2char(val)}), '') |
| 6360 | < |str2list()| does the opposite. |
| 6361 | |
| 6362 | When {utf8} is omitted or zero, the current 'encoding' is used. |
| 6363 | When {utf8} is TRUE, always return UTF-8 characters. |
| 6364 | With UTF-8 composing characters work as expected: > |
| 6365 | list2str([97, 769]) returns "á" |
| 6366 | < |
Bram Moolenaar | 6ba83ba | 2022-06-12 22:15:57 +0100 | [diff] [blame] | 6367 | Returns an empty string on error. |
| 6368 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6369 | Can also be used as a |method|: > |
| 6370 | GetList()->list2str() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 6371 | < |
| 6372 | Return type: |String| |
| 6373 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6374 | |
| 6375 | listener_add({callback} [, {buf}]) *listener_add()* |
| 6376 | Add a callback function that will be invoked when changes have |
| 6377 | been made to buffer {buf}. |
| 6378 | {buf} refers to a buffer name or number. For the accepted |
| 6379 | values, see |bufname()|. When {buf} is omitted the current |
| 6380 | buffer is used. |
| 6381 | Returns a unique ID that can be passed to |listener_remove()|. |
| 6382 | |
| 6383 | The {callback} is invoked with five arguments: |
Bram Moolenaar | 944697a | 2022-02-20 19:48:20 +0000 | [diff] [blame] | 6384 | bufnr the buffer that was changed |
| 6385 | start first changed line number |
| 6386 | end first line number below the change |
| 6387 | added number of lines added, negative if lines were |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6388 | deleted |
Bram Moolenaar | 944697a | 2022-02-20 19:48:20 +0000 | [diff] [blame] | 6389 | changes a List of items with details about the changes |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6390 | |
| 6391 | Example: > |
| 6392 | func Listener(bufnr, start, end, added, changes) |
| 6393 | echo 'lines ' .. a:start .. ' until ' .. a:end .. ' changed' |
| 6394 | endfunc |
| 6395 | call listener_add('Listener', bufnr) |
| 6396 | |
Bram Moolenaar | 944697a | 2022-02-20 19:48:20 +0000 | [diff] [blame] | 6397 | < The List cannot be changed. Each item in "changes" is a |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6398 | dictionary with these entries: |
| 6399 | lnum the first line number of the change |
| 6400 | end the first line below the change |
| 6401 | added number of lines added; negative if lines were |
| 6402 | deleted |
| 6403 | col first column in "lnum" that was affected by |
| 6404 | the change; one if unknown or the whole line |
| 6405 | was affected; this is a byte index, first |
| 6406 | character has a value of one. |
Bram Moolenaar | 3c053a1 | 2022-10-16 13:11:12 +0100 | [diff] [blame] | 6407 | When lines are inserted (not when a line is split, e.g. by |
| 6408 | typing CR in Insert mode) the values are: |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6409 | lnum line above which the new line is added |
| 6410 | end equal to "lnum" |
| 6411 | added number of lines inserted |
| 6412 | col 1 |
| 6413 | When lines are deleted the values are: |
| 6414 | lnum the first deleted line |
| 6415 | end the line below the first deleted line, before |
| 6416 | the deletion was done |
| 6417 | added negative, number of lines deleted |
| 6418 | col 1 |
| 6419 | When lines are changed: |
| 6420 | lnum the first changed line |
| 6421 | end the line below the last changed line |
| 6422 | added 0 |
| 6423 | col first column with a change or 1 |
| 6424 | |
| 6425 | The entries are in the order the changes were made, thus the |
| 6426 | most recent change is at the end. The line numbers are valid |
| 6427 | when the callback is invoked, but later changes may make them |
| 6428 | invalid, thus keeping a copy for later might not work. |
| 6429 | |
| 6430 | The {callback} is invoked just before the screen is updated, |
| 6431 | when |listener_flush()| is called or when a change is being |
| 6432 | made that changes the line count in a way it causes a line |
| 6433 | number in the list of changes to become invalid. |
| 6434 | |
| 6435 | The {callback} is invoked with the text locked, see |
| 6436 | |textlock|. If you do need to make changes to the buffer, use |
| 6437 | a timer to do this later |timer_start()|. |
| 6438 | |
| 6439 | The {callback} is not invoked when the buffer is first loaded. |
| 6440 | Use the |BufReadPost| autocmd event to handle the initial text |
| 6441 | of a buffer. |
| 6442 | The {callback} is also not invoked when the buffer is |
| 6443 | unloaded, use the |BufUnload| autocmd event for that. |
| 6444 | |
Bram Moolenaar | 6ba83ba | 2022-06-12 22:15:57 +0100 | [diff] [blame] | 6445 | Returns zero if {callback} or {buf} is invalid. |
| 6446 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6447 | Can also be used as a |method|, the base is passed as the |
| 6448 | second argument: > |
| 6449 | GetBuffer()->listener_add(callback) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 6450 | < |
| 6451 | Return type: |Number| |
| 6452 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6453 | |
| 6454 | listener_flush([{buf}]) *listener_flush()* |
| 6455 | Invoke listener callbacks for buffer {buf}. If there are no |
| 6456 | pending changes then no callbacks are invoked. |
| 6457 | |
| 6458 | {buf} refers to a buffer name or number. For the accepted |
| 6459 | values, see |bufname()|. When {buf} is omitted the current |
| 6460 | buffer is used. |
| 6461 | |
| 6462 | Can also be used as a |method|: > |
| 6463 | GetBuffer()->listener_flush() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 6464 | < |
| 6465 | Return type: |Number| |
| 6466 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6467 | |
| 6468 | listener_remove({id}) *listener_remove()* |
| 6469 | Remove a listener previously added with listener_add(). |
| 6470 | Returns FALSE when {id} could not be found, TRUE when {id} was |
| 6471 | removed. |
| 6472 | |
| 6473 | Can also be used as a |method|: > |
| 6474 | GetListenerId()->listener_remove() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 6475 | < |
| 6476 | Return type: |Number| |
| 6477 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6478 | |
| 6479 | localtime() *localtime()* |
| 6480 | Return the current time, measured as seconds since 1st Jan |
| 6481 | 1970. See also |strftime()|, |strptime()| and |getftime()|. |
| 6482 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 6483 | Return type: |Number| |
| 6484 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6485 | |
| 6486 | log({expr}) *log()* |
| 6487 | Return the natural logarithm (base e) of {expr} as a |Float|. |
| 6488 | {expr} must evaluate to a |Float| or a |Number| in the range |
| 6489 | (0, inf]. |
Bram Moolenaar | 6ba83ba | 2022-06-12 22:15:57 +0100 | [diff] [blame] | 6490 | Returns 0.0 if {expr} is not a |Float| or a |Number|. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6491 | Examples: > |
| 6492 | :echo log(10) |
| 6493 | < 2.302585 > |
| 6494 | :echo log(exp(5)) |
| 6495 | < 5.0 |
| 6496 | |
| 6497 | Can also be used as a |method|: > |
| 6498 | Compute()->log() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 6499 | < |
| 6500 | Return type: |Float| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6501 | |
| 6502 | |
| 6503 | log10({expr}) *log10()* |
| 6504 | Return the logarithm of Float {expr} to base 10 as a |Float|. |
| 6505 | {expr} must evaluate to a |Float| or a |Number|. |
Bram Moolenaar | 6ba83ba | 2022-06-12 22:15:57 +0100 | [diff] [blame] | 6506 | Returns 0.0 if {expr} is not a |Float| or a |Number|. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6507 | Examples: > |
| 6508 | :echo log10(1000) |
| 6509 | < 3.0 > |
| 6510 | :echo log10(0.01) |
| 6511 | < -2.0 |
| 6512 | |
| 6513 | Can also be used as a |method|: > |
| 6514 | Compute()->log10() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 6515 | < |
| 6516 | Return type: |Float| |
| 6517 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6518 | |
| 6519 | luaeval({expr} [, {expr}]) *luaeval()* |
| 6520 | Evaluate Lua expression {expr} and return its result converted |
| 6521 | to Vim data structures. Second {expr} may hold additional |
| 6522 | argument accessible as _A inside first {expr}. |
| 6523 | Strings are returned as they are. |
| 6524 | Boolean objects are converted to numbers. |
Bram Moolenaar | 73e28dc | 2022-09-17 21:08:33 +0100 | [diff] [blame] | 6525 | Numbers are converted to |Float| values. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6526 | Dictionaries and lists obtained by vim.eval() are returned |
| 6527 | as-is. |
| 6528 | Other objects are returned as zero without any errors. |
| 6529 | See |lua-luaeval| for more details. |
| 6530 | Note that in a `:def` function local variables are not visible |
| 6531 | to {expr}. |
| 6532 | |
| 6533 | Can also be used as a |method|: > |
| 6534 | GetExpr()->luaeval() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 6535 | < |
| 6536 | Return type: any, depending on {expr} |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6537 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 6538 | {only available when compiled with the |+lua| feature} |
| 6539 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6540 | |
| 6541 | map({expr1}, {expr2}) *map()* |
| 6542 | {expr1} must be a |List|, |String|, |Blob| or |Dictionary|. |
Bram Moolenaar | 944697a | 2022-02-20 19:48:20 +0000 | [diff] [blame] | 6543 | When {expr1} is a |List| or |Dictionary|, replace each |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6544 | item in {expr1} with the result of evaluating {expr2}. |
| 6545 | For a |Blob| each byte is replaced. |
| 6546 | For a |String|, each character, including composing |
| 6547 | characters, is replaced. |
| 6548 | If the item type changes you may want to use |mapnew()| to |
| 6549 | create a new List or Dictionary. This is required when using |
| 6550 | Vim9 script. |
| 6551 | |
| 6552 | {expr2} must be a |String| or |Funcref|. |
| 6553 | |
| 6554 | If {expr2} is a |String|, inside {expr2} |v:val| has the value |
| 6555 | of the current item. For a |Dictionary| |v:key| has the key |
| 6556 | of the current item and for a |List| |v:key| has the index of |
| 6557 | the current item. For a |Blob| |v:key| has the index of the |
| 6558 | current byte. For a |String| |v:key| has the index of the |
| 6559 | current character. |
| 6560 | Example: > |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 6561 | :call map(mylist, '"> " .. v:val .. " <"') |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6562 | < This puts "> " before and " <" after each item in "mylist". |
| 6563 | |
| 6564 | Note that {expr2} is the result of an expression and is then |
| 6565 | used as an expression again. Often it is good to use a |
| 6566 | |literal-string| to avoid having to double backslashes. You |
| 6567 | still have to double ' quotes |
| 6568 | |
| 6569 | If {expr2} is a |Funcref| it is called with two arguments: |
| 6570 | 1. The key or the index of the current item. |
| 6571 | 2. the value of the current item. |
Bram Moolenaar | b59ae59 | 2022-11-23 23:46:31 +0000 | [diff] [blame] | 6572 | With a legacy script lambda you don't get an error if it only |
| 6573 | accepts one argument, but with a Vim9 lambda you get "E1106: |
| 6574 | One argument too many", the number of arguments must match. |
| 6575 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6576 | The function must return the new value of the item. Example |
| 6577 | that changes each value by "key-value": > |
| 6578 | func KeyValue(key, val) |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 6579 | return a:key .. '-' .. a:val |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6580 | endfunc |
| 6581 | call map(myDict, function('KeyValue')) |
| 6582 | < It is shorter when using a |lambda|: > |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 6583 | call map(myDict, {key, val -> key .. '-' .. val}) |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6584 | < If you do not use "val" you can leave it out: > |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 6585 | call map(myDict, {key -> 'item: ' .. key}) |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6586 | < If you do not use "key" you can use a short name: > |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 6587 | call map(myDict, {_, val -> 'item: ' .. val}) |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6588 | < |
| 6589 | The operation is done in-place for a |List| and |Dictionary|. |
| 6590 | If you want it to remain unmodified make a copy first: > |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 6591 | :let tlist = map(copy(mylist), ' v:val .. "\t"') |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6592 | |
| 6593 | < Returns {expr1}, the |List| or |Dictionary| that was filtered, |
| 6594 | or a new |Blob| or |String|. |
| 6595 | When an error is encountered while evaluating {expr2} no |
| 6596 | further items in {expr1} are processed. |
| 6597 | When {expr2} is a Funcref errors inside a function are ignored, |
| 6598 | unless it was defined with the "abort" flag. |
| 6599 | |
| 6600 | Can also be used as a |method|: > |
| 6601 | mylist->map(expr2) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 6602 | < |
| 6603 | Return type: |String|, |Blob|, list<{type}> or dict<{type}> |
| 6604 | depending on {expr1} |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6605 | |
| 6606 | |
| 6607 | maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()* |
| 6608 | When {dict} is omitted or zero: Return the rhs of mapping |
| 6609 | {name} in mode {mode}. The returned String has special |
| 6610 | characters translated like in the output of the ":map" command |
Ernie Rael | 0966120 | 2022-04-25 14:40:44 +0100 | [diff] [blame] | 6611 | listing. When {dict} is TRUE a dictionary is returned, see |
| 6612 | below. To get a list of all mappings see |maplist()|. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6613 | |
| 6614 | When there is no mapping for {name}, an empty String is |
Bram Moolenaar | 6ba83ba | 2022-06-12 22:15:57 +0100 | [diff] [blame] | 6615 | returned if {dict} is FALSE, otherwise returns an empty Dict. |
| 6616 | When the mapping for {name} is empty, then "<Nop>" is |
| 6617 | returned. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6618 | |
| 6619 | The {name} can have special key names, like in the ":map" |
| 6620 | command. |
| 6621 | |
| 6622 | {mode} can be one of these strings: |
| 6623 | "n" Normal |
| 6624 | "v" Visual (including Select) |
| 6625 | "o" Operator-pending |
| 6626 | "i" Insert |
| 6627 | "c" Cmd-line |
| 6628 | "s" Select |
| 6629 | "x" Visual |
| 6630 | "l" langmap |language-mapping| |
| 6631 | "t" Terminal-Job |
| 6632 | "" Normal, Visual and Operator-pending |
| 6633 | When {mode} is omitted, the modes for "" are used. |
| 6634 | |
| 6635 | When {abbr} is there and it is |TRUE| use abbreviations |
| 6636 | instead of mappings. |
| 6637 | |
| 6638 | When {dict} is there and it is |TRUE| return a dictionary |
| 6639 | containing all the information of the mapping with the |
Ernie Rael | 659c240 | 2022-04-24 18:40:28 +0100 | [diff] [blame] | 6640 | following items: *mapping-dict* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6641 | "lhs" The {lhs} of the mapping as it would be typed |
| 6642 | "lhsraw" The {lhs} of the mapping as raw bytes |
| 6643 | "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate |
| 6644 | form, only present when it differs from "lhsraw" |
| 6645 | "rhs" The {rhs} of the mapping as typed. |
| 6646 | "silent" 1 for a |:map-silent| mapping, else 0. |
| 6647 | "noremap" 1 if the {rhs} of the mapping is not remappable. |
| 6648 | "script" 1 if mapping was defined with <script>. |
| 6649 | "expr" 1 for an expression mapping (|:map-<expr>|). |
| 6650 | "buffer" 1 for a buffer local mapping (|:map-local|). |
| 6651 | "mode" Modes for which the mapping is defined. In |
| 6652 | addition to the modes mentioned above, these |
| 6653 | characters will be used: |
| 6654 | " " Normal, Visual and Operator-pending |
| 6655 | "!" Insert and Commandline mode |
| 6656 | (|mapmode-ic|) |
| 6657 | "sid" The script local ID, used for <sid> mappings |
Bram Moolenaar | 71badf9 | 2023-04-22 22:40:14 +0100 | [diff] [blame] | 6658 | (|<SID>|). Negative for special contexts. |
Bram Moolenaar | a9528b3 | 2022-01-18 20:51:35 +0000 | [diff] [blame] | 6659 | "scriptversion" The version of the script. 999999 for |
Bram Moolenaar | 2d8ed02 | 2022-05-21 13:08:16 +0100 | [diff] [blame] | 6660 | |Vim9| script. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6661 | "lnum" The line number in "sid", zero if unknown. |
| 6662 | "nowait" Do not wait for other, longer mappings. |
| 6663 | (|:map-<nowait>|). |
Bram Moolenaar | 921bde8 | 2022-05-09 19:50:35 +0100 | [diff] [blame] | 6664 | "abbr" True if this is an abbreviation |abbreviations|. |
Ernie Rael | d8f5f76 | 2022-05-10 17:50:39 +0100 | [diff] [blame] | 6665 | "mode_bits" Vim's internal binary representation of "mode". |
| 6666 | |mapset()| ignores this; only "mode" is used. |
| 6667 | See |maplist()| for usage examples. The values |
| 6668 | are from src/vim.h and may change in the future. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6669 | |
| 6670 | The dictionary can be used to restore a mapping with |
| 6671 | |mapset()|. |
| 6672 | |
| 6673 | The mappings local to the current buffer are checked first, |
| 6674 | then the global mappings. |
| 6675 | This function can be used to map a key even when it's already |
| 6676 | mapped, and have it do the original mapping too. Sketch: > |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 6677 | exe 'nnoremap <Tab> ==' .. maparg('<Tab>', 'n') |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6678 | |
| 6679 | < Can also be used as a |method|: > |
| 6680 | GetKey()->maparg('n') |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 6681 | < |
| 6682 | Return type: |String| or dict<any> depending on {dict} |
| 6683 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6684 | |
| 6685 | mapcheck({name} [, {mode} [, {abbr}]]) *mapcheck()* |
| 6686 | Check if there is a mapping that matches with {name} in mode |
| 6687 | {mode}. See |maparg()| for {mode} and special names in |
| 6688 | {name}. |
| 6689 | When {abbr} is there and it is |TRUE| use abbreviations |
| 6690 | instead of mappings. |
| 6691 | A match happens with a mapping that starts with {name} and |
| 6692 | with a mapping which is equal to the start of {name}. |
| 6693 | |
| 6694 | matches mapping "a" "ab" "abc" ~ |
| 6695 | mapcheck("a") yes yes yes |
| 6696 | mapcheck("abc") yes yes yes |
| 6697 | mapcheck("ax") yes no no |
| 6698 | mapcheck("b") no no no |
| 6699 | |
| 6700 | The difference with maparg() is that mapcheck() finds a |
| 6701 | mapping that matches with {name}, while maparg() only finds a |
| 6702 | mapping for {name} exactly. |
| 6703 | When there is no mapping that starts with {name}, an empty |
| 6704 | String is returned. If there is one, the RHS of that mapping |
| 6705 | is returned. If there are several mappings that start with |
| 6706 | {name}, the RHS of one of them is returned. This will be |
| 6707 | "<Nop>" if the RHS is empty. |
| 6708 | The mappings local to the current buffer are checked first, |
| 6709 | then the global mappings. |
| 6710 | This function can be used to check if a mapping can be added |
| 6711 | without being ambiguous. Example: > |
| 6712 | :if mapcheck("_vv") == "" |
| 6713 | : map _vv :set guifont=7x13<CR> |
| 6714 | :endif |
| 6715 | < This avoids adding the "_vv" mapping when there already is a |
| 6716 | mapping for "_v" or for "_vvv". |
| 6717 | |
| 6718 | Can also be used as a |method|: > |
| 6719 | GetKey()->mapcheck('n') |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 6720 | < |
| 6721 | Return type: |String| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6722 | |
| 6723 | |
Ernie Rael | 0966120 | 2022-04-25 14:40:44 +0100 | [diff] [blame] | 6724 | maplist([{abbr}]) *maplist()* |
| 6725 | Returns a |List| of all mappings. Each List item is a |Dict|, |
| 6726 | the same as what is returned by |maparg()|, see |
| 6727 | |mapping-dict|. When {abbr} is there and it is |TRUE| use |
| 6728 | abbreviations instead of mappings. |
| 6729 | |
| 6730 | Example to show all mappings with 'MultiMatch' in rhs: > |
| 6731 | vim9script |
| 6732 | echo maplist()->filter( |
| 6733 | (_, m) => match(m.rhs, 'MultiMatch') >= 0) |
Ernie Rael | d8f5f76 | 2022-05-10 17:50:39 +0100 | [diff] [blame] | 6734 | < It can be tricky to find mappings for particular |:map-modes|. |
| 6735 | |mapping-dict|'s "mode_bits" can simplify this. For example, |
| 6736 | the mode_bits for Normal, Insert or Command-line modes are |
| 6737 | 0x19. To find all the mappings available in those modes you |
| 6738 | can do: > |
| 6739 | vim9script |
| 6740 | var saved_maps = [] |
| 6741 | for m in maplist() |
| 6742 | if and(m.mode_bits, 0x19) != 0 |
| 6743 | saved_maps->add(m) |
| 6744 | endif |
| 6745 | endfor |
| 6746 | echo saved_maps->mapnew((_, m) => m.lhs) |
| 6747 | < The values of the mode_bits are defined in Vim's src/vim.h |
| 6748 | file and they can be discovered at runtime using |
| 6749 | |:map-commands| and "maplist()". Example: > |
| 6750 | vim9script |
| 6751 | omap xyzzy <Nop> |
| 6752 | var op_bit = maplist()->filter( |
| 6753 | (_, m) => m.lhs == 'xyzzy')[0].mode_bits |
| 6754 | ounmap xyzzy |
| 6755 | echo printf("Operator-pending mode bit: 0x%x", op_bit) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 6756 | < |
| 6757 | Return type: list<dict<any>> |
Ernie Rael | 0966120 | 2022-04-25 14:40:44 +0100 | [diff] [blame] | 6758 | |
| 6759 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6760 | mapnew({expr1}, {expr2}) *mapnew()* |
| 6761 | Like |map()| but instead of replacing items in {expr1} a new |
| 6762 | List or Dictionary is created and returned. {expr1} remains |
| 6763 | unchanged. Items can still be changed by {expr2}, if you |
| 6764 | don't want that use |deepcopy()| first. |
| 6765 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 6766 | Return type: |String|, |Blob|, list<{type}> or dict<{type}> |
| 6767 | depending on {expr1} |
| 6768 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6769 | |
| 6770 | mapset({mode}, {abbr}, {dict}) *mapset()* |
Ernie Rael | 51d04d1 | 2022-05-04 15:40:22 +0100 | [diff] [blame] | 6771 | mapset({dict}) |
| 6772 | Restore a mapping from a dictionary, possibly returned by |
| 6773 | |maparg()| or |maplist()|. A buffer mapping, when dict.buffer |
| 6774 | is true, is set on the current buffer; it is up to the caller |
Bram Moolenaar | 2d8ed02 | 2022-05-21 13:08:16 +0100 | [diff] [blame] | 6775 | to ensure that the intended buffer is the current buffer. This |
Ernie Rael | 51d04d1 | 2022-05-04 15:40:22 +0100 | [diff] [blame] | 6776 | feature allows copying mappings from one buffer to another. |
| 6777 | The dict.mode value may restore a single mapping that covers |
| 6778 | more than one mode, like with mode values of '!', ' ', 'nox', |
| 6779 | or 'v'. *E1276* |
| 6780 | |
| 6781 | In the first form, {mode} and {abbr} should be the same as |
| 6782 | for the call to |maparg()|. *E460* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6783 | {mode} is used to define the mode in which the mapping is set, |
| 6784 | not the "mode" entry in {dict}. |
| 6785 | Example for saving and restoring a mapping: > |
| 6786 | let save_map = maparg('K', 'n', 0, 1) |
| 6787 | nnoremap K somethingelse |
| 6788 | ... |
| 6789 | call mapset('n', 0, save_map) |
| 6790 | < Note that if you are going to replace a map in several modes, |
Ernie Rael | 51d04d1 | 2022-05-04 15:40:22 +0100 | [diff] [blame] | 6791 | e.g. with `:map!`, you need to save/restore the mapping for |
| 6792 | all of them, when they might differ. |
| 6793 | |
| 6794 | In the second form, with {dict} as the only argument, mode |
| 6795 | and abbr are taken from the dict. |
| 6796 | Example: > |
| 6797 | vim9script |
| 6798 | var save_maps = maplist()->filter( |
| 6799 | (_, m) => m.lhs == 'K') |
| 6800 | nnoremap K somethingelse |
| 6801 | cnoremap K somethingelse2 |
| 6802 | # ... |
| 6803 | unmap K |
| 6804 | for d in save_maps |
| 6805 | mapset(d) |
| 6806 | endfor |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 6807 | < |
| 6808 | Return type: |Number| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6809 | |
| 6810 | |
| 6811 | match({expr}, {pat} [, {start} [, {count}]]) *match()* |
| 6812 | When {expr} is a |List| then this returns the index of the |
| 6813 | first item where {pat} matches. Each item is used as a |
| 6814 | String, |Lists| and |Dictionaries| are used as echoed. |
| 6815 | |
| 6816 | Otherwise, {expr} is used as a String. The result is a |
| 6817 | Number, which gives the index (byte offset) in {expr} where |
| 6818 | {pat} matches. |
| 6819 | |
| 6820 | A match at the first character or |List| item returns zero. |
| 6821 | If there is no match -1 is returned. |
| 6822 | |
| 6823 | For getting submatches see |matchlist()|. |
| 6824 | Example: > |
| 6825 | :echo match("testing", "ing") " results in 4 |
| 6826 | :echo match([1, 'x'], '\a') " results in 1 |
| 6827 | < See |string-match| for how {pat} is used. |
| 6828 | *strpbrk()* |
| 6829 | Vim doesn't have a strpbrk() function. But you can do: > |
| 6830 | :let sepidx = match(line, '[.,;: \t]') |
| 6831 | < *strcasestr()* |
| 6832 | Vim doesn't have a strcasestr() function. But you can add |
| 6833 | "\c" to the pattern to ignore case: > |
| 6834 | :let idx = match(haystack, '\cneedle') |
| 6835 | < |
| 6836 | If {start} is given, the search starts from byte index |
| 6837 | {start} in a String or item {start} in a |List|. |
| 6838 | The result, however, is still the index counted from the |
| 6839 | first character/item. Example: > |
| 6840 | :echo match("testing", "ing", 2) |
| 6841 | < result is again "4". > |
| 6842 | :echo match("testing", "ing", 4) |
| 6843 | < result is again "4". > |
| 6844 | :echo match("testing", "t", 2) |
| 6845 | < result is "3". |
| 6846 | For a String, if {start} > 0 then it is like the string starts |
| 6847 | {start} bytes later, thus "^" will match at {start}. Except |
| 6848 | when {count} is given, then it's like matches before the |
| 6849 | {start} byte are ignored (this is a bit complicated to keep it |
| 6850 | backwards compatible). |
| 6851 | For a String, if {start} < 0, it will be set to 0. For a list |
| 6852 | the index is counted from the end. |
| 6853 | If {start} is out of range ({start} > strlen({expr}) for a |
| 6854 | String or {start} > len({expr}) for a |List|) -1 is returned. |
| 6855 | |
| 6856 | When {count} is given use the {count}'th match. When a match |
| 6857 | is found in a String the search for the next one starts one |
| 6858 | character further. Thus this example results in 1: > |
| 6859 | echo match("testing", "..", 0, 2) |
| 6860 | < In a |List| the search continues in the next item. |
| 6861 | Note that when {count} is added the way {start} works changes, |
| 6862 | see above. |
| 6863 | |
Yegappan Lakshmanan | a35235e | 2024-02-24 10:09:43 +0100 | [diff] [blame] | 6864 | *match-pattern* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6865 | See |pattern| for the patterns that are accepted. |
| 6866 | The 'ignorecase' option is used to set the ignore-caseness of |
| 6867 | the pattern. 'smartcase' is NOT used. The matching is always |
| 6868 | done like 'magic' is set and 'cpoptions' is empty. |
| 6869 | Note that a match at the start is preferred, thus when the |
| 6870 | pattern is using "*" (any number of matches) it tends to find |
| 6871 | zero matches at the start instead of a number of matches |
| 6872 | further down in the text. |
| 6873 | |
| 6874 | Can also be used as a |method|: > |
| 6875 | GetText()->match('word') |
| 6876 | GetList()->match('word') |
| 6877 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 6878 | Return type: |Number| |
| 6879 | |
| 6880 | |
Bram Moolenaar | 2f0936c | 2022-01-08 21:51:59 +0000 | [diff] [blame] | 6881 | *matchadd()* *E290* *E798* *E799* *E801* *E957* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6882 | matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]]) |
| 6883 | Defines a pattern to be highlighted in the current window (a |
| 6884 | "match"). It will be highlighted with {group}. Returns an |
| 6885 | identification number (ID), which can be used to delete the |
| 6886 | match using |matchdelete()|. The ID is bound to the window. |
| 6887 | Matching is case sensitive and magic, unless case sensitivity |
| 6888 | or magicness are explicitly overridden in {pattern}. The |
| 6889 | 'magic', 'smartcase' and 'ignorecase' options are not used. |
| 6890 | The "Conceal" value is special, it causes the match to be |
| 6891 | concealed. |
| 6892 | |
| 6893 | The optional {priority} argument assigns a priority to the |
| 6894 | match. A match with a high priority will have its |
| 6895 | highlighting overrule that of a match with a lower priority. |
| 6896 | A priority is specified as an integer (negative numbers are no |
| 6897 | exception). If the {priority} argument is not specified, the |
| 6898 | default priority is 10. The priority of 'hlsearch' is zero, |
| 6899 | hence all matches with a priority greater than zero will |
| 6900 | overrule it. Syntax highlighting (see 'syntax') is a separate |
| 6901 | mechanism, and regardless of the chosen priority a match will |
| 6902 | always overrule syntax highlighting. |
| 6903 | |
| 6904 | The optional {id} argument allows the request for a specific |
| 6905 | match ID. If a specified ID is already taken, an error |
| 6906 | message will appear and the match will not be added. An ID |
| 6907 | is specified as a positive integer (zero excluded). IDs 1, 2 |
| 6908 | and 3 are reserved for |:match|, |:2match| and |:3match|, |
Bram Moolenaar | 2ecbe53 | 2022-07-29 21:36:21 +0100 | [diff] [blame] | 6909 | respectively. 3 is reserved for use by the |matchparen| |
| 6910 | plugin. |
Bram Moolenaar | b529cfb | 2022-07-25 15:42:07 +0100 | [diff] [blame] | 6911 | If the {id} argument is not specified or -1, |matchadd()| |
Bram Moolenaar | 9f573a8 | 2022-09-29 13:50:08 +0100 | [diff] [blame] | 6912 | automatically chooses a free ID, which is at least 1000. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6913 | |
| 6914 | The optional {dict} argument allows for further custom |
| 6915 | values. Currently this is used to specify a match specific |
| 6916 | conceal character that will be shown for |hl-Conceal| |
| 6917 | highlighted matches. The dict can have the following members: |
| 6918 | |
| 6919 | conceal Special character to show instead of the |
| 6920 | match (only for |hl-Conceal| highlighted |
| 6921 | matches, see |:syn-cchar|) |
| 6922 | window Instead of the current window use the |
| 6923 | window with this number or window ID. |
| 6924 | |
| 6925 | The number of matches is not limited, as it is the case with |
| 6926 | the |:match| commands. |
| 6927 | |
Bram Moolenaar | 6ba83ba | 2022-06-12 22:15:57 +0100 | [diff] [blame] | 6928 | Returns -1 on error. |
| 6929 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6930 | Example: > |
| 6931 | :highlight MyGroup ctermbg=green guibg=green |
| 6932 | :let m = matchadd("MyGroup", "TODO") |
| 6933 | < Deletion of the pattern: > |
| 6934 | :call matchdelete(m) |
| 6935 | |
| 6936 | < A list of matches defined by |matchadd()| and |:match| are |
| 6937 | available from |getmatches()|. All matches can be deleted in |
| 6938 | one operation by |clearmatches()|. |
| 6939 | |
| 6940 | Can also be used as a |method|: > |
| 6941 | GetGroup()->matchadd('TODO') |
| 6942 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 6943 | Return type: |Number| |
| 6944 | |
| 6945 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6946 | *matchaddpos()* |
| 6947 | matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]]) |
| 6948 | Same as |matchadd()|, but requires a list of positions {pos} |
| 6949 | instead of a pattern. This command is faster than |matchadd()| |
| 6950 | because it does not require to handle regular expressions and |
| 6951 | sets buffer line boundaries to redraw screen. It is supposed |
| 6952 | to be used when fast match additions and deletions are |
| 6953 | required, for example to highlight matching parentheses. |
| 6954 | |
| 6955 | {pos} is a list of positions. Each position can be one of |
| 6956 | these: |
| 6957 | - A number. This whole line will be highlighted. The first |
| 6958 | line has number 1. |
| 6959 | - A list with one number, e.g., [23]. The whole line with this |
| 6960 | number will be highlighted. |
| 6961 | - A list with two numbers, e.g., [23, 11]. The first number is |
| 6962 | the line number, the second one is the column number (first |
| 6963 | column is 1, the value must correspond to the byte index as |
| 6964 | |col()| would return). The character at this position will |
| 6965 | be highlighted. |
| 6966 | - A list with three numbers, e.g., [23, 11, 3]. As above, but |
| 6967 | the third number gives the length of the highlight in bytes. |
| 6968 | |
Bram Moolenaar | 6ba83ba | 2022-06-12 22:15:57 +0100 | [diff] [blame] | 6969 | Returns -1 on error. |
| 6970 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6971 | Example: > |
| 6972 | :highlight MyGroup ctermbg=green guibg=green |
| 6973 | :let m = matchaddpos("MyGroup", [[23, 24], 34]) |
| 6974 | < Deletion of the pattern: > |
| 6975 | :call matchdelete(m) |
| 6976 | |
| 6977 | < Matches added by |matchaddpos()| are returned by |
| 6978 | |getmatches()|. |
| 6979 | |
| 6980 | Can also be used as a |method|: > |
| 6981 | GetGroup()->matchaddpos([23, 11]) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 6982 | < |
| 6983 | Return type: |Number| |
| 6984 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 6985 | |
| 6986 | matcharg({nr}) *matcharg()* |
| 6987 | Selects the {nr} match item, as set with a |:match|, |
| 6988 | |:2match| or |:3match| command. |
| 6989 | Return a |List| with two elements: |
| 6990 | The name of the highlight group used |
| 6991 | The pattern used. |
| 6992 | When {nr} is not 1, 2 or 3 returns an empty |List|. |
| 6993 | When there is no match item set returns ['', '']. |
| 6994 | This is useful to save and restore a |:match|. |
| 6995 | Highlighting matches using the |:match| commands are limited |
| 6996 | to three matches. |matchadd()| does not have this limitation. |
| 6997 | |
| 6998 | Can also be used as a |method|: > |
| 6999 | GetMatch()->matcharg() |
Yegappan Lakshmanan | f93b1c8 | 2024-01-04 22:28:46 +0100 | [diff] [blame] | 7000 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 7001 | Return type: list<string> |
| 7002 | |
Yegappan Lakshmanan | f93b1c8 | 2024-01-04 22:28:46 +0100 | [diff] [blame] | 7003 | *matchbufline()* |
| 7004 | matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict}]) |
| 7005 | Returns the |List| of matches in lines from {lnum} to {end} in |
| 7006 | buffer {buf} where {pat} matches. |
| 7007 | |
| 7008 | {lnum} and {end} can either be a line number or the string "$" |
| 7009 | to refer to the last line in {buf}. |
| 7010 | |
| 7011 | The {dict} argument supports following items: |
| 7012 | submatches include submatch information (|/\(|) |
| 7013 | |
| 7014 | For each match, a |Dict| with the following items is returned: |
| 7015 | byteidx starting byte index of the match |
Yegappan Lakshmanan | eb3475d | 2024-01-15 11:08:25 -0800 | [diff] [blame] | 7016 | lnum line number where there is a match |
| 7017 | text matched string |
Yegappan Lakshmanan | f93b1c8 | 2024-01-04 22:28:46 +0100 | [diff] [blame] | 7018 | Note that there can be multiple matches in a single line. |
| 7019 | |
| 7020 | This function works only for loaded buffers. First call |
| 7021 | |bufload()| if needed. |
| 7022 | |
Yegappan Lakshmanan | a35235e | 2024-02-24 10:09:43 +0100 | [diff] [blame] | 7023 | See |match-pattern| for information about the effect of some |
| 7024 | option settings on the pattern. |
| 7025 | |
Yegappan Lakshmanan | f93b1c8 | 2024-01-04 22:28:46 +0100 | [diff] [blame] | 7026 | When {buf} is not a valid buffer, the buffer is not loaded or |
| 7027 | {lnum} or {end} is not valid then an error is given and an |
| 7028 | empty |List| is returned. |
| 7029 | |
| 7030 | Examples: > |
Yegappan Lakshmanan | eb3475d | 2024-01-15 11:08:25 -0800 | [diff] [blame] | 7031 | " Assuming line 3 in buffer 5 contains "a" |
| 7032 | :echo matchbufline(5, '\<\k\+\>', 3, 3) |
| 7033 | [{'lnum': 3, 'byteidx': 0, 'text': 'a'}] |
| 7034 | " Assuming line 4 in buffer 10 contains "tik tok" |
| 7035 | :echo matchbufline(10, '\<\k\+\>', 1, 4) |
| 7036 | [{'lnum': 4, 'byteidx': 0, 'text': 'tik'}, {'lnum': 4, 'byteidx': 4, 'text': 'tok'}] |
Yegappan Lakshmanan | f93b1c8 | 2024-01-04 22:28:46 +0100 | [diff] [blame] | 7037 | < |
| 7038 | If {submatch} is present and is v:true, then submatches like |
Yegappan Lakshmanan | eb3475d | 2024-01-15 11:08:25 -0800 | [diff] [blame] | 7039 | "\1", "\2", etc. are also returned. Example: > |
| 7040 | " Assuming line 2 in buffer 2 contains "acd" |
| 7041 | :echo matchbufline(2, '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 2, 2 |
Yegappan Lakshmanan | f93b1c8 | 2024-01-04 22:28:46 +0100 | [diff] [blame] | 7042 | \ {'submatches': v:true}) |
Yegappan Lakshmanan | eb3475d | 2024-01-15 11:08:25 -0800 | [diff] [blame] | 7043 | [{'lnum': 2, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}] |
Yegappan Lakshmanan | f93b1c8 | 2024-01-04 22:28:46 +0100 | [diff] [blame] | 7044 | < The "submatches" List always contains 9 items. If a submatch |
| 7045 | is not found, then an empty string is returned for that |
| 7046 | submatch. |
| 7047 | |
| 7048 | Can also be used as a |method|: > |
| 7049 | GetBuffer()->matchbufline('mypat', 1, '$') |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 7050 | < |
| 7051 | Return type: list<dict<any>> or list<any> |
| 7052 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 7053 | |
| 7054 | matchdelete({id} [, {win}) *matchdelete()* *E802* *E803* |
| 7055 | Deletes a match with ID {id} previously defined by |matchadd()| |
| 7056 | or one of the |:match| commands. Returns 0 if successful, |
| 7057 | otherwise -1. See example for |matchadd()|. All matches can |
| 7058 | be deleted in one operation by |clearmatches()|. |
| 7059 | If {win} is specified, use the window with this number or |
| 7060 | window ID instead of the current window. |
| 7061 | |
| 7062 | Can also be used as a |method|: > |
| 7063 | GetMatch()->matchdelete() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 7064 | < |
| 7065 | Return type: |Number| |
| 7066 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 7067 | |
| 7068 | matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()* |
| 7069 | Same as |match()|, but return the index of first character |
| 7070 | after the match. Example: > |
| 7071 | :echo matchend("testing", "ing") |
| 7072 | < results in "7". |
| 7073 | *strspn()* *strcspn()* |
| 7074 | Vim doesn't have a strspn() or strcspn() function, but you can |
| 7075 | do it with matchend(): > |
| 7076 | :let span = matchend(line, '[a-zA-Z]') |
| 7077 | :let span = matchend(line, '[^a-zA-Z]') |
| 7078 | < Except that -1 is returned when there are no matches. |
| 7079 | |
| 7080 | The {start}, if given, has the same meaning as for |match()|. > |
| 7081 | :echo matchend("testing", "ing", 2) |
| 7082 | < results in "7". > |
| 7083 | :echo matchend("testing", "ing", 5) |
| 7084 | < result is "-1". |
| 7085 | When {expr} is a |List| the result is equal to |match()|. |
| 7086 | |
| 7087 | Can also be used as a |method|: > |
| 7088 | GetText()->matchend('word') |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 7089 | < |
| 7090 | Return type: |Number| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 7091 | |
| 7092 | |
| 7093 | matchfuzzy({list}, {str} [, {dict}]) *matchfuzzy()* |
| 7094 | If {list} is a list of strings, then returns a |List| with all |
| 7095 | the strings in {list} that fuzzy match {str}. The strings in |
| 7096 | the returned list are sorted based on the matching score. |
| 7097 | |
| 7098 | The optional {dict} argument always supports the following |
| 7099 | items: |
zeertzjq | 9af2bc0 | 2022-05-11 14:15:37 +0100 | [diff] [blame] | 7100 | matchseq When this item is present return only matches |
| 7101 | that contain the characters in {str} in the |
| 7102 | given sequence. |
Kazuyuki Miyagi | 47f1a55 | 2022-06-17 18:30:03 +0100 | [diff] [blame] | 7103 | limit Maximum number of matches in {list} to be |
| 7104 | returned. Zero means no limit. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 7105 | |
| 7106 | If {list} is a list of dictionaries, then the optional {dict} |
| 7107 | argument supports the following additional items: |
Yasuhiro Matsumoto | 9029a6e | 2022-04-16 12:35:35 +0100 | [diff] [blame] | 7108 | key Key of the item which is fuzzy matched against |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 7109 | {str}. The value of this item should be a |
| 7110 | string. |
| 7111 | text_cb |Funcref| that will be called for every item |
| 7112 | in {list} to get the text for fuzzy matching. |
| 7113 | This should accept a dictionary item as the |
| 7114 | argument and return the text for that item to |
| 7115 | use for fuzzy matching. |
| 7116 | |
| 7117 | {str} is treated as a literal string and regular expression |
| 7118 | matching is NOT supported. The maximum supported {str} length |
| 7119 | is 256. |
| 7120 | |
| 7121 | When {str} has multiple words each separated by white space, |
| 7122 | then the list of strings that have all the words is returned. |
| 7123 | |
| 7124 | If there are no matching strings or there is an error, then an |
| 7125 | empty list is returned. If length of {str} is greater than |
| 7126 | 256, then returns an empty list. |
| 7127 | |
Yasuhiro Matsumoto | 9029a6e | 2022-04-16 12:35:35 +0100 | [diff] [blame] | 7128 | When {limit} is given, matchfuzzy() will find up to this |
| 7129 | number of matches in {list} and return them in sorted order. |
| 7130 | |
Bram Moolenaar | 1588bc8 | 2022-03-08 21:35:07 +0000 | [diff] [blame] | 7131 | Refer to |fuzzy-matching| for more information about fuzzy |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 7132 | matching strings. |
| 7133 | |
| 7134 | Example: > |
| 7135 | :echo matchfuzzy(["clay", "crow"], "cay") |
| 7136 | < results in ["clay"]. > |
| 7137 | :echo getbufinfo()->map({_, v -> v.name})->matchfuzzy("ndl") |
| 7138 | < results in a list of buffer names fuzzy matching "ndl". > |
| 7139 | :echo getbufinfo()->matchfuzzy("ndl", {'key' : 'name'}) |
| 7140 | < results in a list of buffer information dicts with buffer |
| 7141 | names fuzzy matching "ndl". > |
| 7142 | :echo getbufinfo()->matchfuzzy("spl", |
| 7143 | \ {'text_cb' : {v -> v.name}}) |
| 7144 | < results in a list of buffer information dicts with buffer |
| 7145 | names fuzzy matching "spl". > |
| 7146 | :echo v:oldfiles->matchfuzzy("test") |
| 7147 | < results in a list of file names fuzzy matching "test". > |
| 7148 | :let l = readfile("buffer.c")->matchfuzzy("str") |
| 7149 | < results in a list of lines in "buffer.c" fuzzy matching "str". > |
| 7150 | :echo ['one two', 'two one']->matchfuzzy('two one') |
| 7151 | < results in ['two one', 'one two']. > |
| 7152 | :echo ['one two', 'two one']->matchfuzzy('two one', |
| 7153 | \ {'matchseq': 1}) |
| 7154 | < results in ['two one']. |
| 7155 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 7156 | Return type: list<string> or list<any> |
| 7157 | |
| 7158 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 7159 | matchfuzzypos({list}, {str} [, {dict}]) *matchfuzzypos()* |
| 7160 | Same as |matchfuzzy()|, but returns the list of matched |
| 7161 | strings, the list of character positions where characters |
| 7162 | in {str} matches and a list of matching scores. You can |
| 7163 | use |byteidx()| to convert a character position to a byte |
| 7164 | position. |
| 7165 | |
| 7166 | If {str} matches multiple times in a string, then only the |
| 7167 | positions for the best match is returned. |
| 7168 | |
| 7169 | If there are no matching strings or there is an error, then a |
| 7170 | list with three empty list items is returned. |
| 7171 | |
| 7172 | Example: > |
| 7173 | :echo matchfuzzypos(['testing'], 'tsg') |
| 7174 | < results in [['testing'], [[0, 2, 6]], [99]] > |
| 7175 | :echo matchfuzzypos(['clay', 'lacy'], 'la') |
| 7176 | < results in [['lacy', 'clay'], [[0, 1], [1, 2]], [153, 133]] > |
| 7177 | :echo [{'text': 'hello', 'id' : 10}]->matchfuzzypos('ll', {'key' : 'text'}) |
| 7178 | < results in [[{'id': 10, 'text': 'hello'}], [[2, 3]], [127]] |
| 7179 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 7180 | Return type: list<list<any>> |
| 7181 | |
| 7182 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 7183 | matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()* |
| 7184 | Same as |match()|, but return a |List|. The first item in the |
| 7185 | list is the matched string, same as what matchstr() would |
| 7186 | return. Following items are submatches, like "\1", "\2", etc. |
| 7187 | in |:substitute|. When an optional submatch didn't match an |
| 7188 | empty string is used. Example: > |
| 7189 | echo matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)') |
| 7190 | < Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', ''] |
| 7191 | When there is no match an empty list is returned. |
| 7192 | |
| 7193 | You can pass in a List, but that is not very useful. |
| 7194 | |
| 7195 | Can also be used as a |method|: > |
| 7196 | GetText()->matchlist('word') |
Yegappan Lakshmanan | f93b1c8 | 2024-01-04 22:28:46 +0100 | [diff] [blame] | 7197 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 7198 | Return type: list<string> or list<any> |
| 7199 | |
Yegappan Lakshmanan | f93b1c8 | 2024-01-04 22:28:46 +0100 | [diff] [blame] | 7200 | *matchstrlist()* |
| 7201 | matchstrlist({list}, {pat} [, {dict}]) |
| 7202 | Returns the |List| of matches in {list} where {pat} matches. |
| 7203 | {list} is a |List| of strings. {pat} is matched against each |
| 7204 | string in {list}. |
| 7205 | |
| 7206 | The {dict} argument supports following items: |
| 7207 | submatches include submatch information (|/\(|) |
| 7208 | |
| 7209 | For each match, a |Dict| with the following items is returned: |
| 7210 | byteidx starting byte index of the match. |
| 7211 | idx index in {list} of the match. |
| 7212 | text matched string |
| 7213 | submatches a List of submatches. Present only if |
| 7214 | "submatches" is set to v:true in {dict}. |
| 7215 | |
Yegappan Lakshmanan | a35235e | 2024-02-24 10:09:43 +0100 | [diff] [blame] | 7216 | See |match-pattern| for information about the effect of some |
| 7217 | option settings on the pattern. |
| 7218 | |
Yegappan Lakshmanan | f93b1c8 | 2024-01-04 22:28:46 +0100 | [diff] [blame] | 7219 | Example: > |
Yegappan Lakshmanan | eb3475d | 2024-01-15 11:08:25 -0800 | [diff] [blame] | 7220 | :echo matchstrlist(['tik tok'], '\<\k\+\>') |
| 7221 | [{'idx': 0, 'byteidx': 0, 'text': 'tik'}, {'idx': 0, 'byteidx': 4, 'text': 'tok'}] |
| 7222 | :echo matchstrlist(['a', 'b'], '\<\k\+\>') |
| 7223 | [{'idx': 0, 'byteidx': 0, 'text': 'a'}, {'idx': 1, 'byteidx': 0, 'text': 'b'}] |
Yegappan Lakshmanan | f93b1c8 | 2024-01-04 22:28:46 +0100 | [diff] [blame] | 7224 | < |
| 7225 | If "submatches" is present and is v:true, then submatches like |
| 7226 | "\1", "\2", etc. are also returned. Example: > |
| 7227 | :echo matchstrlist(['acd'], '\(a\)\?\(b\)\?\(c\)\?\(.*\)', |
| 7228 | \ #{submatches: v:true}) |
| 7229 | [{'idx': 0, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}] |
| 7230 | < The "submatches" List always contains 9 items. If a submatch |
| 7231 | is not found, then an empty string is returned for that |
| 7232 | submatch. |
| 7233 | |
| 7234 | Can also be used as a |method|: > |
| 7235 | GetListOfStrings()->matchstrlist('mypat') |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 7236 | < |
| 7237 | Return type: list<dict<any>> or list<any> |
| 7238 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 7239 | |
| 7240 | matchstr({expr}, {pat} [, {start} [, {count}]]) *matchstr()* |
| 7241 | Same as |match()|, but return the matched string. Example: > |
| 7242 | :echo matchstr("testing", "ing") |
| 7243 | < results in "ing". |
| 7244 | When there is no match "" is returned. |
| 7245 | The {start}, if given, has the same meaning as for |match()|. > |
| 7246 | :echo matchstr("testing", "ing", 2) |
| 7247 | < results in "ing". > |
| 7248 | :echo matchstr("testing", "ing", 5) |
| 7249 | < result is "". |
| 7250 | When {expr} is a |List| then the matching item is returned. |
| 7251 | The type isn't changed, it's not necessarily a String. |
| 7252 | |
| 7253 | Can also be used as a |method|: > |
| 7254 | GetText()->matchstr('word') |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 7255 | < |
| 7256 | Return type: |String| |
| 7257 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 7258 | |
| 7259 | matchstrpos({expr}, {pat} [, {start} [, {count}]]) *matchstrpos()* |
| 7260 | Same as |matchstr()|, but return the matched string, the start |
| 7261 | position and the end position of the match. Example: > |
| 7262 | :echo matchstrpos("testing", "ing") |
| 7263 | < results in ["ing", 4, 7]. |
| 7264 | When there is no match ["", -1, -1] is returned. |
| 7265 | The {start}, if given, has the same meaning as for |match()|. > |
| 7266 | :echo matchstrpos("testing", "ing", 2) |
| 7267 | < results in ["ing", 4, 7]. > |
| 7268 | :echo matchstrpos("testing", "ing", 5) |
| 7269 | < result is ["", -1, -1]. |
| 7270 | When {expr} is a |List| then the matching item, the index |
| 7271 | of first item where {pat} matches, the start position and the |
| 7272 | end position of the match are returned. > |
| 7273 | :echo matchstrpos([1, '__x'], '\a') |
| 7274 | < result is ["x", 1, 2, 3]. |
| 7275 | The type isn't changed, it's not necessarily a String. |
| 7276 | |
| 7277 | Can also be used as a |method|: > |
| 7278 | GetText()->matchstrpos('word') |
| 7279 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 7280 | Return type: list<any> |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 7281 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 7282 | |
| 7283 | max({expr}) *max()* |
| 7284 | Return the maximum value of all items in {expr}. Example: > |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 7285 | echo max([apples, pears, oranges]) |
| 7286 | |
| 7287 | < {expr} can be a |List| or a |Dictionary|. For a Dictionary, |
| 7288 | it returns the maximum of all values in the Dictionary. |
| 7289 | If {expr} is neither a List nor a Dictionary, or one of the |
| 7290 | items in {expr} cannot be used as a Number this results in |
| 7291 | an error. An empty |List| or |Dictionary| results in zero. |
| 7292 | |
| 7293 | Can also be used as a |method|: > |
| 7294 | mylist->max() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 7295 | < |
| 7296 | Return type: |Number| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 7297 | |
| 7298 | |
| 7299 | menu_info({name} [, {mode}]) *menu_info()* |
| 7300 | Return information about the specified menu {name} in |
| 7301 | mode {mode}. The menu name should be specified without the |
| 7302 | shortcut character ('&'). If {name} is "", then the top-level |
| 7303 | menu names are returned. |
| 7304 | |
| 7305 | {mode} can be one of these strings: |
| 7306 | "n" Normal |
| 7307 | "v" Visual (including Select) |
| 7308 | "o" Operator-pending |
| 7309 | "i" Insert |
| 7310 | "c" Cmd-line |
| 7311 | "s" Select |
| 7312 | "x" Visual |
| 7313 | "t" Terminal-Job |
| 7314 | "" Normal, Visual and Operator-pending |
| 7315 | "!" Insert and Cmd-line |
| 7316 | When {mode} is omitted, the modes for "" are used. |
| 7317 | |
| 7318 | Returns a |Dictionary| containing the following items: |
| 7319 | accel menu item accelerator text |menu-text| |
| 7320 | display display name (name without '&') |
| 7321 | enabled v:true if this menu item is enabled |
| 7322 | Refer to |:menu-enable| |
| 7323 | icon name of the icon file (for toolbar) |
| 7324 | |toolbar-icon| |
| 7325 | iconidx index of a built-in icon |
| 7326 | modes modes for which the menu is defined. In |
| 7327 | addition to the modes mentioned above, these |
| 7328 | characters will be used: |
| 7329 | " " Normal, Visual and Operator-pending |
| 7330 | name menu item name. |
| 7331 | noremenu v:true if the {rhs} of the menu item is not |
| 7332 | remappable else v:false. |
| 7333 | priority menu order priority |menu-priority| |
| 7334 | rhs right-hand-side of the menu item. The returned |
| 7335 | string has special characters translated like |
| 7336 | in the output of the ":menu" command listing. |
| 7337 | When the {rhs} of a menu item is empty, then |
| 7338 | "<Nop>" is returned. |
| 7339 | script v:true if script-local remapping of {rhs} is |
| 7340 | allowed else v:false. See |:menu-script|. |
| 7341 | shortcut shortcut key (character after '&' in |
| 7342 | the menu name) |menu-shortcut| |
| 7343 | silent v:true if the menu item is created |
| 7344 | with <silent> argument |:menu-silent| |
| 7345 | submenus |List| containing the names of |
| 7346 | all the submenus. Present only if the menu |
| 7347 | item has submenus. |
| 7348 | |
| 7349 | Returns an empty dictionary if the menu item is not found. |
| 7350 | |
| 7351 | Examples: > |
| 7352 | :echo menu_info('Edit.Cut') |
| 7353 | :echo menu_info('File.Save', 'n') |
| 7354 | |
| 7355 | " Display the entire menu hierarchy in a buffer |
| 7356 | func ShowMenu(name, pfx) |
| 7357 | let m = menu_info(a:name) |
| 7358 | call append(line('$'), a:pfx .. m.display) |
| 7359 | for child in m->get('submenus', []) |
| 7360 | call ShowMenu(a:name .. '.' .. escape(child, '.'), |
| 7361 | \ a:pfx .. ' ') |
| 7362 | endfor |
| 7363 | endfunc |
| 7364 | new |
| 7365 | for topmenu in menu_info('').submenus |
| 7366 | call ShowMenu(topmenu, '') |
| 7367 | endfor |
| 7368 | < |
| 7369 | Can also be used as a |method|: > |
| 7370 | GetMenuName()->menu_info('v') |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 7371 | < |
| 7372 | Return type: dict<any> |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 7373 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 7374 | min({expr}) *min()* |
| 7375 | Return the minimum value of all items in {expr}. Example: > |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 7376 | echo min([apples, pears, oranges]) |
| 7377 | |
| 7378 | < {expr} can be a |List| or a |Dictionary|. For a Dictionary, |
| 7379 | it returns the minimum of all values in the Dictionary. |
| 7380 | If {expr} is neither a List nor a Dictionary, or one of the |
| 7381 | items in {expr} cannot be used as a Number this results in |
| 7382 | an error. An empty |List| or |Dictionary| results in zero. |
| 7383 | |
| 7384 | Can also be used as a |method|: > |
| 7385 | mylist->min() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 7386 | < |
| 7387 | Return type: |Number| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 7388 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 7389 | |
| 7390 | mkdir({name} [, {flags} [, {prot}]]) *mkdir()* *E739* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 7391 | Create directory {name}. |
| 7392 | |
Bram Moolenaar | 938ae28 | 2023-02-20 20:44:55 +0000 | [diff] [blame] | 7393 | When {flags} is present it must be a string. An empty string |
| 7394 | has no effect. |
Bram Moolenaar | 6f14da1 | 2022-09-07 21:30:44 +0100 | [diff] [blame] | 7395 | |
Christian Brabandt | d6d4e13 | 2024-06-13 21:21:41 +0200 | [diff] [blame] | 7396 | {flags} can contain these character flags: |
| 7397 | "p" intermediate directories will be created as necessary |
| 7398 | "D" {name} will be deleted at the end of the current |
Christian Brabandt | c509c00 | 2024-06-14 20:22:05 +0200 | [diff] [blame] | 7399 | function, but not recursively |:defer| |
Christian Brabandt | d6d4e13 | 2024-06-13 21:21:41 +0200 | [diff] [blame] | 7400 | "R" {name} will be deleted recursively at the end of the |
Christian Brabandt | c509c00 | 2024-06-14 20:22:05 +0200 | [diff] [blame] | 7401 | current function |:defer| |
Bram Moolenaar | 938ae28 | 2023-02-20 20:44:55 +0000 | [diff] [blame] | 7402 | |
Christian Brabandt | d6d4e13 | 2024-06-13 21:21:41 +0200 | [diff] [blame] | 7403 | Note that when {name} has more than one part and "p" is used |
Bram Moolenaar | 6f14da1 | 2022-09-07 21:30:44 +0100 | [diff] [blame] | 7404 | some directories may already exist. Only the first one that |
| 7405 | is created and what it contains is scheduled to be deleted. |
| 7406 | E.g. when using: > |
| 7407 | call mkdir('subdir/tmp/autoload', 'pR') |
| 7408 | < and "subdir" already exists then "subdir/tmp" will be |
| 7409 | scheduled for deletion, like with: > |
| 7410 | defer delete('subdir/tmp', 'rf') |
| 7411 | < Note that if scheduling the defer fails the directory is not |
| 7412 | deleted. This should only happen when out of memory. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 7413 | |
| 7414 | If {prot} is given it is used to set the protection bits of |
| 7415 | the new directory. The default is 0o755 (rwxr-xr-x: r/w for |
| 7416 | the user, readable for others). Use 0o700 to make it |
| 7417 | unreadable for others. This is only used for the last part of |
| 7418 | {name}. Thus if you create /tmp/foo/bar then /tmp/foo will be |
| 7419 | created with 0o755. |
| 7420 | Example: > |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 7421 | :call mkdir($HOME .. "/tmp/foo/bar", "p", 0o700) |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 7422 | |
| 7423 | < This function is not available in the |sandbox|. |
| 7424 | |
| 7425 | There is no error if the directory already exists and the "p" |
| 7426 | flag is passed (since patch 8.0.1708). However, without the |
| 7427 | "p" option the call will fail. |
| 7428 | |
| 7429 | The function result is a Number, which is TRUE if the call was |
| 7430 | successful or FALSE if the directory creation failed or partly |
| 7431 | failed. |
| 7432 | |
| 7433 | Not available on all systems. To check use: > |
| 7434 | :if exists("*mkdir") |
| 7435 | |
| 7436 | < Can also be used as a |method|: > |
| 7437 | GetName()->mkdir() |
| 7438 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 7439 | Return type: |Number| |
| 7440 | |
| 7441 | |
| 7442 | mode([{expr}]) *mode()* |
| 7443 | Return a string that indicates the current mode. |
Doug Kearns | 9cd9e75 | 2024-04-07 17:42:17 +0200 | [diff] [blame] | 7444 | If {expr} is supplied and it evaluates to a non-zero Number or |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 7445 | a non-empty String (|non-zero-arg|), then the full mode is |
| 7446 | returned, otherwise only the first letter is returned. |
| 7447 | Also see |state()|. |
| 7448 | |
| 7449 | n Normal |
| 7450 | no Operator-pending |
| 7451 | nov Operator-pending (forced characterwise |o_v|) |
| 7452 | noV Operator-pending (forced linewise |o_V|) |
| 7453 | noCTRL-V Operator-pending (forced blockwise |o_CTRL-V|); |
| 7454 | CTRL-V is one character |
| 7455 | niI Normal using |i_CTRL-O| in |Insert-mode| |
| 7456 | niR Normal using |i_CTRL-O| in |Replace-mode| |
| 7457 | niV Normal using |i_CTRL-O| in |Virtual-Replace-mode| |
| 7458 | nt Terminal-Normal (insert goes to Terminal-Job mode) |
| 7459 | v Visual by character |
| 7460 | vs Visual by character using |v_CTRL-O| in Select mode |
| 7461 | V Visual by line |
| 7462 | Vs Visual by line using |v_CTRL-O| in Select mode |
| 7463 | CTRL-V Visual blockwise |
| 7464 | CTRL-Vs Visual blockwise using |v_CTRL-O| in Select mode |
| 7465 | s Select by character |
| 7466 | S Select by line |
| 7467 | CTRL-S Select blockwise |
| 7468 | i Insert |
| 7469 | ic Insert mode completion |compl-generic| |
| 7470 | ix Insert mode |i_CTRL-X| completion |
| 7471 | R Replace |R| |
| 7472 | Rc Replace mode completion |compl-generic| |
| 7473 | Rx Replace mode |i_CTRL-X| completion |
| 7474 | Rv Virtual Replace |gR| |
| 7475 | Rvc Virtual Replace mode completion |compl-generic| |
| 7476 | Rvx Virtual Replace mode |i_CTRL-X| completion |
| 7477 | c Command-line editing |
h-east | 71ebf3b | 2023-09-03 17:12:55 +0200 | [diff] [blame] | 7478 | ct Command-line editing via Terminal-Job mode |
zeertzjq | fcaeb3d | 2023-11-28 20:46:29 +0100 | [diff] [blame] | 7479 | cr Command-line editing overstrike mode |c_<Insert>| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 7480 | cv Vim Ex mode |gQ| |
zeertzjq | fcaeb3d | 2023-11-28 20:46:29 +0100 | [diff] [blame] | 7481 | cvr Vim Ex mode while in overstrike mode |c_<Insert>| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 7482 | ce Normal Ex mode |Q| |
| 7483 | r Hit-enter prompt |
| 7484 | rm The -- more -- prompt |
| 7485 | r? A |:confirm| query of some sort |
| 7486 | ! Shell or external command is executing |
| 7487 | t Terminal-Job mode: keys go to the job |
| 7488 | |
| 7489 | This is useful in the 'statusline' option or when used |
| 7490 | with |remote_expr()| In most other places it always returns |
| 7491 | "c" or "n". |
| 7492 | Note that in the future more modes and more specific modes may |
| 7493 | be added. It's better not to compare the whole string but only |
| 7494 | the leading character(s). |
| 7495 | Also see |visualmode()|. |
| 7496 | |
| 7497 | Can also be used as a |method|: > |
| 7498 | DoFull()->mode() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 7499 | < |
| 7500 | Return type: |String| |
| 7501 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 7502 | |
| 7503 | mzeval({expr}) *mzeval()* |
| 7504 | Evaluate MzScheme expression {expr} and return its result |
| 7505 | converted to Vim data structures. |
| 7506 | Numbers and strings are returned as they are. |
| 7507 | Pairs (including lists and improper lists) and vectors are |
| 7508 | returned as Vim |Lists|. |
| 7509 | Hash tables are represented as Vim |Dictionary| type with keys |
| 7510 | converted to strings. |
| 7511 | All other types are converted to string with display function. |
| 7512 | Examples: > |
| 7513 | :mz (define l (list 1 2 3)) |
| 7514 | :mz (define h (make-hash)) (hash-set! h "list" l) |
| 7515 | :echo mzeval("l") |
| 7516 | :echo mzeval("h") |
| 7517 | < |
| 7518 | Note that in a `:def` function local variables are not visible |
| 7519 | to {expr}. |
| 7520 | |
| 7521 | Can also be used as a |method|: > |
| 7522 | GetExpr()->mzeval() |
| 7523 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 7524 | Return type: any, depending on {expr} |
| 7525 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 7526 | {only available when compiled with the |+mzscheme| feature} |
| 7527 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 7528 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 7529 | nextnonblank({lnum}) *nextnonblank()* |
| 7530 | Return the line number of the first line at or below {lnum} |
| 7531 | that is not blank. Example: > |
| 7532 | if getline(nextnonblank(1)) =~ "Java" |
| 7533 | < When {lnum} is invalid or there is no non-blank line at or |
| 7534 | below it, zero is returned. |
| 7535 | {lnum} is used like with |getline()|. |
| 7536 | See also |prevnonblank()|. |
| 7537 | |
| 7538 | Can also be used as a |method|: > |
| 7539 | GetLnum()->nextnonblank() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 7540 | < |
| 7541 | Return type: |Number| |
| 7542 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 7543 | |
| 7544 | nr2char({expr} [, {utf8}]) *nr2char()* |
| 7545 | Return a string with a single character, which has the number |
| 7546 | value {expr}. Examples: > |
| 7547 | nr2char(64) returns "@" |
| 7548 | nr2char(32) returns " " |
| 7549 | < When {utf8} is omitted or zero, the current 'encoding' is used. |
| 7550 | Example for "utf-8": > |
| 7551 | nr2char(300) returns I with bow character |
| 7552 | < When {utf8} is TRUE, always return UTF-8 characters. |
| 7553 | Note that a NUL character in the file is specified with |
| 7554 | nr2char(10), because NULs are represented with newline |
| 7555 | characters. nr2char(0) is a real NUL and terminates the |
| 7556 | string, thus results in an empty string. |
| 7557 | To turn a list of character numbers into a string: > |
| 7558 | let list = [65, 66, 67] |
| 7559 | let str = join(map(list, {_, val -> nr2char(val)}), '') |
| 7560 | < Result: "ABC" |
| 7561 | |
| 7562 | Can also be used as a |method|: > |
| 7563 | GetNumber()->nr2char() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 7564 | < |
| 7565 | Return type: |String| |
| 7566 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 7567 | |
| 7568 | or({expr}, {expr}) *or()* |
| 7569 | Bitwise OR on the two arguments. The arguments are converted |
| 7570 | to a number. A List, Dict or Float argument causes an error. |
Bram Moolenaar | 5a6ec10 | 2022-05-27 21:58:00 +0100 | [diff] [blame] | 7571 | Also see `and()` and `xor()`. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 7572 | Example: > |
| 7573 | :let bits = or(bits, 0x80) |
| 7574 | < Can also be used as a |method|: > |
| 7575 | :let bits = bits->or(0x80) |
| 7576 | |
Bram Moolenaar | 5a6ec10 | 2022-05-27 21:58:00 +0100 | [diff] [blame] | 7577 | < Rationale: The reason this is a function and not using the "|" |
| 7578 | character like many languages, is that Vi has always used "|" |
| 7579 | to separate commands. In many places it would not be clear if |
| 7580 | "|" is an operator or a command separator. |
| 7581 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 7582 | Return type: |Number| |
| 7583 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 7584 | |
| 7585 | pathshorten({path} [, {len}]) *pathshorten()* |
| 7586 | Shorten directory names in the path {path} and return the |
| 7587 | result. The tail, the file name, is kept as-is. The other |
| 7588 | components in the path are reduced to {len} letters in length. |
| 7589 | If {len} is omitted or smaller than 1 then 1 is used (single |
| 7590 | letters). Leading '~' and '.' characters are kept. Examples: > |
| 7591 | :echo pathshorten('~/.vim/autoload/myfile.vim') |
| 7592 | < ~/.v/a/myfile.vim ~ |
| 7593 | > |
| 7594 | :echo pathshorten('~/.vim/autoload/myfile.vim', 2) |
| 7595 | < ~/.vi/au/myfile.vim ~ |
| 7596 | It doesn't matter if the path exists or not. |
Bram Moolenaar | 6ba83ba | 2022-06-12 22:15:57 +0100 | [diff] [blame] | 7597 | Returns an empty string on error. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 7598 | |
| 7599 | Can also be used as a |method|: > |
| 7600 | GetDirectories()->pathshorten() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 7601 | < |
| 7602 | Return type: |String| |
| 7603 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 7604 | |
| 7605 | perleval({expr}) *perleval()* |
| 7606 | Evaluate Perl expression {expr} in scalar context and return |
| 7607 | its result converted to Vim data structures. If value can't be |
| 7608 | converted, it is returned as a string Perl representation. |
| 7609 | Note: If you want an array or hash, {expr} must return a |
| 7610 | reference to it. |
| 7611 | Example: > |
| 7612 | :echo perleval('[1 .. 4]') |
| 7613 | < [1, 2, 3, 4] |
| 7614 | |
| 7615 | Note that in a `:def` function local variables are not visible |
| 7616 | to {expr}. |
| 7617 | |
| 7618 | Can also be used as a |method|: > |
| 7619 | GetExpr()->perleval() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 7620 | < |
| 7621 | Return type: any, depending on {expr} |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 7622 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 7623 | {only available when compiled with the |+perl| feature} |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 7624 | |
| 7625 | |
| 7626 | popup_ functions are documented here: |popup-functions| |
| 7627 | |
| 7628 | |
| 7629 | pow({x}, {y}) *pow()* |
| 7630 | Return the power of {x} to the exponent {y} as a |Float|. |
| 7631 | {x} and {y} must evaluate to a |Float| or a |Number|. |
Bram Moolenaar | 6ba83ba | 2022-06-12 22:15:57 +0100 | [diff] [blame] | 7632 | Returns 0.0 if {x} or {y} is not a |Float| or a |Number|. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 7633 | Examples: > |
| 7634 | :echo pow(3, 3) |
| 7635 | < 27.0 > |
| 7636 | :echo pow(2, 16) |
| 7637 | < 65536.0 > |
| 7638 | :echo pow(32, 0.20) |
| 7639 | < 2.0 |
| 7640 | |
| 7641 | Can also be used as a |method|: > |
| 7642 | Compute()->pow(3) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 7643 | < |
| 7644 | Return type: |Number| |
| 7645 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 7646 | |
| 7647 | prevnonblank({lnum}) *prevnonblank()* |
| 7648 | Return the line number of the first line at or above {lnum} |
| 7649 | that is not blank. Example: > |
| 7650 | let ind = indent(prevnonblank(v:lnum - 1)) |
| 7651 | < When {lnum} is invalid or there is no non-blank line at or |
| 7652 | above it, zero is returned. |
| 7653 | {lnum} is used like with |getline()|. |
| 7654 | Also see |nextnonblank()|. |
| 7655 | |
| 7656 | Can also be used as a |method|: > |
| 7657 | GetLnum()->prevnonblank() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 7658 | < |
| 7659 | Return type: |Number| |
| 7660 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 7661 | |
| 7662 | printf({fmt}, {expr1} ...) *printf()* |
| 7663 | Return a String with {fmt}, where "%" items are replaced by |
| 7664 | the formatted form of their respective arguments. Example: > |
| 7665 | printf("%4d: E%d %.30s", lnum, errno, msg) |
| 7666 | < May result in: |
| 7667 | " 99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~ |
| 7668 | |
| 7669 | When used as a |method| the base is passed as the second |
| 7670 | argument: > |
| 7671 | Compute()->printf("result: %d") |
Bram Moolenaar | cbaff5e | 2022-04-08 17:45:08 +0100 | [diff] [blame] | 7672 | < |
| 7673 | You can use `call()` to pass the items as a list. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 7674 | |
Bram Moolenaar | cbaff5e | 2022-04-08 17:45:08 +0100 | [diff] [blame] | 7675 | Often used items are: |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 7676 | %s string |
| 7677 | %6S string right-aligned in 6 display cells |
| 7678 | %6s string right-aligned in 6 bytes |
| 7679 | %.9s string truncated to 9 bytes |
| 7680 | %c single byte |
| 7681 | %d decimal number |
| 7682 | %5d decimal number padded with spaces to 5 characters |
| 7683 | %x hex number |
| 7684 | %04x hex number padded with zeros to at least 4 characters |
| 7685 | %X hex number using upper case letters |
| 7686 | %o octal number |
| 7687 | %08b binary number padded with zeros to at least 8 chars |
| 7688 | %f floating point number as 12.23, inf, -inf or nan |
| 7689 | %F floating point number as 12.23, INF, -INF or NAN |
| 7690 | %e floating point number as 1.23e3, inf, -inf or nan |
| 7691 | %E floating point number as 1.23E3, INF, -INF or NAN |
| 7692 | %g floating point number, as %f or %e depending on value |
| 7693 | %G floating point number, as %F or %E depending on value |
| 7694 | %% the % character itself |
| 7695 | |
| 7696 | Conversion specifications start with '%' and end with the |
| 7697 | conversion type. All other characters are copied unchanged to |
| 7698 | the result. |
| 7699 | |
| 7700 | The "%" starts a conversion specification. The following |
| 7701 | arguments appear in sequence: |
| 7702 | |
Christ van Willegen | 0c6181f | 2023-08-13 18:03:14 +0200 | [diff] [blame] | 7703 | % [pos-argument] [flags] [field-width] [.precision] type |
| 7704 | |
| 7705 | pos-argument |
| 7706 | At most one positional argument specifier. These |
| 7707 | take the form {n$}, where n is >= 1. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 7708 | |
| 7709 | flags |
| 7710 | Zero or more of the following flags: |
| 7711 | |
| 7712 | # The value should be converted to an "alternate |
| 7713 | form". For c, d, and s conversions, this option |
| 7714 | has no effect. For o conversions, the precision |
| 7715 | of the number is increased to force the first |
| 7716 | character of the output string to a zero (except |
| 7717 | if a zero value is printed with an explicit |
| 7718 | precision of zero). |
| 7719 | For b and B conversions, a non-zero result has |
| 7720 | the string "0b" (or "0B" for B conversions) |
| 7721 | prepended to it. |
| 7722 | For x and X conversions, a non-zero result has |
| 7723 | the string "0x" (or "0X" for X conversions) |
| 7724 | prepended to it. |
| 7725 | |
| 7726 | 0 (zero) Zero padding. For all conversions the converted |
| 7727 | value is padded on the left with zeros rather |
| 7728 | than blanks. If a precision is given with a |
| 7729 | numeric conversion (d, b, B, o, x, and X), the 0 |
| 7730 | flag is ignored. |
| 7731 | |
| 7732 | - A negative field width flag; the converted value |
| 7733 | is to be left adjusted on the field boundary. |
| 7734 | The converted value is padded on the right with |
| 7735 | blanks, rather than on the left with blanks or |
| 7736 | zeros. A - overrides a 0 if both are given. |
| 7737 | |
| 7738 | ' ' (space) A blank should be left before a positive |
| 7739 | number produced by a signed conversion (d). |
| 7740 | |
| 7741 | + A sign must always be placed before a number |
| 7742 | produced by a signed conversion. A + overrides |
| 7743 | a space if both are used. |
| 7744 | |
| 7745 | field-width |
| 7746 | An optional decimal digit string specifying a minimum |
| 7747 | field width. If the converted value has fewer bytes |
| 7748 | than the field width, it will be padded with spaces on |
| 7749 | the left (or right, if the left-adjustment flag has |
| 7750 | been given) to fill out the field width. For the S |
| 7751 | conversion the count is in cells. |
| 7752 | |
| 7753 | .precision |
| 7754 | An optional precision, in the form of a period '.' |
| 7755 | followed by an optional digit string. If the digit |
| 7756 | string is omitted, the precision is taken as zero. |
| 7757 | This gives the minimum number of digits to appear for |
| 7758 | d, o, x, and X conversions, the maximum number of |
| 7759 | bytes to be printed from a string for s conversions, |
| 7760 | or the maximum number of cells to be printed from a |
| 7761 | string for S conversions. |
| 7762 | For floating point it is the number of digits after |
| 7763 | the decimal point. |
| 7764 | |
| 7765 | type |
| 7766 | A character that specifies the type of conversion to |
| 7767 | be applied, see below. |
| 7768 | |
| 7769 | A field width or precision, or both, may be indicated by an |
| 7770 | asterisk '*' instead of a digit string. In this case, a |
| 7771 | Number argument supplies the field width or precision. A |
| 7772 | negative field width is treated as a left adjustment flag |
| 7773 | followed by a positive field width; a negative precision is |
| 7774 | treated as though it were missing. Example: > |
| 7775 | :echo printf("%d: %.*s", nr, width, line) |
| 7776 | < This limits the length of the text used from "line" to |
| 7777 | "width" bytes. |
| 7778 | |
Dominique Pellé | 17dca3c | 2023-12-14 20:36:32 +0100 | [diff] [blame] | 7779 | If the argument to be formatted is specified using a |
| 7780 | positional argument specifier, and a '*' is used to indicate |
| 7781 | that a number argument is to be used to specify the width or |
Christ van Willegen | 0c6181f | 2023-08-13 18:03:14 +0200 | [diff] [blame] | 7782 | precision, the argument(s) to be used must also be specified |
| 7783 | using a {n$} positional argument specifier. See |printf-$|. |
| 7784 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 7785 | The conversion specifiers and their meanings are: |
| 7786 | |
| 7787 | *printf-d* *printf-b* *printf-B* *printf-o* |
| 7788 | *printf-x* *printf-X* |
| 7789 | dbBoxX The Number argument is converted to signed decimal |
| 7790 | (d), unsigned binary (b and B), unsigned octal (o), or |
| 7791 | unsigned hexadecimal (x and X) notation. The letters |
| 7792 | "abcdef" are used for x conversions; the letters |
| 7793 | "ABCDEF" are used for X conversions. |
| 7794 | The precision, if any, gives the minimum number of |
| 7795 | digits that must appear; if the converted value |
| 7796 | requires fewer digits, it is padded on the left with |
| 7797 | zeros. |
| 7798 | In no case does a non-existent or small field width |
| 7799 | cause truncation of a numeric field; if the result of |
| 7800 | a conversion is wider than the field width, the field |
| 7801 | is expanded to contain the conversion result. |
| 7802 | The 'h' modifier indicates the argument is 16 bits. |
Christ van Willegen | aa90d4f | 2023-09-03 17:22:37 +0200 | [diff] [blame] | 7803 | The 'l' modifier indicates the argument is a long |
| 7804 | integer. The size will be 32 bits or 64 bits |
| 7805 | depending on your platform. |
| 7806 | The "ll" modifier indicates the argument is 64 bits. |
| 7807 | The b and B conversion specifiers never take a width |
| 7808 | modifier and always assume their argument is a 64 bit |
| 7809 | integer. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 7810 | Generally, these modifiers are not useful. They are |
| 7811 | ignored when type is known from the argument. |
| 7812 | |
| 7813 | i alias for d |
| 7814 | D alias for ld |
| 7815 | U alias for lu |
| 7816 | O alias for lo |
| 7817 | |
| 7818 | *printf-c* |
| 7819 | c The Number argument is converted to a byte, and the |
| 7820 | resulting character is written. |
| 7821 | |
| 7822 | *printf-s* |
| 7823 | s The text of the String argument is used. If a |
| 7824 | precision is specified, no more bytes than the number |
| 7825 | specified are used. |
| 7826 | If the argument is not a String type, it is |
| 7827 | automatically converted to text with the same format |
| 7828 | as ":echo". |
| 7829 | *printf-S* |
| 7830 | S The text of the String argument is used. If a |
| 7831 | precision is specified, no more display cells than the |
| 7832 | number specified are used. |
| 7833 | |
| 7834 | *printf-f* *E807* |
| 7835 | f F The Float argument is converted into a string of the |
| 7836 | form 123.456. The precision specifies the number of |
| 7837 | digits after the decimal point. When the precision is |
| 7838 | zero the decimal point is omitted. When the precision |
| 7839 | is not specified 6 is used. A really big number |
| 7840 | (out of range or dividing by zero) results in "inf" |
| 7841 | or "-inf" with %f (INF or -INF with %F). |
| 7842 | "0.0 / 0.0" results in "nan" with %f (NAN with %F). |
| 7843 | Example: > |
| 7844 | echo printf("%.2f", 12.115) |
| 7845 | < 12.12 |
| 7846 | Note that roundoff depends on the system libraries. |
| 7847 | Use |round()| when in doubt. |
| 7848 | |
| 7849 | *printf-e* *printf-E* |
| 7850 | e E The Float argument is converted into a string of the |
| 7851 | form 1.234e+03 or 1.234E+03 when using 'E'. The |
| 7852 | precision specifies the number of digits after the |
| 7853 | decimal point, like with 'f'. |
| 7854 | |
| 7855 | *printf-g* *printf-G* |
| 7856 | g G The Float argument is converted like with 'f' if the |
| 7857 | value is between 0.001 (inclusive) and 10000000.0 |
| 7858 | (exclusive). Otherwise 'e' is used for 'g' and 'E' |
| 7859 | for 'G'. When no precision is specified superfluous |
| 7860 | zeroes and '+' signs are removed, except for the zero |
| 7861 | immediately after the decimal point. Thus 10000000.0 |
| 7862 | results in 1.0e7. |
| 7863 | |
| 7864 | *printf-%* |
| 7865 | % A '%' is written. No argument is converted. The |
| 7866 | complete conversion specification is "%%". |
| 7867 | |
| 7868 | When a Number argument is expected a String argument is also |
| 7869 | accepted and automatically converted. |
| 7870 | When a Float or String argument is expected a Number argument |
| 7871 | is also accepted and automatically converted. |
| 7872 | Any other argument type results in an error message. |
| 7873 | |
| 7874 | *E766* *E767* |
| 7875 | The number of {exprN} arguments must exactly match the number |
| 7876 | of "%" items. If there are not sufficient or too many |
| 7877 | arguments an error is given. Up to 18 arguments can be used. |
| 7878 | |
Christ van Willegen | 0c6181f | 2023-08-13 18:03:14 +0200 | [diff] [blame] | 7879 | *printf-$* |
| 7880 | In certain languages, error and informative messages are |
| 7881 | more readable when the order of words is different from the |
Christian Brabandt | ee17b6f | 2023-09-09 11:23:50 +0200 | [diff] [blame] | 7882 | corresponding message in English. To accommodate translations |
Christ van Willegen | 0c6181f | 2023-08-13 18:03:14 +0200 | [diff] [blame] | 7883 | having a different word order, positional arguments may be |
| 7884 | used to indicate this. For instance: > |
| 7885 | |
h_east | 596a9f2 | 2023-11-21 21:24:23 +0900 | [diff] [blame] | 7886 | #, c-format |
| 7887 | msgid "%s returning %s" |
| 7888 | msgstr "waarde %2$s komt terug van %1$s" |
Christ van Willegen | 0c6181f | 2023-08-13 18:03:14 +0200 | [diff] [blame] | 7889 | < |
h_east | 596a9f2 | 2023-11-21 21:24:23 +0900 | [diff] [blame] | 7890 | In this example, the sentence has its 2 string arguments |
| 7891 | reversed in the output. > |
Christ van Willegen | 0c6181f | 2023-08-13 18:03:14 +0200 | [diff] [blame] | 7892 | |
h_east | 596a9f2 | 2023-11-21 21:24:23 +0900 | [diff] [blame] | 7893 | echo printf( |
| 7894 | "In The Netherlands, vim's creator's name is: %1$s %2$s", |
| 7895 | "Bram", "Moolenaar") |
| 7896 | < In The Netherlands, vim's creator's name is: Bram Moolenaar > |
Christ van Willegen | 0c6181f | 2023-08-13 18:03:14 +0200 | [diff] [blame] | 7897 | |
h_east | 596a9f2 | 2023-11-21 21:24:23 +0900 | [diff] [blame] | 7898 | echo printf( |
| 7899 | "In Belgium, vim's creator's name is: %2$s %1$s", |
| 7900 | "Bram", "Moolenaar") |
| 7901 | < In Belgium, vim's creator's name is: Moolenaar Bram |
Christ van Willegen | 0c6181f | 2023-08-13 18:03:14 +0200 | [diff] [blame] | 7902 | |
| 7903 | Width (and precision) can be specified using the '*' specifier. |
| 7904 | In this case, you must specify the field width position in the |
| 7905 | argument list. > |
| 7906 | |
h_east | 596a9f2 | 2023-11-21 21:24:23 +0900 | [diff] [blame] | 7907 | echo printf("%1$*2$.*3$d", 1, 2, 3) |
| 7908 | < 001 > |
| 7909 | echo printf("%2$*3$.*1$d", 1, 2, 3) |
| 7910 | < 2 > |
| 7911 | echo printf("%3$*1$.*2$d", 1, 2, 3) |
| 7912 | < 03 > |
| 7913 | echo printf("%1$*2$.*3$g", 1.4142, 2, 3) |
| 7914 | < 1.414 |
Christ van Willegen | 0c6181f | 2023-08-13 18:03:14 +0200 | [diff] [blame] | 7915 | |
| 7916 | You can mix specifying the width and/or precision directly |
| 7917 | and via positional arguments: > |
| 7918 | |
h_east | 596a9f2 | 2023-11-21 21:24:23 +0900 | [diff] [blame] | 7919 | echo printf("%1$4.*2$f", 1.4142135, 6) |
| 7920 | < 1.414214 > |
| 7921 | echo printf("%1$*2$.4f", 1.4142135, 6) |
| 7922 | < 1.4142 > |
| 7923 | echo printf("%1$*2$.*3$f", 1.4142135, 6, 2) |
| 7924 | < 1.41 |
Christ van Willegen | 0c6181f | 2023-08-13 18:03:14 +0200 | [diff] [blame] | 7925 | |
Christ van Willegen | c35fc03 | 2024-03-14 18:30:41 +0100 | [diff] [blame] | 7926 | You will get an overflow error |E1510|, when the field-width |
| 7927 | or precision will result in a string longer than 6400 chars. |
| 7928 | |
Yegappan Lakshmanan | 413f839 | 2023-09-28 22:46:37 +0200 | [diff] [blame] | 7929 | *E1500* |
Christ van Willegen | 0c6181f | 2023-08-13 18:03:14 +0200 | [diff] [blame] | 7930 | You cannot mix positional and non-positional arguments: > |
h_east | 596a9f2 | 2023-11-21 21:24:23 +0900 | [diff] [blame] | 7931 | echo printf("%s%1$s", "One", "Two") |
| 7932 | < E1500: Cannot mix positional and non-positional arguments: |
| 7933 | %s%1$s |
Christ van Willegen | 0c6181f | 2023-08-13 18:03:14 +0200 | [diff] [blame] | 7934 | |
Yegappan Lakshmanan | 413f839 | 2023-09-28 22:46:37 +0200 | [diff] [blame] | 7935 | *E1501* |
Christ van Willegen | 0c6181f | 2023-08-13 18:03:14 +0200 | [diff] [blame] | 7936 | You cannot skip a positional argument in a format string: > |
h_east | 596a9f2 | 2023-11-21 21:24:23 +0900 | [diff] [blame] | 7937 | echo printf("%3$s%1$s", "One", "Two", "Three") |
| 7938 | < E1501: format argument 2 unused in $-style format: |
| 7939 | %3$s%1$s |
Christ van Willegen | 0c6181f | 2023-08-13 18:03:14 +0200 | [diff] [blame] | 7940 | |
Yegappan Lakshmanan | 413f839 | 2023-09-28 22:46:37 +0200 | [diff] [blame] | 7941 | *E1502* |
Christ van Willegen | 0c6181f | 2023-08-13 18:03:14 +0200 | [diff] [blame] | 7942 | You can re-use a [field-width] (or [precision]) argument: > |
h_east | 596a9f2 | 2023-11-21 21:24:23 +0900 | [diff] [blame] | 7943 | echo printf("%1$d at width %2$d is: %01$*2$d", 1, 2) |
| 7944 | < 1 at width 2 is: 01 |
Christ van Willegen | 0c6181f | 2023-08-13 18:03:14 +0200 | [diff] [blame] | 7945 | |
| 7946 | However, you can't use it as a different type: > |
h_east | 596a9f2 | 2023-11-21 21:24:23 +0900 | [diff] [blame] | 7947 | echo printf("%1$d at width %2$ld is: %01$*2$d", 1, 2) |
| 7948 | < E1502: Positional argument 2 used as field width reused as |
| 7949 | different type: long int/int |
Christ van Willegen | 0c6181f | 2023-08-13 18:03:14 +0200 | [diff] [blame] | 7950 | |
Yegappan Lakshmanan | 413f839 | 2023-09-28 22:46:37 +0200 | [diff] [blame] | 7951 | *E1503* |
Christ van Willegen | 0c6181f | 2023-08-13 18:03:14 +0200 | [diff] [blame] | 7952 | When a positional argument is used, but not the correct number |
| 7953 | or arguments is given, an error is raised: > |
h_east | 596a9f2 | 2023-11-21 21:24:23 +0900 | [diff] [blame] | 7954 | echo printf("%1$d at width %2$d is: %01$*2$.*3$d", 1, 2) |
| 7955 | < E1503: Positional argument 3 out of bounds: %1$d at width |
| 7956 | %2$d is: %01$*2$.*3$d |
Christ van Willegen | 0c6181f | 2023-08-13 18:03:14 +0200 | [diff] [blame] | 7957 | |
| 7958 | Only the first error is reported: > |
h_east | 596a9f2 | 2023-11-21 21:24:23 +0900 | [diff] [blame] | 7959 | echo printf("%01$*2$.*3$d %4$d", 1, 2) |
| 7960 | < E1503: Positional argument 3 out of bounds: %01$*2$.*3$d |
| 7961 | %4$d |
Christ van Willegen | 0c6181f | 2023-08-13 18:03:14 +0200 | [diff] [blame] | 7962 | |
Yegappan Lakshmanan | 413f839 | 2023-09-28 22:46:37 +0200 | [diff] [blame] | 7963 | *E1504* |
Christ van Willegen | 0c6181f | 2023-08-13 18:03:14 +0200 | [diff] [blame] | 7964 | A positional argument can be used more than once: > |
h_east | 596a9f2 | 2023-11-21 21:24:23 +0900 | [diff] [blame] | 7965 | echo printf("%1$s %2$s %1$s", "One", "Two") |
| 7966 | < One Two One |
Christ van Willegen | 0c6181f | 2023-08-13 18:03:14 +0200 | [diff] [blame] | 7967 | |
| 7968 | However, you can't use a different type the second time: > |
h_east | 596a9f2 | 2023-11-21 21:24:23 +0900 | [diff] [blame] | 7969 | echo printf("%1$s %2$s %1$d", "One", "Two") |
| 7970 | < E1504: Positional argument 1 type used inconsistently: |
| 7971 | int/string |
Christ van Willegen | 0c6181f | 2023-08-13 18:03:14 +0200 | [diff] [blame] | 7972 | |
Yegappan Lakshmanan | 413f839 | 2023-09-28 22:46:37 +0200 | [diff] [blame] | 7973 | *E1505* |
Christ van Willegen | 0c6181f | 2023-08-13 18:03:14 +0200 | [diff] [blame] | 7974 | Various other errors that lead to a format string being |
| 7975 | wrongly formatted lead to: > |
h_east | 596a9f2 | 2023-11-21 21:24:23 +0900 | [diff] [blame] | 7976 | echo printf("%1$d at width %2$d is: %01$*2$.3$d", 1, 2) |
| 7977 | < E1505: Invalid format specifier: %1$d at width %2$d is: |
| 7978 | %01$*2$.3$d |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 7979 | |
Christ van Willegen | ea746f9 | 2023-10-05 20:48:36 +0200 | [diff] [blame] | 7980 | *E1507* |
zeertzjq | 27e12c7 | 2023-10-07 01:34:04 +0800 | [diff] [blame] | 7981 | This internal error indicates that the logic to parse a |
| 7982 | positional format argument ran into a problem that couldn't be |
| 7983 | otherwise reported. Please file a bug against Vim if you run |
| 7984 | into this, copying the exact format string and parameters that |
| 7985 | were used. |
Christ van Willegen | ea746f9 | 2023-10-05 20:48:36 +0200 | [diff] [blame] | 7986 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 7987 | Return type: |String| |
| 7988 | |
Christ van Willegen | ea746f9 | 2023-10-05 20:48:36 +0200 | [diff] [blame] | 7989 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 7990 | prompt_getprompt({buf}) *prompt_getprompt()* |
| 7991 | Returns the effective prompt text for buffer {buf}. {buf} can |
| 7992 | be a buffer name or number. See |prompt-buffer|. |
| 7993 | |
| 7994 | If the buffer doesn't exist or isn't a prompt buffer, an empty |
| 7995 | string is returned. |
| 7996 | |
| 7997 | Can also be used as a |method|: > |
| 7998 | GetBuffer()->prompt_getprompt() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 7999 | < |
| 8000 | Return type: |String| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8001 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8002 | {only available when compiled with the |+channel| feature} |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8003 | |
| 8004 | |
| 8005 | prompt_setcallback({buf}, {expr}) *prompt_setcallback()* |
| 8006 | Set prompt callback for buffer {buf} to {expr}. When {expr} |
| 8007 | is an empty string the callback is removed. This has only |
| 8008 | effect if {buf} has 'buftype' set to "prompt". |
| 8009 | |
| 8010 | The callback is invoked when pressing Enter. The current |
| 8011 | buffer will always be the prompt buffer. A new line for a |
| 8012 | prompt is added before invoking the callback, thus the prompt |
| 8013 | for which the callback was invoked will be in the last but one |
| 8014 | line. |
| 8015 | If the callback wants to add text to the buffer, it must |
| 8016 | insert it above the last line, since that is where the current |
| 8017 | prompt is. This can also be done asynchronously. |
| 8018 | The callback is invoked with one argument, which is the text |
| 8019 | that was entered at the prompt. This can be an empty string |
| 8020 | if the user only typed Enter. |
| 8021 | Example: > |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8022 | func s:TextEntered(text) |
| 8023 | if a:text == 'exit' || a:text == 'quit' |
| 8024 | stopinsert |
Bram Moolenaar | b7398fe | 2023-05-14 18:50:25 +0100 | [diff] [blame] | 8025 | " Reset 'modified' to allow the buffer to be closed. |
| 8026 | " We assume there is nothing useful to be saved. |
| 8027 | set nomodified |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8028 | close |
| 8029 | else |
Bram Moolenaar | b7398fe | 2023-05-14 18:50:25 +0100 | [diff] [blame] | 8030 | " Do something useful with "a:text". In this example |
| 8031 | " we just repeat it. |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 8032 | call append(line('$') - 1, 'Entered: "' .. a:text .. '"') |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8033 | endif |
| 8034 | endfunc |
Bram Moolenaar | b7398fe | 2023-05-14 18:50:25 +0100 | [diff] [blame] | 8035 | call prompt_setcallback(bufnr(), function('s:TextEntered')) |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8036 | |
| 8037 | < Can also be used as a |method|: > |
| 8038 | GetBuffer()->prompt_setcallback(callback) |
| 8039 | |
| 8040 | < {only available when compiled with the |+channel| feature} |
| 8041 | |
| 8042 | prompt_setinterrupt({buf}, {expr}) *prompt_setinterrupt()* |
| 8043 | Set a callback for buffer {buf} to {expr}. When {expr} is an |
| 8044 | empty string the callback is removed. This has only effect if |
| 8045 | {buf} has 'buftype' set to "prompt". |
| 8046 | |
| 8047 | This callback will be invoked when pressing CTRL-C in Insert |
| 8048 | mode. Without setting a callback Vim will exit Insert mode, |
| 8049 | as in any buffer. |
| 8050 | |
| 8051 | Can also be used as a |method|: > |
| 8052 | GetBuffer()->prompt_setinterrupt(callback) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8053 | < |
| 8054 | Return type: |Number| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8055 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8056 | {only available when compiled with the |+channel| feature} |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8057 | |
| 8058 | prompt_setprompt({buf}, {text}) *prompt_setprompt()* |
| 8059 | Set prompt for buffer {buf} to {text}. You most likely want |
| 8060 | {text} to end in a space. |
| 8061 | The result is only visible if {buf} has 'buftype' set to |
| 8062 | "prompt". Example: > |
| 8063 | call prompt_setprompt(bufnr(), 'command: ') |
| 8064 | < |
| 8065 | Can also be used as a |method|: > |
| 8066 | GetBuffer()->prompt_setprompt('command: ') |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8067 | < |
| 8068 | Return type: |Number| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8069 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8070 | {only available when compiled with the |+channel| feature} |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8071 | |
| 8072 | prop_ functions are documented here: |text-prop-functions| |
| 8073 | |
| 8074 | pum_getpos() *pum_getpos()* |
| 8075 | If the popup menu (see |ins-completion-menu|) is not visible, |
| 8076 | returns an empty |Dictionary|, otherwise, returns a |
| 8077 | |Dictionary| with the following keys: |
| 8078 | height nr of items visible |
| 8079 | width screen cells |
| 8080 | row top screen row (0 first row) |
| 8081 | col leftmost screen column (0 first col) |
| 8082 | size total nr of items |
| 8083 | scrollbar |TRUE| if scrollbar is visible |
| 8084 | |
| 8085 | The values are the same as in |v:event| during |
| 8086 | |CompleteChanged|. |
| 8087 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8088 | Return type: dict<any> |
| 8089 | |
| 8090 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8091 | pumvisible() *pumvisible()* |
| 8092 | Returns non-zero when the popup menu is visible, zero |
| 8093 | otherwise. See |ins-completion-menu|. |
| 8094 | This can be used to avoid some things that would remove the |
| 8095 | popup menu. |
| 8096 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8097 | Return type: |Number| |
| 8098 | |
| 8099 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8100 | py3eval({expr}) *py3eval()* |
| 8101 | Evaluate Python expression {expr} and return its result |
| 8102 | converted to Vim data structures. |
| 8103 | Numbers and strings are returned as they are (strings are |
| 8104 | copied though, Unicode strings are additionally converted to |
| 8105 | 'encoding'). |
| 8106 | Lists are represented as Vim |List| type. |
| 8107 | Dictionaries are represented as Vim |Dictionary| type with |
| 8108 | keys converted to strings. |
| 8109 | Note that in a `:def` function local variables are not visible |
| 8110 | to {expr}. |
| 8111 | |
| 8112 | Can also be used as a |method|: > |
| 8113 | GetExpr()->py3eval() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8114 | < |
| 8115 | Return type: any, depending on {expr} |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8116 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8117 | {only available when compiled with the |+python3| feature} |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8118 | |
| 8119 | *E858* *E859* |
| 8120 | pyeval({expr}) *pyeval()* |
| 8121 | Evaluate Python expression {expr} and return its result |
| 8122 | converted to Vim data structures. |
| 8123 | Numbers and strings are returned as they are (strings are |
| 8124 | copied though). |
| 8125 | Lists are represented as Vim |List| type. |
| 8126 | Dictionaries are represented as Vim |Dictionary| type, |
| 8127 | non-string keys result in error. |
| 8128 | Note that in a `:def` function local variables are not visible |
| 8129 | to {expr}. |
| 8130 | |
| 8131 | Can also be used as a |method|: > |
| 8132 | GetExpr()->pyeval() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8133 | < |
| 8134 | Return type: any, depending on {expr} |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8135 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8136 | {only available when compiled with the |+python| feature} |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8137 | |
| 8138 | pyxeval({expr}) *pyxeval()* |
| 8139 | Evaluate Python expression {expr} and return its result |
| 8140 | converted to Vim data structures. |
| 8141 | Uses Python 2 or 3, see |python_x| and 'pyxversion'. |
| 8142 | See also: |pyeval()|, |py3eval()| |
| 8143 | |
| 8144 | Can also be used as a |method|: > |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8145 | < GetExpr()->pyxeval() |
| 8146 | < |
| 8147 | Return type: any, depending on {expr} |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8148 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8149 | {only available when compiled with the |+python| or the |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8150 | |+python3| feature} |
| 8151 | |
| 8152 | rand([{expr}]) *rand()* *random* |
| 8153 | Return a pseudo-random Number generated with an xoshiro128** |
| 8154 | algorithm using seed {expr}. The returned number is 32 bits, |
| 8155 | also on 64 bits systems, for consistency. |
| 8156 | {expr} can be initialized by |srand()| and will be updated by |
| 8157 | rand(). If {expr} is omitted, an internal seed value is used |
| 8158 | and updated. |
Bram Moolenaar | 6ba83ba | 2022-06-12 22:15:57 +0100 | [diff] [blame] | 8159 | Returns -1 if {expr} is invalid. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8160 | |
| 8161 | Examples: > |
| 8162 | :echo rand() |
| 8163 | :let seed = srand() |
| 8164 | :echo rand(seed) |
| 8165 | :echo rand(seed) % 16 " random number 0 - 15 |
| 8166 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8167 | Return type: |Number| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8168 | |
| 8169 | *E726* *E727* |
| 8170 | range({expr} [, {max} [, {stride}]]) *range()* |
| 8171 | Returns a |List| with Numbers: |
| 8172 | - If only {expr} is specified: [0, 1, ..., {expr} - 1] |
| 8173 | - If {max} is specified: [{expr}, {expr} + 1, ..., {max}] |
| 8174 | - If {stride} is specified: [{expr}, {expr} + {stride}, ..., |
| 8175 | {max}] (increasing {expr} with {stride} each time, not |
| 8176 | producing a value past {max}). |
| 8177 | When the maximum is one before the start the result is an |
| 8178 | empty list. When the maximum is more than one before the |
| 8179 | start this is an error. |
| 8180 | Examples: > |
| 8181 | range(4) " [0, 1, 2, 3] |
| 8182 | range(2, 4) " [2, 3, 4] |
| 8183 | range(2, 9, 3) " [2, 5, 8] |
| 8184 | range(2, -2, -1) " [2, 1, 0, -1, -2] |
| 8185 | range(0) " [] |
| 8186 | range(2, 0) " error! |
| 8187 | < |
| 8188 | Can also be used as a |method|: > |
| 8189 | GetExpr()->range() |
| 8190 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8191 | Return type: list<number> |
| 8192 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8193 | |
K.Takata | 11df3ae | 2022-10-19 14:02:40 +0100 | [diff] [blame] | 8194 | readblob({fname} [, {offset} [, {size}]]) *readblob()* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8195 | Read file {fname} in binary mode and return a |Blob|. |
K.Takata | 11df3ae | 2022-10-19 14:02:40 +0100 | [diff] [blame] | 8196 | If {offset} is specified, read the file from the specified |
| 8197 | offset. If it is a negative value, it is used as an offset |
| 8198 | from the end of the file. E.g., to read the last 12 bytes: > |
| 8199 | readblob('file.bin', -12) |
| 8200 | < If {size} is specified, only the specified size will be read. |
| 8201 | E.g. to read the first 100 bytes of a file: > |
| 8202 | readblob('file.bin', 0, 100) |
| 8203 | < If {size} is -1 or omitted, the whole data starting from |
| 8204 | {offset} will be read. |
K.Takata | 4362576 | 2022-10-20 13:28:51 +0100 | [diff] [blame] | 8205 | This can be also used to read the data from a character device |
| 8206 | on Unix when {size} is explicitly set. Only if the device |
| 8207 | supports seeking {offset} can be used. Otherwise it should be |
| 8208 | zero. E.g. to read 10 bytes from a serial console: > |
| 8209 | readblob('/dev/ttyS0', 0, 10) |
| 8210 | < When the file can't be opened an error message is given and |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8211 | the result is an empty |Blob|. |
Bram Moolenaar | 5b2a3d7 | 2022-10-21 11:25:30 +0100 | [diff] [blame] | 8212 | When the offset is beyond the end of the file the result is an |
| 8213 | empty blob. |
| 8214 | When trying to read more bytes than are available the result |
| 8215 | is truncated. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8216 | Also see |readfile()| and |writefile()|. |
| 8217 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8218 | Return type: |Blob| |
| 8219 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8220 | |
| 8221 | readdir({directory} [, {expr} [, {dict}]]) *readdir()* |
| 8222 | Return a list with file and directory names in {directory}. |
| 8223 | You can also use |glob()| if you don't need to do complicated |
| 8224 | things, such as limiting the number of matches. |
| 8225 | The list will be sorted (case sensitive), see the {dict} |
| 8226 | argument below for changing the sort order. |
| 8227 | |
| 8228 | When {expr} is omitted all entries are included. |
| 8229 | When {expr} is given, it is evaluated to check what to do: |
| 8230 | If {expr} results in -1 then no further entries will |
| 8231 | be handled. |
| 8232 | If {expr} results in 0 then this entry will not be |
| 8233 | added to the list. |
| 8234 | If {expr} results in 1 then this entry will be added |
| 8235 | to the list. |
| 8236 | The entries "." and ".." are always excluded. |
| 8237 | Each time {expr} is evaluated |v:val| is set to the entry name. |
| 8238 | When {expr} is a function the name is passed as the argument. |
| 8239 | For example, to get a list of files ending in ".txt": > |
| 8240 | readdir(dirname, {n -> n =~ '.txt$'}) |
| 8241 | < To skip hidden and backup files: > |
| 8242 | readdir(dirname, {n -> n !~ '^\.\|\~$'}) |
Bram Moolenaar | 6f4754b | 2022-01-23 12:07:04 +0000 | [diff] [blame] | 8243 | < *E857* |
| 8244 | The optional {dict} argument allows for further custom |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8245 | values. Currently this is used to specify if and how sorting |
| 8246 | should be performed. The dict can have the following members: |
| 8247 | |
| 8248 | sort How to sort the result returned from the system. |
| 8249 | Valid values are: |
| 8250 | "none" do not sort (fastest method) |
| 8251 | "case" sort case sensitive (byte value of |
| 8252 | each character, technically, using |
| 8253 | strcmp()) (default) |
| 8254 | "icase" sort case insensitive (technically |
| 8255 | using strcasecmp()) |
| 8256 | "collate" sort using the collation order |
| 8257 | of the "POSIX" or "C" |locale| |
| 8258 | (technically using strcoll()) |
| 8259 | Other values are silently ignored. |
| 8260 | |
| 8261 | For example, to get a list of all files in the current |
| 8262 | directory without sorting the individual entries: > |
| 8263 | readdir('.', '1', #{sort: 'none'}) |
| 8264 | < If you want to get a directory tree: > |
| 8265 | function! s:tree(dir) |
| 8266 | return {a:dir : map(readdir(a:dir), |
| 8267 | \ {_, x -> isdirectory(x) ? |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 8268 | \ {x : s:tree(a:dir .. '/' .. x)} : x})} |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8269 | endfunction |
| 8270 | echo s:tree(".") |
| 8271 | < |
Bram Moolenaar | 6ba83ba | 2022-06-12 22:15:57 +0100 | [diff] [blame] | 8272 | Returns an empty List on error. |
| 8273 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8274 | Can also be used as a |method|: > |
| 8275 | GetDirName()->readdir() |
| 8276 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8277 | Return type: list<string> or list<any> |
| 8278 | |
| 8279 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8280 | readdirex({directory} [, {expr} [, {dict}]]) *readdirex()* |
| 8281 | Extended version of |readdir()|. |
| 8282 | Return a list of Dictionaries with file and directory |
| 8283 | information in {directory}. |
| 8284 | This is useful if you want to get the attributes of file and |
| 8285 | directory at the same time as getting a list of a directory. |
| 8286 | This is much faster than calling |readdir()| then calling |
| 8287 | |getfperm()|, |getfsize()|, |getftime()| and |getftype()| for |
| 8288 | each file and directory especially on MS-Windows. |
| 8289 | The list will by default be sorted by name (case sensitive), |
| 8290 | the sorting can be changed by using the optional {dict} |
| 8291 | argument, see |readdir()|. |
| 8292 | |
| 8293 | The Dictionary for file and directory information has the |
| 8294 | following items: |
| 8295 | group Group name of the entry. (Only on Unix) |
| 8296 | name Name of the entry. |
| 8297 | perm Permissions of the entry. See |getfperm()|. |
| 8298 | size Size of the entry. See |getfsize()|. |
| 8299 | time Timestamp of the entry. See |getftime()|. |
| 8300 | type Type of the entry. |
| 8301 | On Unix, almost same as |getftype()| except: |
| 8302 | Symlink to a dir "linkd" |
| 8303 | Other symlink "link" |
| 8304 | On MS-Windows: |
| 8305 | Normal file "file" |
| 8306 | Directory "dir" |
| 8307 | Junction "junction" |
| 8308 | Symlink to a dir "linkd" |
| 8309 | Other symlink "link" |
| 8310 | Other reparse point "reparse" |
| 8311 | user User name of the entry's owner. (Only on Unix) |
| 8312 | On Unix, if the entry is a symlink, the Dictionary includes |
| 8313 | the information of the target (except the "type" item). |
| 8314 | On MS-Windows, it includes the information of the symlink |
| 8315 | itself because of performance reasons. |
| 8316 | |
| 8317 | When {expr} is omitted all entries are included. |
| 8318 | When {expr} is given, it is evaluated to check what to do: |
| 8319 | If {expr} results in -1 then no further entries will |
| 8320 | be handled. |
| 8321 | If {expr} results in 0 then this entry will not be |
| 8322 | added to the list. |
| 8323 | If {expr} results in 1 then this entry will be added |
| 8324 | to the list. |
| 8325 | The entries "." and ".." are always excluded. |
| 8326 | Each time {expr} is evaluated |v:val| is set to a |Dictionary| |
| 8327 | of the entry. |
| 8328 | When {expr} is a function the entry is passed as the argument. |
| 8329 | For example, to get a list of files ending in ".txt": > |
| 8330 | readdirex(dirname, {e -> e.name =~ '.txt$'}) |
| 8331 | < |
| 8332 | For example, to get a list of all files in the current |
| 8333 | directory without sorting the individual entries: > |
| 8334 | readdirex(dirname, '1', #{sort: 'none'}) |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8335 | < |
| 8336 | Can also be used as a |method|: > |
| 8337 | GetDirName()->readdirex() |
| 8338 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8339 | Return type: list<dict<any>> or list<any> |
| 8340 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8341 | |
| 8342 | *readfile()* |
| 8343 | readfile({fname} [, {type} [, {max}]]) |
| 8344 | Read file {fname} and return a |List|, each line of the file |
| 8345 | as an item. Lines are broken at NL characters. Macintosh |
| 8346 | files separated with CR will result in a single long line |
| 8347 | (unless a NL appears somewhere). |
| 8348 | All NUL characters are replaced with a NL character. |
| 8349 | When {type} contains "b" binary mode is used: |
| 8350 | - When the last line ends in a NL an extra empty list item is |
| 8351 | added. |
| 8352 | - No CR characters are removed. |
| 8353 | Otherwise: |
| 8354 | - CR characters that appear before a NL are removed. |
| 8355 | - Whether the last line ends in a NL or not does not matter. |
| 8356 | - When 'encoding' is Unicode any UTF-8 byte order mark is |
| 8357 | removed from the text. |
| 8358 | When {max} is given this specifies the maximum number of lines |
| 8359 | to be read. Useful if you only want to check the first ten |
| 8360 | lines of a file: > |
| 8361 | :for line in readfile(fname, '', 10) |
| 8362 | : if line =~ 'Date' | echo line | endif |
| 8363 | :endfor |
| 8364 | < When {max} is negative -{max} lines from the end of the file |
| 8365 | are returned, or as many as there are. |
| 8366 | When {max} is zero the result is an empty list. |
| 8367 | Note that without {max} the whole file is read into memory. |
| 8368 | Also note that there is no recognition of encoding. Read a |
| 8369 | file into a buffer if you need to. |
| 8370 | Deprecated (use |readblob()| instead): When {type} contains |
| 8371 | "B" a |Blob| is returned with the binary data of the file |
| 8372 | unmodified. |
| 8373 | When the file can't be opened an error message is given and |
| 8374 | the result is an empty list. |
| 8375 | Also see |writefile()|. |
| 8376 | |
| 8377 | Can also be used as a |method|: > |
| 8378 | GetFileName()->readfile() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8379 | < |
| 8380 | Return type: list<string> or list<any> |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8381 | |
| 8382 | reduce({object}, {func} [, {initial}]) *reduce()* *E998* |
| 8383 | {func} is called for every item in {object}, which can be a |
| 8384 | |String|, |List| or a |Blob|. {func} is called with two |
| 8385 | arguments: the result so far and current item. After |
Bram Moolenaar | f10911e | 2022-01-29 22:20:48 +0000 | [diff] [blame] | 8386 | processing all items the result is returned. *E1132* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8387 | |
| 8388 | {initial} is the initial result. When omitted, the first item |
| 8389 | in {object} is used and {func} is first called for the second |
| 8390 | item. If {initial} is not given and {object} is empty no |
| 8391 | result can be computed, an E998 error is given. |
| 8392 | |
| 8393 | Examples: > |
| 8394 | echo reduce([1, 3, 5], { acc, val -> acc + val }) |
| 8395 | echo reduce(['x', 'y'], { acc, val -> acc .. val }, 'a') |
| 8396 | echo reduce(0z1122, { acc, val -> 2 * acc + val }) |
| 8397 | echo reduce('xyz', { acc, val -> acc .. ',' .. val }) |
| 8398 | < |
| 8399 | Can also be used as a |method|: > |
| 8400 | echo mylist->reduce({ acc, val -> acc + val }, 0) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8401 | < |
| 8402 | Return type: |String|, |Blob|, list<{type}> or dict<{type}> |
| 8403 | depending on {object} and {func} |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8404 | |
| 8405 | |
| 8406 | reg_executing() *reg_executing()* |
| 8407 | Returns the single letter name of the register being executed. |
| 8408 | Returns an empty string when no register is being executed. |
| 8409 | See |@|. |
| 8410 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8411 | Return type: |String| |
| 8412 | |
| 8413 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8414 | reg_recording() *reg_recording()* |
| 8415 | Returns the single letter name of the register being recorded. |
| 8416 | Returns an empty string when not recording. See |q|. |
| 8417 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8418 | Return type: |String| |
| 8419 | |
| 8420 | |
| 8421 | reltime() *reltime()* |
Bram Moolenaar | f269eab | 2022-10-03 18:04:35 +0100 | [diff] [blame] | 8422 | reltime({start}) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8423 | reltime({start}, {end}) |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8424 | Return an item that represents a time value. The item is a |
| 8425 | list with items that depend on the system. In Vim 9 script |
Bram Moolenaar | 71badf9 | 2023-04-22 22:40:14 +0100 | [diff] [blame] | 8426 | the type list<any> can be used. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8427 | The item can be passed to |reltimestr()| to convert it to a |
Bram Moolenaar | f269eab | 2022-10-03 18:04:35 +0100 | [diff] [blame] | 8428 | string or |reltimefloat()| to convert to a Float. For |
| 8429 | example, to see the time spent in function Work(): > |
| 8430 | var startTime = reltime() |
| 8431 | Work() |
| 8432 | echo startTime->reltime()->reltimestr() |
| 8433 | < |
Bram Moolenaar | 016188f | 2022-06-06 20:52:59 +0100 | [diff] [blame] | 8434 | Without an argument reltime() returns the current time (the |
Lifepillar | 963fd7d | 2024-01-05 17:44:57 +0100 | [diff] [blame] | 8435 | representation is system-dependent, it cannot be used as the |
Bram Moolenaar | 016188f | 2022-06-06 20:52:59 +0100 | [diff] [blame] | 8436 | wall-clock time, see |localtime()| for that). |
Lifepillar | 963fd7d | 2024-01-05 17:44:57 +0100 | [diff] [blame] | 8437 | With one argument it returns the time passed since the time |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8438 | specified in the argument. |
| 8439 | With two arguments it returns the time passed between {start} |
| 8440 | and {end}. |
| 8441 | |
| 8442 | The {start} and {end} arguments must be values returned by |
Bram Moolenaar | 6ba83ba | 2022-06-12 22:15:57 +0100 | [diff] [blame] | 8443 | reltime(). If there is an error an empty List is returned in |
| 8444 | legacy script, in Vim9 script an error is given. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8445 | |
| 8446 | Can also be used as a |method|: > |
| 8447 | GetStart()->reltime() |
| 8448 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8449 | Return type: list<number> |
| 8450 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8451 | {only available when compiled with the |+reltime| feature} |
| 8452 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8453 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8454 | reltimefloat({time}) *reltimefloat()* |
| 8455 | Return a Float that represents the time value of {time}. |
| 8456 | Example: > |
| 8457 | let start = reltime() |
| 8458 | call MyFunction() |
| 8459 | let seconds = reltimefloat(reltime(start)) |
| 8460 | < See the note of reltimestr() about overhead. |
| 8461 | Also see |profiling|. |
| 8462 | If there is an error 0.0 is returned in legacy script, in Vim9 |
| 8463 | script an error is given. |
| 8464 | |
| 8465 | Can also be used as a |method|: > |
| 8466 | reltime(start)->reltimefloat() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8467 | < |
| 8468 | Return type: |Float| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8469 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8470 | {only available when compiled with the |+reltime| feature} |
| 8471 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8472 | |
| 8473 | reltimestr({time}) *reltimestr()* |
| 8474 | Return a String that represents the time value of {time}. |
| 8475 | This is the number of seconds, a dot and the number of |
| 8476 | microseconds. Example: > |
| 8477 | let start = reltime() |
| 8478 | call MyFunction() |
| 8479 | echo reltimestr(reltime(start)) |
| 8480 | < Note that overhead for the commands will be added to the time. |
Ernie Rael | 076de79 | 2023-03-16 21:43:15 +0000 | [diff] [blame] | 8481 | The accuracy depends on the system. Use reltimefloat() for the |
| 8482 | greatest accuracy which is nanoseconds on some systems. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8483 | Leading spaces are used to make the string align nicely. You |
| 8484 | can use split() to remove it. > |
| 8485 | echo split(reltimestr(reltime(start)))[0] |
| 8486 | < Also see |profiling|. |
| 8487 | If there is an error an empty string is returned in legacy |
| 8488 | script, in Vim9 script an error is given. |
| 8489 | |
| 8490 | Can also be used as a |method|: > |
| 8491 | reltime(start)->reltimestr() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8492 | < |
| 8493 | Return type: |String| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8494 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8495 | {only available when compiled with the |+reltime| feature} |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8496 | |
| 8497 | *remote_expr()* *E449* |
| 8498 | remote_expr({server}, {string} [, {idvar} [, {timeout}]]) |
Bram Moolenaar | 944697a | 2022-02-20 19:48:20 +0000 | [diff] [blame] | 8499 | Send the {string} to {server}. The {server} argument is a |
| 8500 | string, also see |{server}|. |
| 8501 | |
| 8502 | The string is sent as an expression and the result is returned |
| 8503 | after evaluation. The result must be a String or a |List|. A |
| 8504 | |List| is turned into a String by joining the items with a |
| 8505 | line break in between (not at the end), like with join(expr, |
| 8506 | "\n"). |
| 8507 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8508 | If {idvar} is present and not empty, it is taken as the name |
| 8509 | of a variable and a {serverid} for later use with |
| 8510 | |remote_read()| is stored there. |
Bram Moolenaar | 944697a | 2022-02-20 19:48:20 +0000 | [diff] [blame] | 8511 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8512 | If {timeout} is given the read times out after this many |
| 8513 | seconds. Otherwise a timeout of 600 seconds is used. |
Bram Moolenaar | 944697a | 2022-02-20 19:48:20 +0000 | [diff] [blame] | 8514 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8515 | See also |clientserver| |RemoteReply|. |
| 8516 | This function is not available in the |sandbox|. |
| 8517 | {only available when compiled with the |+clientserver| feature} |
| 8518 | Note: Any errors will cause a local error message to be issued |
| 8519 | and the result will be the empty string. |
| 8520 | |
| 8521 | Variables will be evaluated in the global namespace, |
| 8522 | independent of a function currently being active. Except |
| 8523 | when in debug mode, then local function variables and |
| 8524 | arguments can be evaluated. |
| 8525 | |
| 8526 | Examples: > |
| 8527 | :echo remote_expr("gvim", "2+2") |
| 8528 | :echo remote_expr("gvim1", "b:current_syntax") |
| 8529 | < |
| 8530 | Can also be used as a |method|: > |
| 8531 | ServerName()->remote_expr(expr) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8532 | < |
| 8533 | Return type: |String| or list<{type}> |
| 8534 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8535 | |
| 8536 | remote_foreground({server}) *remote_foreground()* |
| 8537 | Move the Vim server with the name {server} to the foreground. |
Bram Moolenaar | 944697a | 2022-02-20 19:48:20 +0000 | [diff] [blame] | 8538 | The {server} argument is a string, also see |{server}|. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8539 | This works like: > |
| 8540 | remote_expr({server}, "foreground()") |
| 8541 | < Except that on Win32 systems the client does the work, to work |
| 8542 | around the problem that the OS doesn't always allow the server |
| 8543 | to bring itself to the foreground. |
| 8544 | Note: This does not restore the window if it was minimized, |
| 8545 | like foreground() does. |
| 8546 | This function is not available in the |sandbox|. |
| 8547 | |
| 8548 | Can also be used as a |method|: > |
| 8549 | ServerName()->remote_foreground() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8550 | < |
| 8551 | Return type: |Number| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8552 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8553 | {only in the Win32, Motif and GTK GUI versions and the |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8554 | Win32 console version} |
| 8555 | |
| 8556 | |
| 8557 | remote_peek({serverid} [, {retvar}]) *remote_peek()* |
| 8558 | Returns a positive number if there are available strings |
| 8559 | from {serverid}. Copies any reply string into the variable |
| 8560 | {retvar} if specified. {retvar} must be a string with the |
| 8561 | name of a variable. |
| 8562 | Returns zero if none are available. |
| 8563 | Returns -1 if something is wrong. |
| 8564 | See also |clientserver|. |
| 8565 | This function is not available in the |sandbox|. |
| 8566 | {only available when compiled with the |+clientserver| feature} |
| 8567 | Examples: > |
Bram Moolenaar | f269eab | 2022-10-03 18:04:35 +0100 | [diff] [blame] | 8568 | :let repl = "" |
| 8569 | :echo "PEEK: " .. remote_peek(id, "repl") .. ": " .. repl |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8570 | |
| 8571 | < Can also be used as a |method|: > |
| 8572 | ServerId()->remote_peek() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8573 | < |
| 8574 | Return type: |Number| |
| 8575 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8576 | |
| 8577 | remote_read({serverid}, [{timeout}]) *remote_read()* |
| 8578 | Return the oldest available reply from {serverid} and consume |
| 8579 | it. Unless a {timeout} in seconds is given, it blocks until a |
Bram Moolenaar | 6ba83ba | 2022-06-12 22:15:57 +0100 | [diff] [blame] | 8580 | reply is available. Returns an empty string, if a reply is |
| 8581 | not available or on error. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8582 | See also |clientserver|. |
| 8583 | This function is not available in the |sandbox|. |
| 8584 | {only available when compiled with the |+clientserver| feature} |
| 8585 | Example: > |
| 8586 | :echo remote_read(id) |
| 8587 | |
| 8588 | < Can also be used as a |method|: > |
| 8589 | ServerId()->remote_read() |
| 8590 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8591 | Return type: |String| |
| 8592 | |
| 8593 | |
| 8594 | remote_send({server}, {string} [, {idvar}]) *remote_send()* *E241* |
Bram Moolenaar | 944697a | 2022-02-20 19:48:20 +0000 | [diff] [blame] | 8595 | Send the {string} to {server}. The {server} argument is a |
| 8596 | string, also see |{server}|. |
| 8597 | |
| 8598 | The string is sent as input keys and the function returns |
| 8599 | immediately. At the Vim server the keys are not mapped |
| 8600 | |:map|. |
| 8601 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8602 | If {idvar} is present, it is taken as the name of a variable |
| 8603 | and a {serverid} for later use with remote_read() is stored |
| 8604 | there. |
Bram Moolenaar | 944697a | 2022-02-20 19:48:20 +0000 | [diff] [blame] | 8605 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8606 | See also |clientserver| |RemoteReply|. |
| 8607 | This function is not available in the |sandbox|. |
| 8608 | {only available when compiled with the |+clientserver| feature} |
| 8609 | |
| 8610 | Note: Any errors will be reported in the server and may mess |
| 8611 | up the display. |
| 8612 | Examples: > |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 8613 | :echo remote_send("gvim", ":DropAndReply " .. file, "serverid") .. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8614 | \ remote_read(serverid) |
| 8615 | |
| 8616 | :autocmd NONE RemoteReply * |
| 8617 | \ echo remote_read(expand("<amatch>")) |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 8618 | :echo remote_send("gvim", ":sleep 10 | echo " .. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8619 | \ 'server2client(expand("<client>"), "HELLO")<CR>') |
| 8620 | < |
| 8621 | Can also be used as a |method|: > |
| 8622 | ServerName()->remote_send(keys) |
| 8623 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8624 | Return type: |String| |
| 8625 | |
| 8626 | |
| 8627 | remote_startserver({name}) *remote_startserver()* *E941* *E942* |
h-east | 17b6951 | 2023-05-01 22:36:56 +0100 | [diff] [blame] | 8628 | Become the server {name}. {name} must be a non-empty string. |
| 8629 | This fails if already running as a server, when |v:servername| |
| 8630 | is not empty. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8631 | |
| 8632 | Can also be used as a |method|: > |
| 8633 | ServerName()->remote_startserver() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8634 | < |
| 8635 | Return type: |Number| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8636 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8637 | {only available when compiled with the |+clientserver| feature} |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8638 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8639 | |
| 8640 | remove({list}, {idx}) *remove()* |
| 8641 | remove({list}, {idx}, {end}) |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8642 | Without {end}: Remove the item at {idx} from |List| {list} and |
| 8643 | return the item. |
| 8644 | With {end}: Remove items from {idx} to {end} (inclusive) and |
| 8645 | return a |List| with these items. When {idx} points to the same |
| 8646 | item as {end} a list with one item is returned. When {end} |
| 8647 | points to an item before {idx} this is an error. |
| 8648 | See |list-index| for possible values of {idx} and {end}. |
Bram Moolenaar | 6ba83ba | 2022-06-12 22:15:57 +0100 | [diff] [blame] | 8649 | Returns zero on error. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8650 | Example: > |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 8651 | :echo "last item: " .. remove(mylist, -1) |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8652 | :call remove(mylist, 0, 9) |
| 8653 | < |
| 8654 | Use |delete()| to remove a file. |
| 8655 | |
| 8656 | Can also be used as a |method|: > |
| 8657 | mylist->remove(idx) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8658 | < |
| 8659 | Return type: any, depending on {list} |
| 8660 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8661 | |
Bram Moolenaar | f269eab | 2022-10-03 18:04:35 +0100 | [diff] [blame] | 8662 | remove({blob}, {idx}) |
| 8663 | remove({blob}, {idx}, {end}) |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8664 | Without {end}: Remove the byte at {idx} from |Blob| {blob} and |
| 8665 | return the byte. |
| 8666 | With {end}: Remove bytes from {idx} to {end} (inclusive) and |
| 8667 | return a |Blob| with these bytes. When {idx} points to the same |
| 8668 | byte as {end} a |Blob| with one byte is returned. When {end} |
| 8669 | points to a byte before {idx} this is an error. |
Bram Moolenaar | 6ba83ba | 2022-06-12 22:15:57 +0100 | [diff] [blame] | 8670 | Returns zero on error. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8671 | Example: > |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 8672 | :echo "last byte: " .. remove(myblob, -1) |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8673 | :call remove(mylist, 0, 9) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8674 | < |
| 8675 | Return type: |Number| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8676 | |
| 8677 | remove({dict}, {key}) |
| 8678 | Remove the entry from {dict} with key {key} and return it. |
| 8679 | Example: > |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 8680 | :echo "removed " .. remove(dict, "one") |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8681 | < If there is no {key} in {dict} this is an error. |
Bram Moolenaar | 6ba83ba | 2022-06-12 22:15:57 +0100 | [diff] [blame] | 8682 | Returns zero on error. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8683 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8684 | Return type: any, depending on {dict} |
| 8685 | |
| 8686 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8687 | rename({from}, {to}) *rename()* |
| 8688 | Rename the file by the name {from} to the name {to}. This |
| 8689 | should also work to move files across file systems. The |
| 8690 | result is a Number, which is 0 if the file was renamed |
| 8691 | successfully, and non-zero when the renaming failed. |
| 8692 | NOTE: If {to} exists it is overwritten without warning. |
| 8693 | This function is not available in the |sandbox|. |
| 8694 | |
| 8695 | Can also be used as a |method|: > |
| 8696 | GetOldName()->rename(newname) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8697 | < |
| 8698 | Return type: |Number| |
| 8699 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8700 | |
| 8701 | repeat({expr}, {count}) *repeat()* |
| 8702 | Repeat {expr} {count} times and return the concatenated |
| 8703 | result. Example: > |
| 8704 | :let separator = repeat('-', 80) |
| 8705 | < When {count} is zero or negative the result is empty. |
Bakudankun | 375141e | 2022-09-09 18:46:47 +0100 | [diff] [blame] | 8706 | When {expr} is a |List| or a |Blob| the result is {expr} |
| 8707 | concatenated {count} times. Example: > |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8708 | :let longlist = repeat(['a', 'b'], 3) |
| 8709 | < Results in ['a', 'b', 'a', 'b', 'a', 'b']. |
| 8710 | |
| 8711 | Can also be used as a |method|: > |
| 8712 | mylist->repeat(count) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8713 | < |
| 8714 | Return type: |String|, |Blob| or list<{type}> depending on |
| 8715 | {expr} |
| 8716 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8717 | |
| 8718 | resolve({filename}) *resolve()* *E655* |
| 8719 | On MS-Windows, when {filename} is a shortcut (a .lnk file), |
| 8720 | returns the path the shortcut points to in a simplified form. |
| 8721 | When {filename} is a symbolic link or junction point, return |
| 8722 | the full path to the target. If the target of junction is |
| 8723 | removed, return {filename}. |
| 8724 | On Unix, repeat resolving symbolic links in all path |
| 8725 | components of {filename} and return the simplified result. |
| 8726 | To cope with link cycles, resolving of symbolic links is |
| 8727 | stopped after 100 iterations. |
| 8728 | On other systems, return the simplified {filename}. |
| 8729 | The simplification step is done as by |simplify()|. |
| 8730 | resolve() keeps a leading path component specifying the |
| 8731 | current directory (provided the result is still a relative |
| 8732 | path name) and also keeps a trailing path separator. |
| 8733 | |
| 8734 | Can also be used as a |method|: > |
| 8735 | GetName()->resolve() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8736 | < |
| 8737 | Return type: |String| |
| 8738 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8739 | |
| 8740 | reverse({object}) *reverse()* |
Yegappan Lakshmanan | 03ff1c2 | 2023-05-06 14:08:21 +0100 | [diff] [blame] | 8741 | Reverse the order of items in {object}. {object} can be a |
| 8742 | |List|, a |Blob| or a |String|. For a List and a Blob the |
| 8743 | items are reversed in-place and {object} is returned. |
| 8744 | For a String a new String is returned. |
| 8745 | Returns zero if {object} is not a List, Blob or a String. |
| 8746 | If you want a List or Blob to remain unmodified make a copy |
| 8747 | first: > |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8748 | :let revlist = reverse(copy(mylist)) |
| 8749 | < Can also be used as a |method|: > |
| 8750 | mylist->reverse() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8751 | < |
| 8752 | Return type: |String|, |Blob| or list<{type}> depending on |
| 8753 | {object} |
| 8754 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8755 | |
| 8756 | round({expr}) *round()* |
| 8757 | Round off {expr} to the nearest integral value and return it |
| 8758 | as a |Float|. If {expr} lies halfway between two integral |
| 8759 | values, then use the larger one (away from zero). |
| 8760 | {expr} must evaluate to a |Float| or a |Number|. |
Bram Moolenaar | 6ba83ba | 2022-06-12 22:15:57 +0100 | [diff] [blame] | 8761 | Returns 0.0 if {expr} is not a |Float| or a |Number|. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8762 | Examples: > |
| 8763 | echo round(0.456) |
| 8764 | < 0.0 > |
| 8765 | echo round(4.5) |
| 8766 | < 5.0 > |
| 8767 | echo round(-4.5) |
| 8768 | < -5.0 |
| 8769 | |
| 8770 | Can also be used as a |method|: > |
| 8771 | Compute()->round() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8772 | < |
| 8773 | Return type: |Float| |
| 8774 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8775 | |
| 8776 | rubyeval({expr}) *rubyeval()* |
| 8777 | Evaluate Ruby expression {expr} and return its result |
| 8778 | converted to Vim data structures. |
| 8779 | Numbers, floats and strings are returned as they are (strings |
| 8780 | are copied though). |
| 8781 | Arrays are represented as Vim |List| type. |
| 8782 | Hashes are represented as Vim |Dictionary| type. |
| 8783 | Other objects are represented as strings resulted from their |
| 8784 | "Object#to_s" method. |
| 8785 | Note that in a `:def` function local variables are not visible |
| 8786 | to {expr}. |
| 8787 | |
| 8788 | Can also be used as a |method|: > |
| 8789 | GetRubyExpr()->rubyeval() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8790 | < |
| 8791 | Return type: any, depending on {expr} |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8792 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8793 | {only available when compiled with the |+ruby| feature} |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8794 | |
| 8795 | screenattr({row}, {col}) *screenattr()* |
| 8796 | Like |screenchar()|, but return the attribute. This is a rather |
| 8797 | arbitrary number that can only be used to compare to the |
| 8798 | attribute at other positions. |
Bram Moolenaar | 6ba83ba | 2022-06-12 22:15:57 +0100 | [diff] [blame] | 8799 | Returns -1 when row or col is out of range. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8800 | |
| 8801 | Can also be used as a |method|: > |
| 8802 | GetRow()->screenattr(col) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8803 | < |
| 8804 | Return type: |Number| |
| 8805 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8806 | |
| 8807 | screenchar({row}, {col}) *screenchar()* |
| 8808 | The result is a Number, which is the character at position |
| 8809 | [row, col] on the screen. This works for every possible |
| 8810 | screen position, also status lines, window separators and the |
| 8811 | command line. The top left position is row one, column one |
| 8812 | The character excludes composing characters. For double-byte |
| 8813 | encodings it may only be the first byte. |
| 8814 | This is mainly to be used for testing. |
| 8815 | Returns -1 when row or col is out of range. |
| 8816 | |
| 8817 | Can also be used as a |method|: > |
| 8818 | GetRow()->screenchar(col) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8819 | < |
| 8820 | Return type: |Number| |
| 8821 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8822 | |
| 8823 | screenchars({row}, {col}) *screenchars()* |
| 8824 | The result is a |List| of Numbers. The first number is the same |
| 8825 | as what |screenchar()| returns. Further numbers are |
| 8826 | composing characters on top of the base character. |
| 8827 | This is mainly to be used for testing. |
| 8828 | Returns an empty List when row or col is out of range. |
| 8829 | |
| 8830 | Can also be used as a |method|: > |
| 8831 | GetRow()->screenchars(col) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8832 | < |
| 8833 | Return type: list<number> or list<any> |
| 8834 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8835 | |
| 8836 | screencol() *screencol()* |
| 8837 | The result is a Number, which is the current screen column of |
| 8838 | the cursor. The leftmost column has number 1. |
| 8839 | This function is mainly used for testing. |
| 8840 | |
| 8841 | Note: Always returns the current screen column, thus if used |
| 8842 | in a command (e.g. ":echo screencol()") it will return the |
| 8843 | column inside the command line, which is 1 when the command is |
| 8844 | executed. To get the cursor position in the file use one of |
| 8845 | the following mappings: > |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 8846 | nnoremap <expr> GG ":echom " .. screencol() .. "\n" |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8847 | nnoremap <silent> GG :echom screencol()<CR> |
| 8848 | nnoremap GG <Cmd>echom screencol()<CR> |
| 8849 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8850 | Return type: |Number| |
| 8851 | |
| 8852 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8853 | screenpos({winid}, {lnum}, {col}) *screenpos()* |
| 8854 | The result is a Dict with the screen position of the text |
| 8855 | character in window {winid} at buffer line {lnum} and column |
| 8856 | {col}. {col} is a one-based byte index. |
| 8857 | The Dict has these members: |
| 8858 | row screen row |
| 8859 | col first screen column |
| 8860 | endcol last screen column |
| 8861 | curscol cursor screen column |
| 8862 | If the specified position is not visible, all values are zero. |
| 8863 | The "endcol" value differs from "col" when the character |
| 8864 | occupies more than one screen cell. E.g. for a Tab "col" can |
| 8865 | be 1 and "endcol" can be 8. |
| 8866 | The "curscol" value is where the cursor would be placed. For |
| 8867 | a Tab it would be the same as "endcol", while for a double |
| 8868 | width character it would be the same as "col". |
| 8869 | The |conceal| feature is ignored here, the column numbers are |
| 8870 | as if 'conceallevel' is zero. You can set the cursor to the |
| 8871 | right position and use |screencol()| to get the value with |
| 8872 | |conceal| taken into account. |
Bram Moolenaar | 944697a | 2022-02-20 19:48:20 +0000 | [diff] [blame] | 8873 | If the position is in a closed fold the screen position of the |
| 8874 | first character is returned, {col} is not used. |
Bram Moolenaar | 6ba83ba | 2022-06-12 22:15:57 +0100 | [diff] [blame] | 8875 | Returns an empty Dict if {winid} is invalid. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8876 | |
| 8877 | Can also be used as a |method|: > |
| 8878 | GetWinid()->screenpos(lnum, col) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8879 | < |
| 8880 | Return type: dict<number> or dict<any> |
| 8881 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8882 | |
| 8883 | screenrow() *screenrow()* |
| 8884 | The result is a Number, which is the current screen row of the |
| 8885 | cursor. The top line has number one. |
| 8886 | This function is mainly used for testing. |
| 8887 | Alternatively you can use |winline()|. |
| 8888 | |
| 8889 | Note: Same restrictions as with |screencol()|. |
| 8890 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8891 | Return type: |Number| |
| 8892 | |
| 8893 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8894 | screenstring({row}, {col}) *screenstring()* |
| 8895 | The result is a String that contains the base character and |
| 8896 | any composing characters at position [row, col] on the screen. |
| 8897 | This is like |screenchars()| but returning a String with the |
| 8898 | characters. |
| 8899 | This is mainly to be used for testing. |
| 8900 | Returns an empty String when row or col is out of range. |
| 8901 | |
| 8902 | Can also be used as a |method|: > |
| 8903 | GetRow()->screenstring(col) |
| 8904 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 8905 | Return type: |String| |
| 8906 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8907 | *search()* |
| 8908 | search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]]) |
| 8909 | Search for regexp pattern {pattern}. The search starts at the |
| 8910 | cursor position (you can use |cursor()| to set it). |
| 8911 | |
| 8912 | When a match has been found its line number is returned. |
| 8913 | If there is no match a 0 is returned and the cursor doesn't |
| 8914 | move. No error message is given. |
Christian Brabandt | 9a660d2 | 2024-03-12 22:03:09 +0100 | [diff] [blame] | 8915 | To get the matched string, use |matchbufline()|. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8916 | |
| 8917 | {flags} is a String, which can contain these character flags: |
| 8918 | 'b' search Backward instead of forward |
| 8919 | 'c' accept a match at the Cursor position |
| 8920 | 'e' move to the End of the match |
| 8921 | 'n' do Not move the cursor |
| 8922 | 'p' return number of matching sub-Pattern (see below) |
| 8923 | 's' Set the ' mark at the previous location of the cursor |
| 8924 | 'w' Wrap around the end of the file |
| 8925 | 'W' don't Wrap around the end of the file |
| 8926 | 'z' start searching at the cursor column instead of zero |
| 8927 | If neither 'w' or 'W' is given, the 'wrapscan' option applies. |
| 8928 | |
| 8929 | If the 's' flag is supplied, the ' mark is set, only if the |
| 8930 | cursor is moved. The 's' flag cannot be combined with the 'n' |
| 8931 | flag. |
| 8932 | |
| 8933 | 'ignorecase', 'smartcase' and 'magic' are used. |
| 8934 | |
| 8935 | When the 'z' flag is not given, forward searching always |
| 8936 | starts in column zero and then matches before the cursor are |
| 8937 | skipped. When the 'c' flag is present in 'cpo' the next |
| 8938 | search starts after the match. Without the 'c' flag the next |
Bram Moolenaar | fd99945 | 2022-08-24 18:30:14 +0100 | [diff] [blame] | 8939 | search starts one column after the start of the match. This |
| 8940 | matters for overlapping matches. See |cpo-c|. You can also |
| 8941 | insert "\ze" to change where the match ends, see |/\ze|. |
| 8942 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8943 | When searching backwards and the 'z' flag is given then the |
| 8944 | search starts in column zero, thus no match in the current |
| 8945 | line will be found (unless wrapping around the end of the |
| 8946 | file). |
| 8947 | |
| 8948 | When the {stopline} argument is given then the search stops |
| 8949 | after searching this line. This is useful to restrict the |
| 8950 | search to a range of lines. Examples: > |
| 8951 | let match = search('(', 'b', line("w0")) |
| 8952 | let end = search('END', '', line("w$")) |
| 8953 | < When {stopline} is used and it is not zero this also implies |
| 8954 | that the search does not wrap around the end of the file. |
| 8955 | A zero value is equal to not giving the argument. |
Bram Moolenaar | 2ecbe53 | 2022-07-29 21:36:21 +0100 | [diff] [blame] | 8956 | *E1285* *E1286* *E1287* *E1288* *E1289* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8957 | When the {timeout} argument is given the search stops when |
| 8958 | more than this many milliseconds have passed. Thus when |
| 8959 | {timeout} is 500 the search stops after half a second. |
| 8960 | The value must not be negative. A zero value is like not |
| 8961 | giving the argument. |
| 8962 | {only available when compiled with the |+reltime| feature} |
| 8963 | |
| 8964 | If the {skip} expression is given it is evaluated with the |
| 8965 | cursor positioned on the start of a match. If it evaluates to |
| 8966 | non-zero this match is skipped. This can be used, for |
| 8967 | example, to skip a match in a comment or a string. |
| 8968 | {skip} can be a string, which is evaluated as an expression, a |
| 8969 | function reference or a lambda. |
| 8970 | When {skip} is omitted or empty, every match is accepted. |
| 8971 | When evaluating {skip} causes an error the search is aborted |
| 8972 | and -1 returned. |
| 8973 | *search()-sub-match* |
| 8974 | With the 'p' flag the returned value is one more than the |
| 8975 | first sub-match in \(\). One if none of them matched but the |
| 8976 | whole pattern did match. |
| 8977 | To get the column number too use |searchpos()|. |
| 8978 | |
| 8979 | The cursor will be positioned at the match, unless the 'n' |
| 8980 | flag is used. |
| 8981 | |
| 8982 | Example (goes over all files in the argument list): > |
| 8983 | :let n = 1 |
| 8984 | :while n <= argc() " loop over all files in arglist |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 8985 | : exe "argument " .. n |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 8986 | : " start at the last char in the file and wrap for the |
| 8987 | : " first search to find match at start of file |
| 8988 | : normal G$ |
| 8989 | : let flags = "w" |
| 8990 | : while search("foo", flags) > 0 |
| 8991 | : s/foo/bar/g |
| 8992 | : let flags = "W" |
| 8993 | : endwhile |
| 8994 | : update " write the file if modified |
| 8995 | : let n = n + 1 |
| 8996 | :endwhile |
| 8997 | < |
| 8998 | Example for using some flags: > |
| 8999 | :echo search('\<if\|\(else\)\|\(endif\)', 'ncpe') |
| 9000 | < This will search for the keywords "if", "else", and "endif" |
| 9001 | under or after the cursor. Because of the 'p' flag, it |
| 9002 | returns 1, 2, or 3 depending on which keyword is found, or 0 |
| 9003 | if the search fails. With the cursor on the first word of the |
| 9004 | line: |
| 9005 | if (foo == 0) | let foo = foo + 1 | endif ~ |
| 9006 | the function returns 1. Without the 'c' flag, the function |
| 9007 | finds the "endif" and returns 3. The same thing happens |
| 9008 | without the 'e' flag if the cursor is on the "f" of "if". |
| 9009 | The 'n' flag tells the function not to move the cursor. |
| 9010 | |
| 9011 | Can also be used as a |method|: > |
| 9012 | GetPattern()->search() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 9013 | < |
| 9014 | Return type: |Number| |
| 9015 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9016 | |
| 9017 | searchcount([{options}]) *searchcount()* |
| 9018 | Get or update the last search count, like what is displayed |
| 9019 | without the "S" flag in 'shortmess'. This works even if |
| 9020 | 'shortmess' does contain the "S" flag. |
| 9021 | |
| 9022 | This returns a |Dictionary|. The dictionary is empty if the |
| 9023 | previous pattern was not set and "pattern" was not specified. |
| 9024 | |
| 9025 | key type meaning ~ |
| 9026 | current |Number| current position of match; |
| 9027 | 0 if the cursor position is |
| 9028 | before the first match |
| 9029 | exact_match |Boolean| 1 if "current" is matched on |
| 9030 | "pos", otherwise 0 |
| 9031 | total |Number| total count of matches found |
| 9032 | incomplete |Number| 0: search was fully completed |
| 9033 | 1: recomputing was timed out |
| 9034 | 2: max count exceeded |
| 9035 | |
| 9036 | For {options} see further down. |
| 9037 | |
| 9038 | To get the last search count when |n| or |N| was pressed, call |
| 9039 | this function with `recompute: 0` . This sometimes returns |
| 9040 | wrong information because |n| and |N|'s maximum count is 99. |
| 9041 | If it exceeded 99 the result must be max count + 1 (100). If |
| 9042 | you want to get correct information, specify `recompute: 1`: > |
| 9043 | |
| 9044 | " result == maxcount + 1 (100) when many matches |
| 9045 | let result = searchcount(#{recompute: 0}) |
| 9046 | |
| 9047 | " Below returns correct result (recompute defaults |
| 9048 | " to 1) |
| 9049 | let result = searchcount() |
| 9050 | < |
Bram Moolenaar | b529cfb | 2022-07-25 15:42:07 +0100 | [diff] [blame] | 9051 | The function is useful to add the count to 'statusline': > |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9052 | function! LastSearchCount() abort |
| 9053 | let result = searchcount(#{recompute: 0}) |
| 9054 | if empty(result) |
| 9055 | return '' |
| 9056 | endif |
| 9057 | if result.incomplete ==# 1 " timed out |
| 9058 | return printf(' /%s [?/??]', @/) |
| 9059 | elseif result.incomplete ==# 2 " max count exceeded |
| 9060 | if result.total > result.maxcount && |
| 9061 | \ result.current > result.maxcount |
| 9062 | return printf(' /%s [>%d/>%d]', @/, |
| 9063 | \ result.current, result.total) |
| 9064 | elseif result.total > result.maxcount |
| 9065 | return printf(' /%s [%d/>%d]', @/, |
| 9066 | \ result.current, result.total) |
| 9067 | endif |
| 9068 | endif |
| 9069 | return printf(' /%s [%d/%d]', @/, |
| 9070 | \ result.current, result.total) |
| 9071 | endfunction |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 9072 | let &statusline ..= '%{LastSearchCount()}' |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9073 | |
| 9074 | " Or if you want to show the count only when |
| 9075 | " 'hlsearch' was on |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 9076 | " let &statusline ..= |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9077 | " \ '%{v:hlsearch ? LastSearchCount() : ""}' |
| 9078 | < |
| 9079 | You can also update the search count, which can be useful in a |
| 9080 | |CursorMoved| or |CursorMovedI| autocommand: > |
| 9081 | |
| 9082 | autocmd CursorMoved,CursorMovedI * |
| 9083 | \ let s:searchcount_timer = timer_start( |
| 9084 | \ 200, function('s:update_searchcount')) |
| 9085 | function! s:update_searchcount(timer) abort |
| 9086 | if a:timer ==# s:searchcount_timer |
| 9087 | call searchcount(#{ |
| 9088 | \ recompute: 1, maxcount: 0, timeout: 100}) |
| 9089 | redrawstatus |
| 9090 | endif |
| 9091 | endfunction |
| 9092 | < |
| 9093 | This can also be used to count matched texts with specified |
| 9094 | pattern in the current buffer using "pattern": > |
| 9095 | |
| 9096 | " Count '\<foo\>' in this buffer |
| 9097 | " (Note that it also updates search count) |
| 9098 | let result = searchcount(#{pattern: '\<foo\>'}) |
| 9099 | |
| 9100 | " To restore old search count by old pattern, |
| 9101 | " search again |
| 9102 | call searchcount() |
| 9103 | < |
| 9104 | {options} must be a |Dictionary|. It can contain: |
| 9105 | key type meaning ~ |
| 9106 | recompute |Boolean| if |TRUE|, recompute the count |
| 9107 | like |n| or |N| was executed. |
| 9108 | otherwise returns the last |
| 9109 | computed result (when |n| or |
| 9110 | |N| was used when "S" is not |
| 9111 | in 'shortmess', or this |
| 9112 | function was called). |
| 9113 | (default: |TRUE|) |
| 9114 | pattern |String| recompute if this was given |
| 9115 | and different with |@/|. |
| 9116 | this works as same as the |
| 9117 | below command is executed |
| 9118 | before calling this function > |
| 9119 | let @/ = pattern |
| 9120 | < (default: |@/|) |
| 9121 | timeout |Number| 0 or negative number is no |
| 9122 | timeout. timeout milliseconds |
| 9123 | for recomputing the result |
| 9124 | (default: 0) |
| 9125 | maxcount |Number| 0 or negative number is no |
| 9126 | limit. max count of matched |
| 9127 | text while recomputing the |
| 9128 | result. if search exceeded |
| 9129 | total count, "total" value |
| 9130 | becomes `maxcount + 1` |
| 9131 | (default: 99) |
| 9132 | pos |List| `[lnum, col, off]` value |
| 9133 | when recomputing the result. |
| 9134 | this changes "current" result |
| 9135 | value. see |cursor()|, |
| 9136 | |getpos()| |
| 9137 | (default: cursor's position) |
| 9138 | |
| 9139 | Can also be used as a |method|: > |
| 9140 | GetSearchOpts()->searchcount() |
| 9141 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 9142 | Return type: dict<number> |
| 9143 | |
| 9144 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9145 | searchdecl({name} [, {global} [, {thisblock}]]) *searchdecl()* |
| 9146 | Search for the declaration of {name}. |
| 9147 | |
| 9148 | With a non-zero {global} argument it works like |gD|, find |
| 9149 | first match in the file. Otherwise it works like |gd|, find |
| 9150 | first match in the function. |
| 9151 | |
| 9152 | With a non-zero {thisblock} argument matches in a {} block |
| 9153 | that ends before the cursor position are ignored. Avoids |
| 9154 | finding variable declarations only valid in another scope. |
| 9155 | |
| 9156 | Moves the cursor to the found match. |
| 9157 | Returns zero for success, non-zero for failure. |
| 9158 | Example: > |
| 9159 | if searchdecl('myvar') == 0 |
| 9160 | echo getline('.') |
| 9161 | endif |
| 9162 | < |
| 9163 | Can also be used as a |method|: > |
| 9164 | GetName()->searchdecl() |
| 9165 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 9166 | Return type: |Number| |
| 9167 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9168 | *searchpair()* |
| 9169 | searchpair({start}, {middle}, {end} [, {flags} [, {skip} |
| 9170 | [, {stopline} [, {timeout}]]]]) |
| 9171 | Search for the match of a nested start-end pair. This can be |
| 9172 | used to find the "endif" that matches an "if", while other |
| 9173 | if/endif pairs in between are ignored. |
| 9174 | The search starts at the cursor. The default is to search |
| 9175 | forward, include 'b' in {flags} to search backward. |
| 9176 | If a match is found, the cursor is positioned at it and the |
| 9177 | line number is returned. If no match is found 0 or -1 is |
| 9178 | returned and the cursor doesn't move. No error message is |
| 9179 | given. |
| 9180 | |
| 9181 | {start}, {middle} and {end} are patterns, see |pattern|. They |
| 9182 | must not contain \( \) pairs. Use of \%( \) is allowed. When |
| 9183 | {middle} is not empty, it is found when searching from either |
| 9184 | direction, but only when not in a nested start-end pair. A |
| 9185 | typical use is: > |
| 9186 | searchpair('\<if\>', '\<else\>', '\<endif\>') |
| 9187 | < By leaving {middle} empty the "else" is skipped. |
| 9188 | |
| 9189 | {flags} 'b', 'c', 'n', 's', 'w' and 'W' are used like with |
| 9190 | |search()|. Additionally: |
| 9191 | 'r' Repeat until no more matches found; will find the |
| 9192 | outer pair. Implies the 'W' flag. |
| 9193 | 'm' Return number of matches instead of line number with |
| 9194 | the match; will be > 1 when 'r' is used. |
| 9195 | Note: it's nearly always a good idea to use the 'W' flag, to |
| 9196 | avoid wrapping around the end of the file. |
| 9197 | |
| 9198 | When a match for {start}, {middle} or {end} is found, the |
| 9199 | {skip} expression is evaluated with the cursor positioned on |
| 9200 | the start of the match. It should return non-zero if this |
| 9201 | match is to be skipped. E.g., because it is inside a comment |
| 9202 | or a string. |
| 9203 | When {skip} is omitted or empty, every match is accepted. |
| 9204 | When evaluating {skip} causes an error the search is aborted |
| 9205 | and -1 returned. |
| 9206 | {skip} can be a string, a lambda, a funcref or a partial. |
| 9207 | Anything else makes the function fail. |
| 9208 | In a `:def` function when the {skip} argument is a string |
| 9209 | constant it is compiled into instructions. |
| 9210 | |
| 9211 | For {stopline} and {timeout} see |search()|. |
| 9212 | |
| 9213 | The value of 'ignorecase' is used. 'magic' is ignored, the |
| 9214 | patterns are used like it's on. |
| 9215 | |
| 9216 | The search starts exactly at the cursor. A match with |
| 9217 | {start}, {middle} or {end} at the next character, in the |
| 9218 | direction of searching, is the first one found. Example: > |
| 9219 | if 1 |
| 9220 | if 2 |
| 9221 | endif 2 |
| 9222 | endif 1 |
| 9223 | < When starting at the "if 2", with the cursor on the "i", and |
| 9224 | searching forwards, the "endif 2" is found. When starting on |
| 9225 | the character just before the "if 2", the "endif 1" will be |
| 9226 | found. That's because the "if 2" will be found first, and |
| 9227 | then this is considered to be a nested if/endif from "if 2" to |
| 9228 | "endif 2". |
| 9229 | When searching backwards and {end} is more than one character, |
| 9230 | it may be useful to put "\zs" at the end of the pattern, so |
| 9231 | that when the cursor is inside a match with the end it finds |
| 9232 | the matching start. |
| 9233 | |
| 9234 | Example, to find the "endif" command in a Vim script: > |
| 9235 | |
| 9236 | :echo searchpair('\<if\>', '\<el\%[seif]\>', '\<en\%[dif]\>', 'W', |
| 9237 | \ 'getline(".") =~ "^\\s*\""') |
| 9238 | |
| 9239 | < The cursor must be at or after the "if" for which a match is |
| 9240 | to be found. Note that single-quote strings are used to avoid |
| 9241 | having to double the backslashes. The skip expression only |
| 9242 | catches comments at the start of a line, not after a command. |
| 9243 | Also, a word "en" or "if" halfway a line is considered a |
| 9244 | match. |
| 9245 | Another example, to search for the matching "{" of a "}": > |
| 9246 | |
| 9247 | :echo searchpair('{', '', '}', 'bW') |
| 9248 | |
| 9249 | < This works when the cursor is at or before the "}" for which a |
| 9250 | match is to be found. To reject matches that syntax |
| 9251 | highlighting recognized as strings: > |
| 9252 | |
| 9253 | :echo searchpair('{', '', '}', 'bW', |
| 9254 | \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"') |
| 9255 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 9256 | Return type: |Number| |
| 9257 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9258 | *searchpairpos()* |
| 9259 | searchpairpos({start}, {middle}, {end} [, {flags} [, {skip} |
| 9260 | [, {stopline} [, {timeout}]]]]) |
| 9261 | Same as |searchpair()|, but returns a |List| with the line and |
| 9262 | column position of the match. The first element of the |List| |
| 9263 | is the line number and the second element is the byte index of |
| 9264 | the column position of the match. If no match is found, |
| 9265 | returns [0, 0]. > |
| 9266 | |
| 9267 | :let [lnum,col] = searchpairpos('{', '', '}', 'n') |
| 9268 | < |
| 9269 | See |match-parens| for a bigger and more useful example. |
| 9270 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 9271 | Return type: list<number> |
| 9272 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9273 | *searchpos()* |
| 9274 | searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]]) |
| 9275 | Same as |search()|, but returns a |List| with the line and |
| 9276 | column position of the match. The first element of the |List| |
| 9277 | is the line number and the second element is the byte index of |
| 9278 | the column position of the match. If no match is found, |
| 9279 | returns [0, 0]. |
| 9280 | Example: > |
| 9281 | :let [lnum, col] = searchpos('mypattern', 'n') |
| 9282 | |
| 9283 | < When the 'p' flag is given then there is an extra item with |
| 9284 | the sub-pattern match number |search()-sub-match|. Example: > |
| 9285 | :let [lnum, col, submatch] = searchpos('\(\l\)\|\(\u\)', 'np') |
| 9286 | < In this example "submatch" is 2 when a lowercase letter is |
| 9287 | found |/\l|, 3 when an uppercase letter is found |/\u|. |
| 9288 | |
| 9289 | Can also be used as a |method|: > |
| 9290 | GetPattern()->searchpos() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 9291 | < |
| 9292 | Return type: list<number> |
| 9293 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9294 | |
| 9295 | server2client({clientid}, {string}) *server2client()* |
| 9296 | Send a reply string to {clientid}. The most recent {clientid} |
| 9297 | that sent a string can be retrieved with expand("<client>"). |
| 9298 | {only available when compiled with the |+clientserver| feature} |
| 9299 | Returns zero for success, -1 for failure. |
| 9300 | Note: |
| 9301 | This id has to be stored before the next command can be |
| 9302 | received. I.e. before returning from the received command and |
| 9303 | before calling any commands that waits for input. |
| 9304 | See also |clientserver|. |
| 9305 | Example: > |
| 9306 | :echo server2client(expand("<client>"), "HELLO") |
| 9307 | |
| 9308 | < Can also be used as a |method|: > |
| 9309 | GetClientId()->server2client(string) |
| 9310 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 9311 | Return type: |Number| |
| 9312 | |
| 9313 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9314 | serverlist() *serverlist()* |
| 9315 | Return a list of available server names, one per line. |
| 9316 | When there are no servers or the information is not available |
| 9317 | an empty string is returned. See also |clientserver|. |
| 9318 | {only available when compiled with the |+clientserver| feature} |
| 9319 | Example: > |
| 9320 | :echo serverlist() |
| 9321 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 9322 | Return type: |String| |
| 9323 | |
| 9324 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9325 | setbufline({buf}, {lnum}, {text}) *setbufline()* |
| 9326 | Set line {lnum} to {text} in buffer {buf}. This works like |
| 9327 | |setline()| for the specified buffer. |
| 9328 | |
| 9329 | This function works only for loaded buffers. First call |
| 9330 | |bufload()| if needed. |
| 9331 | |
| 9332 | To insert lines use |appendbufline()|. |
| 9333 | Any text properties in {lnum} are cleared. |
| 9334 | |
Bram Moolenaar | cd9c8d4 | 2022-11-05 23:46:43 +0000 | [diff] [blame] | 9335 | {text} can be a string to set one line, or a List of strings |
| 9336 | to set multiple lines. If the List extends below the last |
| 9337 | line then those lines are added. If the List is empty then |
| 9338 | nothing is changed and zero is returned. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9339 | |
| 9340 | For the use of {buf}, see |bufname()| above. |
| 9341 | |
| 9342 | {lnum} is used like with |setline()|. |
| 9343 | Use "$" to refer to the last line in buffer {buf}. |
| 9344 | When {lnum} is just below the last line the {text} will be |
| 9345 | added below the last line. |
| 9346 | |
| 9347 | When {buf} is not a valid buffer, the buffer is not loaded or |
| 9348 | {lnum} is not valid then 1 is returned. In |Vim9| script an |
| 9349 | error is given. |
| 9350 | On success 0 is returned. |
| 9351 | |
| 9352 | Can also be used as a |method|, the base is passed as the |
| 9353 | third argument: > |
| 9354 | GetText()->setbufline(buf, lnum) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 9355 | < |
| 9356 | Return type: |Number| |
| 9357 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9358 | |
| 9359 | setbufvar({buf}, {varname}, {val}) *setbufvar()* |
| 9360 | Set option or local variable {varname} in buffer {buf} to |
| 9361 | {val}. |
| 9362 | This also works for a global or local window option, but it |
| 9363 | doesn't work for a global or local window variable. |
| 9364 | For a local window option the global value is unchanged. |
| 9365 | For the use of {buf}, see |bufname()| above. |
| 9366 | The {varname} argument is a string. |
| 9367 | Note that the variable name without "b:" must be used. |
| 9368 | Examples: > |
| 9369 | :call setbufvar(1, "&mod", 1) |
| 9370 | :call setbufvar("todo", "myvar", "foobar") |
| 9371 | < This function is not available in the |sandbox|. |
| 9372 | |
| 9373 | Can also be used as a |method|, the base is passed as the |
| 9374 | third argument: > |
| 9375 | GetValue()->setbufvar(buf, varname) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 9376 | < |
| 9377 | Return type: |Number| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9378 | |
| 9379 | |
| 9380 | setcellwidths({list}) *setcellwidths()* |
| 9381 | Specify overrides for cell widths of character ranges. This |
Bram Moolenaar | b59ae59 | 2022-11-23 23:46:31 +0000 | [diff] [blame] | 9382 | tells Vim how wide characters are when displayed in the |
| 9383 | terminal, counted in screen cells. The values override |
| 9384 | 'ambiwidth'. Example: > |
| 9385 | call setcellwidths([ |
Bram Moolenaar | 938ae28 | 2023-02-20 20:44:55 +0000 | [diff] [blame] | 9386 | \ [0x111, 0x111, 1], |
Bram Moolenaar | b59ae59 | 2022-11-23 23:46:31 +0000 | [diff] [blame] | 9387 | \ [0x2194, 0x2199, 2], |
| 9388 | \ ]) |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9389 | |
Bram Moolenaar | b59ae59 | 2022-11-23 23:46:31 +0000 | [diff] [blame] | 9390 | < The {list} argument is a List of Lists with each three |
| 9391 | numbers: [{low}, {high}, {width}]. *E1109* *E1110* |
| 9392 | {low} and {high} can be the same, in which case this refers to |
| 9393 | one character. Otherwise it is the range of characters from |
| 9394 | {low} to {high} (inclusive). *E1111* *E1114* |
K.Takata | 7193323 | 2023-01-20 16:00:55 +0000 | [diff] [blame] | 9395 | Only characters with value 0x80 and higher can be used. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9396 | |
Bram Moolenaar | b59ae59 | 2022-11-23 23:46:31 +0000 | [diff] [blame] | 9397 | {width} must be either 1 or 2, indicating the character width |
| 9398 | in screen cells. *E1112* |
| 9399 | An error is given if the argument is invalid, also when a |
Bram Moolenaar | 938ae28 | 2023-02-20 20:44:55 +0000 | [diff] [blame] | 9400 | range overlaps with another. *E1113* |
Bram Moolenaar | b59ae59 | 2022-11-23 23:46:31 +0000 | [diff] [blame] | 9401 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9402 | If the new value causes 'fillchars' or 'listchars' to become |
| 9403 | invalid it is rejected and an error is given. |
| 9404 | |
Bram Moolenaar | b59ae59 | 2022-11-23 23:46:31 +0000 | [diff] [blame] | 9405 | To clear the overrides pass an empty {list}: > |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9406 | setcellwidths([]); |
Bram Moolenaar | b59ae59 | 2022-11-23 23:46:31 +0000 | [diff] [blame] | 9407 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9408 | < You can use the script $VIMRUNTIME/tools/emoji_list.vim to see |
Bram Moolenaar | b59ae59 | 2022-11-23 23:46:31 +0000 | [diff] [blame] | 9409 | the effect for known emoji characters. Move the cursor |
| 9410 | through the text to check if the cell widths of your terminal |
| 9411 | match with what Vim knows about each emoji. If it doesn't |
| 9412 | look right you need to adjust the {list} argument. |
| 9413 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 9414 | Return type: |Number| |
| 9415 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9416 | |
| 9417 | setcharpos({expr}, {list}) *setcharpos()* |
| 9418 | Same as |setpos()| but uses the specified column number as the |
| 9419 | character index instead of the byte index in the line. |
| 9420 | |
| 9421 | Example: |
| 9422 | With the text "여보세요" in line 8: > |
| 9423 | call setcharpos('.', [0, 8, 4, 0]) |
| 9424 | < positions the cursor on the fourth character '요'. > |
| 9425 | call setpos('.', [0, 8, 4, 0]) |
| 9426 | < positions the cursor on the second character '보'. |
| 9427 | |
| 9428 | Can also be used as a |method|: > |
| 9429 | GetPosition()->setcharpos('.') |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 9430 | < |
| 9431 | Return type: |Number| |
| 9432 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9433 | |
| 9434 | setcharsearch({dict}) *setcharsearch()* |
| 9435 | Set the current character search information to {dict}, |
| 9436 | which contains one or more of the following entries: |
| 9437 | |
| 9438 | char character which will be used for a subsequent |
| 9439 | |,| or |;| command; an empty string clears the |
| 9440 | character search |
| 9441 | forward direction of character search; 1 for forward, |
| 9442 | 0 for backward |
| 9443 | until type of character search; 1 for a |t| or |T| |
| 9444 | character search, 0 for an |f| or |F| |
| 9445 | character search |
| 9446 | |
| 9447 | This can be useful to save/restore a user's character search |
| 9448 | from a script: > |
| 9449 | :let prevsearch = getcharsearch() |
| 9450 | :" Perform a command which clobbers user's search |
| 9451 | :call setcharsearch(prevsearch) |
| 9452 | < Also see |getcharsearch()|. |
| 9453 | |
| 9454 | Can also be used as a |method|: > |
| 9455 | SavedSearch()->setcharsearch() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 9456 | < |
| 9457 | Return type: dict<any> |
| 9458 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9459 | |
Shougo Matsushita | 07ea5f1 | 2022-08-27 12:22:25 +0100 | [diff] [blame] | 9460 | setcmdline({str} [, {pos}]) *setcmdline()* |
| 9461 | Set the command line to {str} and set the cursor position to |
| 9462 | {pos}. |
| 9463 | If {pos} is omitted, the cursor is positioned after the text. |
| 9464 | Returns 0 when successful, 1 when not editing the command |
| 9465 | line. |
| 9466 | |
| 9467 | Can also be used as a |method|: > |
| 9468 | GetText()->setcmdline() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 9469 | < |
| 9470 | Return type: |Number| |
| 9471 | |
Shougo Matsushita | 07ea5f1 | 2022-08-27 12:22:25 +0100 | [diff] [blame] | 9472 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9473 | setcmdpos({pos}) *setcmdpos()* |
| 9474 | Set the cursor position in the command line to byte position |
| 9475 | {pos}. The first position is 1. |
| 9476 | Use |getcmdpos()| to obtain the current position. |
| 9477 | Only works while editing the command line, thus you must use |
| 9478 | |c_CTRL-\_e|, |c_CTRL-R_=| or |c_CTRL-R_CTRL-R| with '='. For |
| 9479 | |c_CTRL-\_e| and |c_CTRL-R_CTRL-R| with '=' the position is |
| 9480 | set after the command line is set to the expression. For |
| 9481 | |c_CTRL-R_=| it is set after evaluating the expression but |
| 9482 | before inserting the resulting text. |
| 9483 | When the number is too big the cursor is put at the end of the |
| 9484 | line. A number smaller than one has undefined results. |
Shougo Matsushita | 07ea5f1 | 2022-08-27 12:22:25 +0100 | [diff] [blame] | 9485 | Returns 0 when successful, 1 when not editing the command |
| 9486 | line. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9487 | |
| 9488 | Can also be used as a |method|: > |
| 9489 | GetPos()->setcmdpos() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 9490 | < |
| 9491 | Return type: |Number| |
| 9492 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9493 | |
| 9494 | setcursorcharpos({lnum}, {col} [, {off}]) *setcursorcharpos()* |
| 9495 | setcursorcharpos({list}) |
| 9496 | Same as |cursor()| but uses the specified column number as the |
| 9497 | character index instead of the byte index in the line. |
| 9498 | |
| 9499 | Example: |
| 9500 | With the text "여보세요" in line 4: > |
| 9501 | call setcursorcharpos(4, 3) |
| 9502 | < positions the cursor on the third character '세'. > |
| 9503 | call cursor(4, 3) |
| 9504 | < positions the cursor on the first character '여'. |
| 9505 | |
| 9506 | Can also be used as a |method|: > |
| 9507 | GetCursorPos()->setcursorcharpos() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 9508 | < |
| 9509 | Return type: |Number| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9510 | |
| 9511 | |
| 9512 | setenv({name}, {val}) *setenv()* |
| 9513 | Set environment variable {name} to {val}. Example: > |
| 9514 | call setenv('HOME', '/home/myhome') |
| 9515 | |
| 9516 | < When {val} is |v:null| the environment variable is deleted. |
| 9517 | See also |expr-env|. |
| 9518 | |
| 9519 | Can also be used as a |method|, the base is passed as the |
| 9520 | second argument: > |
| 9521 | GetPath()->setenv('PATH') |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 9522 | < |
| 9523 | Return type: |Number| |
| 9524 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9525 | |
| 9526 | setfperm({fname}, {mode}) *setfperm()* *chmod* |
| 9527 | Set the file permissions for {fname} to {mode}. |
| 9528 | {mode} must be a string with 9 characters. It is of the form |
| 9529 | "rwxrwxrwx", where each group of "rwx" flags represent, in |
| 9530 | turn, the permissions of the owner of the file, the group the |
| 9531 | file belongs to, and other users. A '-' character means the |
| 9532 | permission is off, any other character means on. Multi-byte |
| 9533 | characters are not supported. |
| 9534 | |
| 9535 | For example "rw-r-----" means read-write for the user, |
| 9536 | readable by the group, not accessible by others. "xx-x-----" |
| 9537 | would do the same thing. |
| 9538 | |
| 9539 | Returns non-zero for success, zero for failure. |
| 9540 | |
| 9541 | Can also be used as a |method|: > |
| 9542 | GetFilename()->setfperm(mode) |
| 9543 | < |
| 9544 | To read permissions see |getfperm()|. |
| 9545 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 9546 | Return type: |Number| |
| 9547 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9548 | |
| 9549 | setline({lnum}, {text}) *setline()* |
| 9550 | Set line {lnum} of the current buffer to {text}. To insert |
| 9551 | lines use |append()|. To set lines in another buffer use |
Christian Brabandt | 946f61c | 2024-06-17 13:17:58 +0200 | [diff] [blame] | 9552 | |setbufline()|. |
| 9553 | Any text properties in {lnum} are cleared |text-prop-cleared|. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9554 | |
| 9555 | {lnum} is used like with |getline()|. |
| 9556 | When {lnum} is just below the last line the {text} will be |
| 9557 | added below the last line. |
| 9558 | {text} can be any type or a List of any type, each item is |
Bram Moolenaar | cd9c8d4 | 2022-11-05 23:46:43 +0000 | [diff] [blame] | 9559 | converted to a String. When {text} is an empty List then |
| 9560 | nothing is changed and FALSE is returned. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9561 | |
| 9562 | If this succeeds, FALSE is returned. If this fails (most likely |
| 9563 | because {lnum} is invalid) TRUE is returned. |
| 9564 | In |Vim9| script an error is given if {lnum} is invalid. |
| 9565 | |
| 9566 | Example: > |
| 9567 | :call setline(5, strftime("%c")) |
| 9568 | |
| 9569 | < When {text} is a |List| then line {lnum} and following lines |
| 9570 | will be set to the items in the list. Example: > |
| 9571 | :call setline(5, ['aaa', 'bbb', 'ccc']) |
| 9572 | < This is equivalent to: > |
| 9573 | :for [n, l] in [[5, 'aaa'], [6, 'bbb'], [7, 'ccc']] |
| 9574 | : call setline(n, l) |
| 9575 | :endfor |
| 9576 | |
| 9577 | < Note: The '[ and '] marks are not set. |
| 9578 | |
| 9579 | Can also be used as a |method|, the base is passed as the |
| 9580 | second argument: > |
| 9581 | GetText()->setline(lnum) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 9582 | < |
| 9583 | Return type: |Number| |
| 9584 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9585 | |
| 9586 | setloclist({nr}, {list} [, {action} [, {what}]]) *setloclist()* |
| 9587 | Create or replace or add to the location list for window {nr}. |
| 9588 | {nr} can be the window number or the |window-ID|. |
| 9589 | When {nr} is zero the current window is used. |
| 9590 | |
| 9591 | For a location list window, the displayed location list is |
| 9592 | modified. For an invalid window number {nr}, -1 is returned. |
| 9593 | Otherwise, same as |setqflist()|. |
| 9594 | Also see |location-list|. |
| 9595 | |
| 9596 | For {action} see |setqflist-action|. |
| 9597 | |
| 9598 | If the optional {what} dictionary argument is supplied, then |
| 9599 | only the items listed in {what} are set. Refer to |setqflist()| |
| 9600 | for the list of supported keys in {what}. |
| 9601 | |
| 9602 | Can also be used as a |method|, the base is passed as the |
| 9603 | second argument: > |
| 9604 | GetLoclist()->setloclist(winnr) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 9605 | < |
| 9606 | Return type: |Number| |
| 9607 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9608 | |
| 9609 | setmatches({list} [, {win}]) *setmatches()* |
| 9610 | Restores a list of matches saved by |getmatches()| for the |
| 9611 | current window. Returns 0 if successful, otherwise -1. All |
| 9612 | current matches are cleared before the list is restored. See |
| 9613 | example for |getmatches()|. |
| 9614 | If {win} is specified, use the window with this number or |
| 9615 | window ID instead of the current window. |
| 9616 | |
| 9617 | Can also be used as a |method|: > |
| 9618 | GetMatches()->setmatches() |
| 9619 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 9620 | Return type: |Number| |
| 9621 | |
| 9622 | |
| 9623 | setpos({expr}, {list}) *setpos()* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9624 | Set the position for String {expr}. Possible values: |
| 9625 | . the cursor |
| 9626 | 'x mark x |
| 9627 | |
| 9628 | {list} must be a |List| with four or five numbers: |
| 9629 | [bufnum, lnum, col, off] |
| 9630 | [bufnum, lnum, col, off, curswant] |
| 9631 | |
| 9632 | "bufnum" is the buffer number. Zero can be used for the |
| 9633 | current buffer. When setting an uppercase mark "bufnum" is |
| 9634 | used for the mark position. For other marks it specifies the |
| 9635 | buffer to set the mark in. You can use the |bufnr()| function |
| 9636 | to turn a file name into a buffer number. |
| 9637 | For setting the cursor and the ' mark "bufnum" is ignored, |
| 9638 | since these are associated with a window, not a buffer. |
| 9639 | Does not change the jumplist. |
| 9640 | |
| 9641 | "lnum" and "col" are the position in the buffer. The first |
| 9642 | column is 1. Use a zero "lnum" to delete a mark. If "col" is |
| 9643 | smaller than 1 then 1 is used. To use the character count |
| 9644 | instead of the byte count, use |setcharpos()|. |
| 9645 | |
| 9646 | The "off" number is only used when 'virtualedit' is set. Then |
| 9647 | it is the offset in screen columns from the start of the |
| 9648 | character. E.g., a position within a <Tab> or after the last |
| 9649 | character. |
| 9650 | |
| 9651 | The "curswant" number is only used when setting the cursor |
| 9652 | position. It sets the preferred column for when moving the |
| 9653 | cursor vertically. When the "curswant" number is missing the |
| 9654 | preferred column is not set. When it is present and setting a |
| 9655 | mark position it is not used. |
| 9656 | |
| 9657 | Note that for '< and '> changing the line number may result in |
| 9658 | the marks to be effectively be swapped, so that '< is always |
| 9659 | before '>. |
| 9660 | |
| 9661 | Returns 0 when the position could be set, -1 otherwise. |
| 9662 | An error message is given if {expr} is invalid. |
| 9663 | |
| 9664 | Also see |setcharpos()|, |getpos()| and |getcurpos()|. |
| 9665 | |
| 9666 | This does not restore the preferred column for moving |
| 9667 | vertically; if you set the cursor position with this, |j| and |
| 9668 | |k| motions will jump to previous columns! Use |cursor()| to |
| 9669 | also set the preferred column. Also see the "curswant" key in |
| 9670 | |winrestview()|. |
| 9671 | |
| 9672 | Can also be used as a |method|: > |
| 9673 | GetPosition()->setpos('.') |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 9674 | < |
| 9675 | Return type: |Number| |
| 9676 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9677 | |
| 9678 | setqflist({list} [, {action} [, {what}]]) *setqflist()* |
| 9679 | Create or replace or add to the quickfix list. |
| 9680 | |
| 9681 | If the optional {what} dictionary argument is supplied, then |
| 9682 | only the items listed in {what} are set. The first {list} |
| 9683 | argument is ignored. See below for the supported items in |
| 9684 | {what}. |
| 9685 | *setqflist-what* |
| 9686 | When {what} is not present, the items in {list} are used. Each |
| 9687 | item must be a dictionary. Non-dictionary items in {list} are |
| 9688 | ignored. Each dictionary item can contain the following |
| 9689 | entries: |
| 9690 | |
| 9691 | bufnr buffer number; must be the number of a valid |
| 9692 | buffer |
| 9693 | filename name of a file; only used when "bufnr" is not |
| 9694 | present or it is invalid. |
| 9695 | module name of a module; if given it will be used in |
| 9696 | quickfix error window instead of the filename. |
| 9697 | lnum line number in the file |
Bram Moolenaar | a2baa73 | 2022-02-04 16:09:54 +0000 | [diff] [blame] | 9698 | end_lnum end of lines, if the item spans multiple lines |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9699 | pattern search pattern used to locate the error |
| 9700 | col column number |
| 9701 | vcol when non-zero: "col" is visual column |
| 9702 | when zero: "col" is byte index |
Bram Moolenaar | a2baa73 | 2022-02-04 16:09:54 +0000 | [diff] [blame] | 9703 | end_col end column, if the item spans multiple columns |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9704 | nr error number |
| 9705 | text description of the error |
| 9706 | type single-character error type, 'E', 'W', etc. |
| 9707 | valid recognized error message |
Tom Praschan | ca6ac99 | 2023-08-11 23:26:12 +0200 | [diff] [blame] | 9708 | user_data custom data associated with the item, can be |
| 9709 | any type. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9710 | |
| 9711 | The "col", "vcol", "nr", "type" and "text" entries are |
| 9712 | optional. Either "lnum" or "pattern" entry can be used to |
| 9713 | locate a matching error line. |
| 9714 | If the "filename" and "bufnr" entries are not present or |
| 9715 | neither the "lnum" or "pattern" entries are present, then the |
| 9716 | item will not be handled as an error line. |
| 9717 | If both "pattern" and "lnum" are present then "pattern" will |
| 9718 | be used. |
| 9719 | If the "valid" entry is not supplied, then the valid flag is |
| 9720 | set when "bufnr" is a valid buffer or "filename" exists. |
| 9721 | If you supply an empty {list}, the quickfix list will be |
| 9722 | cleared. |
| 9723 | Note that the list is not exactly the same as what |
| 9724 | |getqflist()| returns. |
| 9725 | |
| 9726 | {action} values: *setqflist-action* *E927* |
| 9727 | 'a' The items from {list} are added to the existing |
| 9728 | quickfix list. If there is no existing list, then a |
| 9729 | new list is created. |
| 9730 | |
| 9731 | 'r' The items from the current quickfix list are replaced |
| 9732 | with the items from {list}. This can also be used to |
| 9733 | clear the list: > |
| 9734 | :call setqflist([], 'r') |
| 9735 | < |
| 9736 | 'f' All the quickfix lists in the quickfix stack are |
| 9737 | freed. |
| 9738 | |
| 9739 | If {action} is not present or is set to ' ', then a new list |
| 9740 | is created. The new quickfix list is added after the current |
| 9741 | quickfix list in the stack and all the following lists are |
| 9742 | freed. To add a new quickfix list at the end of the stack, |
| 9743 | set "nr" in {what} to "$". |
| 9744 | |
| 9745 | The following items can be specified in dictionary {what}: |
| 9746 | context quickfix list context. See |quickfix-context| |
| 9747 | efm errorformat to use when parsing text from |
| 9748 | "lines". If this is not present, then the |
| 9749 | 'errorformat' option value is used. |
| 9750 | See |quickfix-parse| |
| 9751 | id quickfix list identifier |quickfix-ID| |
| 9752 | idx index of the current entry in the quickfix |
| 9753 | list specified by 'id' or 'nr'. If set to '$', |
| 9754 | then the last entry in the list is set as the |
| 9755 | current entry. See |quickfix-index| |
| 9756 | items list of quickfix entries. Same as the {list} |
| 9757 | argument. |
| 9758 | lines use 'errorformat' to parse a list of lines and |
| 9759 | add the resulting entries to the quickfix list |
| 9760 | {nr} or {id}. Only a |List| value is supported. |
| 9761 | See |quickfix-parse| |
| 9762 | nr list number in the quickfix stack; zero |
| 9763 | means the current quickfix list and "$" means |
| 9764 | the last quickfix list. |
| 9765 | quickfixtextfunc |
| 9766 | function to get the text to display in the |
| 9767 | quickfix window. The value can be the name of |
| 9768 | a function or a funcref or a lambda. Refer to |
| 9769 | |quickfix-window-function| for an explanation |
| 9770 | of how to write the function and an example. |
| 9771 | title quickfix list title text. See |quickfix-title| |
| 9772 | Unsupported keys in {what} are ignored. |
| 9773 | If the "nr" item is not present, then the current quickfix list |
| 9774 | is modified. When creating a new quickfix list, "nr" can be |
| 9775 | set to a value one greater than the quickfix stack size. |
| 9776 | When modifying a quickfix list, to guarantee that the correct |
| 9777 | list is modified, "id" should be used instead of "nr" to |
| 9778 | specify the list. |
| 9779 | |
| 9780 | Examples (See also |setqflist-examples|): > |
| 9781 | :call setqflist([], 'r', {'title': 'My search'}) |
| 9782 | :call setqflist([], 'r', {'nr': 2, 'title': 'Errors'}) |
| 9783 | :call setqflist([], 'a', {'id':qfid, 'lines':["F1:10:L10"]}) |
| 9784 | < |
| 9785 | Returns zero for success, -1 for failure. |
| 9786 | |
| 9787 | This function can be used to create a quickfix list |
| 9788 | independent of the 'errorformat' setting. Use a command like |
| 9789 | `:cc 1` to jump to the first position. |
| 9790 | |
| 9791 | Can also be used as a |method|, the base is passed as the |
| 9792 | second argument: > |
| 9793 | GetErrorlist()->setqflist() |
| 9794 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 9795 | Return type: |Number| |
| 9796 | |
| 9797 | |
| 9798 | setreg({regname}, {value} [, {options}]) *setreg()* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9799 | Set the register {regname} to {value}. |
| 9800 | If {regname} is "" or "@", the unnamed register '"' is used. |
| 9801 | The {regname} argument is a string. In |Vim9-script| |
| 9802 | {regname} must be one character. |
| 9803 | |
| 9804 | {value} may be any value returned by |getreg()| or |
| 9805 | |getreginfo()|, including a |List| or |Dict|. |
| 9806 | If {options} contains "a" or {regname} is upper case, |
| 9807 | then the value is appended. |
| 9808 | |
| 9809 | {options} can also contain a register type specification: |
| 9810 | "c" or "v" |characterwise| mode |
| 9811 | "l" or "V" |linewise| mode |
| 9812 | "b" or "<CTRL-V>" |blockwise-visual| mode |
| 9813 | If a number immediately follows "b" or "<CTRL-V>" then this is |
| 9814 | used as the width of the selection - if it is not specified |
| 9815 | then the width of the block is set to the number of characters |
| 9816 | in the longest line (counting a <Tab> as 1 character). |
| 9817 | |
| 9818 | If {options} contains no register settings, then the default |
| 9819 | is to use character mode unless {value} ends in a <NL> for |
| 9820 | string {value} and linewise mode for list {value}. Blockwise |
| 9821 | mode is never selected automatically. |
| 9822 | Returns zero for success, non-zero for failure. |
| 9823 | |
| 9824 | *E883* |
| 9825 | Note: you may not use |List| containing more than one item to |
| 9826 | set search and expression registers. Lists containing no |
| 9827 | items act like empty strings. |
| 9828 | |
| 9829 | Examples: > |
| 9830 | :call setreg(v:register, @*) |
| 9831 | :call setreg('*', @%, 'ac') |
| 9832 | :call setreg('a', "1\n2\n3", 'b5') |
| 9833 | :call setreg('"', { 'points_to': 'a'}) |
| 9834 | |
| 9835 | < This example shows using the functions to save and restore a |
| 9836 | register: > |
| 9837 | :let var_a = getreginfo() |
| 9838 | :call setreg('a', var_a) |
| 9839 | < or: > |
| 9840 | :let var_a = getreg('a', 1, 1) |
| 9841 | :let var_amode = getregtype('a') |
| 9842 | .... |
| 9843 | :call setreg('a', var_a, var_amode) |
| 9844 | < Note: you may not reliably restore register value |
| 9845 | without using the third argument to |getreg()| as without it |
| 9846 | newlines are represented as newlines AND Nul bytes are |
| 9847 | represented as newlines as well, see |NL-used-for-Nul|. |
| 9848 | |
| 9849 | You can also change the type of a register by appending |
| 9850 | nothing: > |
| 9851 | :call setreg('a', '', 'al') |
| 9852 | |
| 9853 | < Can also be used as a |method|, the base is passed as the |
| 9854 | second argument: > |
| 9855 | GetText()->setreg('a') |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 9856 | < |
| 9857 | Return type: |Number| |
| 9858 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9859 | |
| 9860 | settabvar({tabnr}, {varname}, {val}) *settabvar()* |
| 9861 | Set tab-local variable {varname} to {val} in tab page {tabnr}. |
| 9862 | |t:var| |
| 9863 | The {varname} argument is a string. |
| 9864 | Note that autocommands are blocked, side effects may not be |
| 9865 | triggered, e.g. when setting 'filetype'. |
| 9866 | Note that the variable name without "t:" must be used. |
| 9867 | Tabs are numbered starting with one. |
| 9868 | This function is not available in the |sandbox|. |
| 9869 | |
| 9870 | Can also be used as a |method|, the base is passed as the |
| 9871 | third argument: > |
| 9872 | GetValue()->settabvar(tab, name) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 9873 | < |
| 9874 | Return type: |Number| |
| 9875 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9876 | |
| 9877 | settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()* |
| 9878 | Set option or local variable {varname} in window {winnr} to |
| 9879 | {val}. |
| 9880 | Tabs are numbered starting with one. For the current tabpage |
| 9881 | use |setwinvar()|. |
| 9882 | {winnr} can be the window number or the |window-ID|. |
| 9883 | When {winnr} is zero the current window is used. |
| 9884 | Note that autocommands are blocked, side effects may not be |
| 9885 | triggered, e.g. when setting 'filetype' or 'syntax'. |
| 9886 | This also works for a global or local buffer option, but it |
| 9887 | doesn't work for a global or local buffer variable. |
| 9888 | For a local buffer option the global value is unchanged. |
| 9889 | Note that the variable name without "w:" must be used. |
| 9890 | Examples: > |
| 9891 | :call settabwinvar(1, 1, "&list", 0) |
| 9892 | :call settabwinvar(3, 2, "myvar", "foobar") |
| 9893 | < This function is not available in the |sandbox|. |
| 9894 | |
| 9895 | Can also be used as a |method|, the base is passed as the |
| 9896 | fourth argument: > |
| 9897 | GetValue()->settabwinvar(tab, winnr, name) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 9898 | < |
| 9899 | Return type: |Number| |
| 9900 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9901 | |
| 9902 | settagstack({nr}, {dict} [, {action}]) *settagstack()* |
| 9903 | Modify the tag stack of the window {nr} using {dict}. |
| 9904 | {nr} can be the window number or the |window-ID|. |
| 9905 | |
| 9906 | For a list of supported items in {dict}, refer to |
| 9907 | |gettagstack()|. "curidx" takes effect before changing the tag |
| 9908 | stack. |
| 9909 | *E962* |
| 9910 | How the tag stack is modified depends on the {action} |
| 9911 | argument: |
| 9912 | - If {action} is not present or is set to 'r', then the tag |
| 9913 | stack is replaced. |
| 9914 | - If {action} is set to 'a', then new entries from {dict} are |
| 9915 | pushed (added) onto the tag stack. |
| 9916 | - If {action} is set to 't', then all the entries from the |
| 9917 | current entry in the tag stack or "curidx" in {dict} are |
| 9918 | removed and then new entries are pushed to the stack. |
| 9919 | |
| 9920 | The current index is set to one after the length of the tag |
| 9921 | stack after the modification. |
| 9922 | |
| 9923 | Returns zero for success, -1 for failure. |
| 9924 | |
| 9925 | Examples (for more examples see |tagstack-examples|): |
| 9926 | Empty the tag stack of window 3: > |
| 9927 | call settagstack(3, {'items' : []}) |
| 9928 | |
| 9929 | < Save and restore the tag stack: > |
| 9930 | let stack = gettagstack(1003) |
| 9931 | " do something else |
| 9932 | call settagstack(1003, stack) |
| 9933 | unlet stack |
| 9934 | < |
| 9935 | Can also be used as a |method|, the base is passed as the |
| 9936 | second argument: > |
| 9937 | GetStack()->settagstack(winnr) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 9938 | < |
| 9939 | Return type: |Number| |
| 9940 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9941 | |
| 9942 | setwinvar({winnr}, {varname}, {val}) *setwinvar()* |
| 9943 | Like |settabwinvar()| for the current tab page. |
| 9944 | Examples: > |
| 9945 | :call setwinvar(1, "&list", 0) |
| 9946 | :call setwinvar(2, "myvar", "foobar") |
| 9947 | |
| 9948 | < Can also be used as a |method|, the base is passed as the |
| 9949 | third argument: > |
| 9950 | GetValue()->setwinvar(winnr, name) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 9951 | < |
| 9952 | Return type: |Number| |
| 9953 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9954 | |
| 9955 | sha256({string}) *sha256()* |
| 9956 | Returns a String with 64 hex characters, which is the SHA256 |
| 9957 | checksum of {string}. |
| 9958 | |
| 9959 | Can also be used as a |method|: > |
| 9960 | GetText()->sha256() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 9961 | < |
| 9962 | Return type: |String| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9963 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 9964 | {only available when compiled with the |+cryptv| feature} |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9965 | |
| 9966 | shellescape({string} [, {special}]) *shellescape()* |
| 9967 | Escape {string} for use as a shell command argument. |
| 9968 | When the 'shell' contains powershell (MS-Windows) or pwsh |
Bram Moolenaar | 944697a | 2022-02-20 19:48:20 +0000 | [diff] [blame] | 9969 | (MS-Windows, Linux, and macOS) then it will enclose {string} |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9970 | in single quotes and will double up all internal single |
| 9971 | quotes. |
| 9972 | On MS-Windows, when 'shellslash' is not set, it will enclose |
| 9973 | {string} in double quotes and double all double quotes within |
| 9974 | {string}. |
| 9975 | Otherwise it will enclose {string} in single quotes and |
| 9976 | replace all "'" with "'\''". |
| 9977 | |
Enno | 5faeb60 | 2024-05-15 21:54:19 +0200 | [diff] [blame] | 9978 | The {special} argument adds additional escaping of keywords |
| 9979 | used in Vim commands. When it is not omitted and a non-zero |
K.Takata | c0e038b | 2024-05-16 12:39:01 +0900 | [diff] [blame] | 9980 | number or a non-empty String (|non-zero-arg|), then special |
| 9981 | items such as "!", "%", "#" and "<cword>" (as listed in |
| 9982 | |expand()|) will be preceded by a backslash. |
Enno | 5faeb60 | 2024-05-15 21:54:19 +0200 | [diff] [blame] | 9983 | This backslash will be removed again by the |:!| command. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 9984 | |
| 9985 | The "!" character will be escaped (again with a |non-zero-arg| |
| 9986 | {special}) when 'shell' contains "csh" in the tail. That is |
| 9987 | because for csh and tcsh "!" is used for history replacement |
| 9988 | even when inside single quotes. |
| 9989 | |
| 9990 | With a |non-zero-arg| {special} the <NL> character is also |
| 9991 | escaped. When 'shell' containing "csh" in the tail it's |
| 9992 | escaped a second time. |
| 9993 | |
| 9994 | The "\" character will be escaped when 'shell' contains "fish" |
| 9995 | in the tail. That is because for fish "\" is used as an escape |
| 9996 | character inside single quotes. |
| 9997 | |
| 9998 | Example of use with a |:!| command: > |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 9999 | :exe '!dir ' .. shellescape(expand('<cfile>'), 1) |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10000 | < This results in a directory listing for the file under the |
| 10001 | cursor. Example of use with |system()|: > |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 10002 | :call system("chmod +w -- " .. shellescape(expand("%"))) |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10003 | < See also |::S|. |
| 10004 | |
| 10005 | Can also be used as a |method|: > |
| 10006 | GetCommand()->shellescape() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 10007 | < |
| 10008 | Return type: |String| |
| 10009 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10010 | |
| 10011 | shiftwidth([{col}]) *shiftwidth()* |
| 10012 | Returns the effective value of 'shiftwidth'. This is the |
| 10013 | 'shiftwidth' value unless it is zero, in which case it is the |
| 10014 | 'tabstop' value. This function was introduced with patch |
| 10015 | 7.3.694 in 2012, everybody should have it by now (however it |
| 10016 | did not allow for the optional {col} argument until 8.1.542). |
| 10017 | |
| 10018 | When there is one argument {col} this is used as column number |
| 10019 | for which to return the 'shiftwidth' value. This matters for the |
| 10020 | 'vartabstop' feature. If the 'vartabstop' setting is enabled and |
| 10021 | no {col} argument is given, column 1 will be assumed. |
| 10022 | |
| 10023 | Can also be used as a |method|: > |
| 10024 | GetColumn()->shiftwidth() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 10025 | < |
| 10026 | Return type: |Number| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10027 | |
| 10028 | sign_ functions are documented here: |sign-functions-details| |
| 10029 | |
| 10030 | |
| 10031 | simplify({filename}) *simplify()* |
| 10032 | Simplify the file name as much as possible without changing |
| 10033 | the meaning. Shortcuts (on MS-Windows) or symbolic links (on |
| 10034 | Unix) are not resolved. If the first path component in |
| 10035 | {filename} designates the current directory, this will be |
| 10036 | valid for the result as well. A trailing path separator is |
| 10037 | not removed either. On Unix "//path" is unchanged, but |
| 10038 | "///path" is simplified to "/path" (this follows the Posix |
| 10039 | standard). |
| 10040 | Example: > |
| 10041 | simplify("./dir/.././/file/") == "./file/" |
| 10042 | < Note: The combination "dir/.." is only removed if "dir" is |
| 10043 | a searchable directory or does not exist. On Unix, it is also |
| 10044 | removed when "dir" is a symbolic link within the same |
| 10045 | directory. In order to resolve all the involved symbolic |
| 10046 | links before simplifying the path name, use |resolve()|. |
| 10047 | |
| 10048 | Can also be used as a |method|: > |
| 10049 | GetName()->simplify() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 10050 | < |
| 10051 | Return type: |String| |
| 10052 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10053 | |
| 10054 | sin({expr}) *sin()* |
| 10055 | Return the sine of {expr}, measured in radians, as a |Float|. |
| 10056 | {expr} must evaluate to a |Float| or a |Number|. |
Bram Moolenaar | 6ba83ba | 2022-06-12 22:15:57 +0100 | [diff] [blame] | 10057 | Returns 0.0 if {expr} is not a |Float| or a |Number|. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10058 | Examples: > |
| 10059 | :echo sin(100) |
| 10060 | < -0.506366 > |
| 10061 | :echo sin(-4.01) |
| 10062 | < 0.763301 |
| 10063 | |
| 10064 | Can also be used as a |method|: > |
| 10065 | Compute()->sin() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 10066 | < |
| 10067 | Return type: |Float| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10068 | |
| 10069 | |
| 10070 | sinh({expr}) *sinh()* |
| 10071 | Return the hyperbolic sine of {expr} as a |Float| in the range |
| 10072 | [-inf, inf]. |
| 10073 | {expr} must evaluate to a |Float| or a |Number|. |
Bram Moolenaar | 6ba83ba | 2022-06-12 22:15:57 +0100 | [diff] [blame] | 10074 | Returns 0.0 if {expr} is not a |Float| or a |Number|. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10075 | Examples: > |
| 10076 | :echo sinh(0.5) |
| 10077 | < 0.521095 > |
| 10078 | :echo sinh(-0.9) |
| 10079 | < -1.026517 |
| 10080 | |
| 10081 | Can also be used as a |method|: > |
| 10082 | Compute()->sinh() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 10083 | < |
| 10084 | Return type: |Float| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10085 | |
| 10086 | |
| 10087 | slice({expr}, {start} [, {end}]) *slice()* |
| 10088 | Similar to using a |slice| "expr[start : end]", but "end" is |
| 10089 | used exclusive. And for a string the indexes are used as |
| 10090 | character indexes instead of byte indexes, like in |
zeertzjq | ad38769 | 2024-03-23 08:23:48 +0100 | [diff] [blame] | 10091 | |vim9script|. Also, composing characters are treated as a |
| 10092 | part of the preceding base character. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10093 | When {end} is omitted the slice continues to the last item. |
| 10094 | When {end} is -1 the last item is omitted. |
Bram Moolenaar | 6ba83ba | 2022-06-12 22:15:57 +0100 | [diff] [blame] | 10095 | Returns an empty value if {start} or {end} are invalid. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10096 | |
| 10097 | Can also be used as a |method|: > |
| 10098 | GetList()->slice(offset) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 10099 | < |
| 10100 | Return type: list<{type}> |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10101 | |
| 10102 | |
Bram Moolenaar | 2007dd4 | 2022-02-23 13:17:47 +0000 | [diff] [blame] | 10103 | sort({list} [, {how} [, {dict}]]) *sort()* *E702* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10104 | Sort the items in {list} in-place. Returns {list}. |
| 10105 | |
| 10106 | If you want a list to remain unmodified make a copy first: > |
| 10107 | :let sortedlist = sort(copy(mylist)) |
| 10108 | |
Bram Moolenaar | 2d8ed02 | 2022-05-21 13:08:16 +0100 | [diff] [blame] | 10109 | < When {how} is omitted or is a string, then sort() uses the |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10110 | string representation of each item to sort on. Numbers sort |
| 10111 | after Strings, |Lists| after Numbers. For sorting text in the |
| 10112 | current buffer use |:sort|. |
| 10113 | |
Bram Moolenaar | 2007dd4 | 2022-02-23 13:17:47 +0000 | [diff] [blame] | 10114 | When {how} is given and it is 'i' then case is ignored. |
| 10115 | In legacy script, for backwards compatibility, the value one |
| 10116 | can be used to ignore case. Zero means to not ignore case. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10117 | |
Bram Moolenaar | 2007dd4 | 2022-02-23 13:17:47 +0000 | [diff] [blame] | 10118 | When {how} is given and it is 'l' then the current collation |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10119 | locale is used for ordering. Implementation details: strcoll() |
| 10120 | is used to compare strings. See |:language| check or set the |
| 10121 | collation locale. |v:collate| can also be used to check the |
| 10122 | current locale. Sorting using the locale typically ignores |
| 10123 | case. Example: > |
| 10124 | " ö is sorted similarly to o with English locale. |
| 10125 | :language collate en_US.UTF8 |
| 10126 | :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l') |
| 10127 | < ['n', 'o', 'O', 'ö', 'p', 'z'] ~ |
| 10128 | > |
| 10129 | " ö is sorted after z with Swedish locale. |
| 10130 | :language collate sv_SE.UTF8 |
| 10131 | :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l') |
| 10132 | < ['n', 'o', 'O', 'p', 'z', 'ö'] ~ |
| 10133 | This does not work properly on Mac. |
| 10134 | |
Bram Moolenaar | 2007dd4 | 2022-02-23 13:17:47 +0000 | [diff] [blame] | 10135 | When {how} is given and it is 'n' then all items will be |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10136 | sorted numerical (Implementation detail: this uses the |
Bram Moolenaar | be19d78 | 2023-03-09 22:06:49 +0000 | [diff] [blame] | 10137 | strtod() function to parse numbers. Strings, Lists, Dicts and |
| 10138 | Funcrefs will be considered as being 0). Note that this won't |
| 10139 | sort a list of strings with numbers! |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10140 | |
Bram Moolenaar | 2007dd4 | 2022-02-23 13:17:47 +0000 | [diff] [blame] | 10141 | When {how} is given and it is 'N' then all items will be |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10142 | sorted numerical. This is like 'n' but a string containing |
| 10143 | digits will be used as the number they represent. |
| 10144 | |
Bram Moolenaar | 2007dd4 | 2022-02-23 13:17:47 +0000 | [diff] [blame] | 10145 | When {how} is given and it is 'f' then all items will be |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10146 | sorted numerical. All values must be a Number or a Float. |
| 10147 | |
Bram Moolenaar | 2007dd4 | 2022-02-23 13:17:47 +0000 | [diff] [blame] | 10148 | When {how} is a |Funcref| or a function name, this function |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10149 | is called to compare items. The function is invoked with two |
| 10150 | items as argument and must return zero if they are equal, 1 or |
| 10151 | bigger if the first one sorts after the second one, -1 or |
| 10152 | smaller if the first one sorts before the second one. |
| 10153 | |
| 10154 | {dict} is for functions with the "dict" attribute. It will be |
| 10155 | used to set the local variable "self". |Dictionary-function| |
| 10156 | |
| 10157 | The sort is stable, items which compare equal (as number or as |
| 10158 | string) will keep their relative position. E.g., when sorting |
| 10159 | on numbers, text strings will sort next to each other, in the |
| 10160 | same order as they were originally. |
| 10161 | |
| 10162 | Can also be used as a |method|: > |
| 10163 | mylist->sort() |
| 10164 | |
| 10165 | < Also see |uniq()|. |
| 10166 | |
| 10167 | Example: > |
| 10168 | func MyCompare(i1, i2) |
| 10169 | return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1 |
| 10170 | endfunc |
| 10171 | eval mylist->sort("MyCompare") |
| 10172 | < A shorter compare version for this specific simple case, which |
| 10173 | ignores overflow: > |
| 10174 | func MyCompare(i1, i2) |
| 10175 | return a:i1 - a:i2 |
| 10176 | endfunc |
| 10177 | < For a simple expression you can use a lambda: > |
| 10178 | eval mylist->sort({i1, i2 -> i1 - i2}) |
| 10179 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 10180 | Return type: list<{type}> |
| 10181 | |
| 10182 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10183 | sound_clear() *sound_clear()* |
| 10184 | Stop playing all sounds. |
| 10185 | |
| 10186 | On some Linux systems you may need the libcanberra-pulse |
| 10187 | package, otherwise sound may not stop. |
| 10188 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 10189 | Return type: |Number| |
| 10190 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10191 | {only available when compiled with the |+sound| feature} |
| 10192 | |
| 10193 | *sound_playevent()* |
| 10194 | sound_playevent({name} [, {callback}]) |
| 10195 | Play a sound identified by {name}. Which event names are |
| 10196 | supported depends on the system. Often the XDG sound names |
| 10197 | are used. On Ubuntu they may be found in |
| 10198 | /usr/share/sounds/freedesktop/stereo. Example: > |
| 10199 | call sound_playevent('bell') |
| 10200 | < On MS-Windows, {name} can be SystemAsterisk, SystemDefault, |
| 10201 | SystemExclamation, SystemExit, SystemHand, SystemQuestion, |
| 10202 | SystemStart, SystemWelcome, etc. |
Yee Cheng Chin | 4314e4f | 2022-10-08 13:50:05 +0100 | [diff] [blame] | 10203 | On macOS, {name} refers to files located in |
| 10204 | /System/Library/Sounds (e.g. "Tink"). It will also work for |
| 10205 | custom installed sounds in folders like ~/Library/Sounds. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10206 | |
| 10207 | When {callback} is specified it is invoked when the sound is |
| 10208 | finished. The first argument is the sound ID, the second |
| 10209 | argument is the status: |
| 10210 | 0 sound was played to the end |
| 10211 | 1 sound was interrupted |
| 10212 | 2 error occurred after sound started |
| 10213 | Example: > |
| 10214 | func Callback(id, status) |
| 10215 | echomsg "sound " .. a:id .. " finished with " .. a:status |
| 10216 | endfunc |
| 10217 | call sound_playevent('bell', 'Callback') |
| 10218 | |
| 10219 | < MS-Windows: {callback} doesn't work for this function. |
| 10220 | |
| 10221 | Returns the sound ID, which can be passed to `sound_stop()`. |
| 10222 | Returns zero if the sound could not be played. |
| 10223 | |
| 10224 | Can also be used as a |method|: > |
| 10225 | GetSoundName()->sound_playevent() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 10226 | < |
| 10227 | Return type: |Number| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10228 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 10229 | {only available when compiled with the |+sound| feature} |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10230 | |
| 10231 | *sound_playfile()* |
| 10232 | sound_playfile({path} [, {callback}]) |
| 10233 | Like `sound_playevent()` but play sound file {path}. {path} |
| 10234 | must be a full path. On Ubuntu you may find files to play |
| 10235 | with this command: > |
| 10236 | :!find /usr/share/sounds -type f | grep -v index.theme |
| 10237 | |
| 10238 | < Can also be used as a |method|: > |
| 10239 | GetSoundPath()->sound_playfile() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 10240 | < |
| 10241 | Return type: |Number| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10242 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 10243 | {only available when compiled with the |+sound| feature} |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10244 | |
| 10245 | |
| 10246 | sound_stop({id}) *sound_stop()* |
| 10247 | Stop playing sound {id}. {id} must be previously returned by |
| 10248 | `sound_playevent()` or `sound_playfile()`. |
| 10249 | |
| 10250 | On some Linux systems you may need the libcanberra-pulse |
| 10251 | package, otherwise sound may not stop. |
| 10252 | |
| 10253 | On MS-Windows, this does not work for event sound started by |
| 10254 | `sound_playevent()`. To stop event sounds, use `sound_clear()`. |
| 10255 | |
| 10256 | Can also be used as a |method|: > |
| 10257 | soundid->sound_stop() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 10258 | < |
| 10259 | Return type: |Number| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10260 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 10261 | {only available when compiled with the |+sound| feature} |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10262 | |
| 10263 | *soundfold()* |
| 10264 | soundfold({word}) |
| 10265 | Return the sound-folded equivalent of {word}. Uses the first |
| 10266 | language in 'spelllang' for the current window that supports |
| 10267 | soundfolding. 'spell' must be set. When no sound folding is |
| 10268 | possible the {word} is returned unmodified. |
| 10269 | This can be used for making spelling suggestions. Note that |
| 10270 | the method can be quite slow. |
| 10271 | |
| 10272 | Can also be used as a |method|: > |
| 10273 | GetWord()->soundfold() |
| 10274 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 10275 | Return type: |String| |
| 10276 | |
| 10277 | |
| 10278 | spellbadword([{sentence}]) *spellbadword()* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10279 | Without argument: The result is the badly spelled word under |
| 10280 | or after the cursor. The cursor is moved to the start of the |
| 10281 | bad word. When no bad word is found in the cursor line the |
| 10282 | result is an empty string and the cursor doesn't move. |
| 10283 | |
| 10284 | With argument: The result is the first word in {sentence} that |
| 10285 | is badly spelled. If there are no spelling mistakes the |
| 10286 | result is an empty string. |
| 10287 | |
| 10288 | The return value is a list with two items: |
| 10289 | - The badly spelled word or an empty string. |
| 10290 | - The type of the spelling error: |
| 10291 | "bad" spelling mistake |
| 10292 | "rare" rare word |
| 10293 | "local" word only valid in another region |
| 10294 | "caps" word should start with Capital |
| 10295 | Example: > |
| 10296 | echo spellbadword("the quik brown fox") |
| 10297 | < ['quik', 'bad'] ~ |
| 10298 | |
| 10299 | The spelling information for the current window and the value |
| 10300 | of 'spelllang' are used. |
| 10301 | |
| 10302 | Can also be used as a |method|: > |
| 10303 | GetText()->spellbadword() |
| 10304 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 10305 | Return type: list<string> |
| 10306 | |
| 10307 | |
| 10308 | spellsuggest({word} [, {max} [, {capital}]]) *spellsuggest()* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10309 | Return a |List| with spelling suggestions to replace {word}. |
| 10310 | When {max} is given up to this number of suggestions are |
| 10311 | returned. Otherwise up to 25 suggestions are returned. |
| 10312 | |
| 10313 | When the {capital} argument is given and it's non-zero only |
| 10314 | suggestions with a leading capital will be given. Use this |
| 10315 | after a match with 'spellcapcheck'. |
| 10316 | |
| 10317 | {word} can be a badly spelled word followed by other text. |
| 10318 | This allows for joining two words that were split. The |
| 10319 | suggestions also include the following text, thus you can |
| 10320 | replace a line. |
| 10321 | |
| 10322 | {word} may also be a good word. Similar words will then be |
| 10323 | returned. {word} itself is not included in the suggestions, |
| 10324 | although it may appear capitalized. |
| 10325 | |
| 10326 | The spelling information for the current window is used. The |
| 10327 | values of 'spelllang' and 'spellsuggest' are used. |
| 10328 | |
| 10329 | Can also be used as a |method|: > |
| 10330 | GetWord()->spellsuggest() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 10331 | < |
| 10332 | Return type: list<string> or list<any> |
| 10333 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10334 | |
| 10335 | split({string} [, {pattern} [, {keepempty}]]) *split()* |
| 10336 | Make a |List| out of {string}. When {pattern} is omitted or |
| 10337 | empty each white-separated sequence of characters becomes an |
| 10338 | item. |
| 10339 | Otherwise the string is split where {pattern} matches, |
| 10340 | removing the matched characters. 'ignorecase' is not used |
| 10341 | here, add \c to ignore case. |/\c| |
| 10342 | When the first or last item is empty it is omitted, unless the |
| 10343 | {keepempty} argument is given and it's non-zero. |
| 10344 | Other empty items are kept when {pattern} matches at least one |
| 10345 | character or when {keepempty} is non-zero. |
| 10346 | Example: > |
| 10347 | :let words = split(getline('.'), '\W\+') |
| 10348 | < To split a string in individual characters: > |
| 10349 | :for c in split(mystring, '\zs') |
| 10350 | < If you want to keep the separator you can also use '\zs' at |
| 10351 | the end of the pattern: > |
| 10352 | :echo split('abc:def:ghi', ':\zs') |
| 10353 | < ['abc:', 'def:', 'ghi'] ~ |
| 10354 | Splitting a table where the first element can be empty: > |
| 10355 | :let items = split(line, ':', 1) |
| 10356 | < The opposite function is |join()|. |
| 10357 | |
| 10358 | Can also be used as a |method|: > |
| 10359 | GetString()->split() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 10360 | < |
| 10361 | Return type: list<string> |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10362 | |
| 10363 | sqrt({expr}) *sqrt()* |
| 10364 | Return the non-negative square root of Float {expr} as a |
| 10365 | |Float|. |
| 10366 | {expr} must evaluate to a |Float| or a |Number|. When {expr} |
Bram Moolenaar | 6ba83ba | 2022-06-12 22:15:57 +0100 | [diff] [blame] | 10367 | is negative the result is NaN (Not a Number). Returns 0.0 if |
| 10368 | {expr} is not a |Float| or a |Number|. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10369 | Examples: > |
| 10370 | :echo sqrt(100) |
| 10371 | < 10.0 > |
| 10372 | :echo sqrt(-4.01) |
| 10373 | < nan |
| 10374 | "nan" may be different, it depends on system libraries. |
| 10375 | |
| 10376 | Can also be used as a |method|: > |
| 10377 | Compute()->sqrt() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 10378 | < |
| 10379 | Return type: |Float| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10380 | |
| 10381 | |
| 10382 | srand([{expr}]) *srand()* |
| 10383 | Initialize seed used by |rand()|: |
| 10384 | - If {expr} is not given, seed values are initialized by |
| 10385 | reading from /dev/urandom, if possible, or using time(NULL) |
| 10386 | a.k.a. epoch time otherwise; this only has second accuracy. |
| 10387 | - If {expr} is given it must be a Number. It is used to |
| 10388 | initialize the seed values. This is useful for testing or |
| 10389 | when a predictable sequence is intended. |
| 10390 | |
| 10391 | Examples: > |
| 10392 | :let seed = srand() |
| 10393 | :let seed = srand(userinput) |
| 10394 | :echo rand(seed) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 10395 | < |
| 10396 | Return type: list<number> |
| 10397 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10398 | |
| 10399 | state([{what}]) *state()* |
| 10400 | Return a string which contains characters indicating the |
| 10401 | current state. Mostly useful in callbacks that want to do |
| 10402 | work that may not always be safe. Roughly this works like: |
| 10403 | - callback uses state() to check if work is safe to do. |
| 10404 | Yes: then do it right away. |
| 10405 | No: add to work queue and add a |SafeState| and/or |
| 10406 | |SafeStateAgain| autocommand (|SafeState| triggers at |
| 10407 | toplevel, |SafeStateAgain| triggers after handling |
| 10408 | messages and callbacks). |
| 10409 | - When SafeState or SafeStateAgain is triggered and executes |
| 10410 | your autocommand, check with `state()` if the work can be |
| 10411 | done now, and if yes remove it from the queue and execute. |
| 10412 | Remove the autocommand if the queue is now empty. |
| 10413 | Also see |mode()|. |
| 10414 | |
| 10415 | When {what} is given only characters in this string will be |
| 10416 | added. E.g, this checks if the screen has scrolled: > |
| 10417 | if state('s') == '' |
| 10418 | " screen has not scrolled |
| 10419 | < |
| 10420 | These characters indicate the state, generally indicating that |
| 10421 | something is busy: |
| 10422 | m halfway a mapping, :normal command, feedkeys() or |
| 10423 | stuffed command |
| 10424 | o operator pending, e.g. after |d| |
| 10425 | a Insert mode autocomplete active |
| 10426 | x executing an autocommand |
| 10427 | w blocked on waiting, e.g. ch_evalexpr(), ch_read() and |
| 10428 | ch_readraw() when reading json |
| 10429 | S not triggering SafeState or SafeStateAgain, e.g. after |
| 10430 | |f| or a count |
| 10431 | c callback invoked, including timer (repeats for |
| 10432 | recursiveness up to "ccc") |
| 10433 | s screen has scrolled for messages |
| 10434 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 10435 | Return type: |String| |
| 10436 | |
| 10437 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10438 | str2float({string} [, {quoted}]) *str2float()* |
| 10439 | Convert String {string} to a Float. This mostly works the |
| 10440 | same as when using a floating point number in an expression, |
| 10441 | see |floating-point-format|. But it's a bit more permissive. |
| 10442 | E.g., "1e40" is accepted, while in an expression you need to |
| 10443 | write "1.0e40". The hexadecimal form "0x123" is also |
| 10444 | accepted, but not others, like binary or octal. |
| 10445 | When {quoted} is present and non-zero then embedded single |
| 10446 | quotes before the dot are ignored, thus "1'000.0" is a |
| 10447 | thousand. |
| 10448 | Text after the number is silently ignored. |
| 10449 | The decimal point is always '.', no matter what the locale is |
| 10450 | set to. A comma ends the number: "12,345.67" is converted to |
| 10451 | 12.0. You can strip out thousands separators with |
| 10452 | |substitute()|: > |
| 10453 | let f = str2float(substitute(text, ',', '', 'g')) |
| 10454 | < |
Bram Moolenaar | 6ba83ba | 2022-06-12 22:15:57 +0100 | [diff] [blame] | 10455 | Returns 0.0 if the conversion fails. |
| 10456 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10457 | Can also be used as a |method|: > |
| 10458 | let f = text->substitute(',', '', 'g')->str2float() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 10459 | < |
| 10460 | Return type: |Float| |
| 10461 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10462 | |
| 10463 | str2list({string} [, {utf8}]) *str2list()* |
| 10464 | Return a list containing the number values which represent |
| 10465 | each character in String {string}. Examples: > |
| 10466 | str2list(" ") returns [32] |
| 10467 | str2list("ABC") returns [65, 66, 67] |
| 10468 | < |list2str()| does the opposite. |
| 10469 | |
| 10470 | When {utf8} is omitted or zero, the current 'encoding' is used. |
| 10471 | When {utf8} is TRUE, always treat the String as UTF-8 |
| 10472 | characters. With UTF-8 composing characters are handled |
| 10473 | properly: > |
| 10474 | str2list("á") returns [97, 769] |
| 10475 | |
| 10476 | < Can also be used as a |method|: > |
| 10477 | GetString()->str2list() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 10478 | < |
| 10479 | Return type: list<number> |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10480 | |
| 10481 | |
| 10482 | str2nr({string} [, {base} [, {quoted}]]) *str2nr()* |
| 10483 | Convert string {string} to a number. |
| 10484 | {base} is the conversion base, it can be 2, 8, 10 or 16. |
| 10485 | When {quoted} is present and non-zero then embedded single |
| 10486 | quotes are ignored, thus "1'000'000" is a million. |
| 10487 | |
| 10488 | When {base} is omitted base 10 is used. This also means that |
| 10489 | a leading zero doesn't cause octal conversion to be used, as |
| 10490 | with the default String to Number conversion. Example: > |
| 10491 | let nr = str2nr('0123') |
| 10492 | < |
| 10493 | When {base} is 16 a leading "0x" or "0X" is ignored. With a |
| 10494 | different base the result will be zero. Similarly, when |
| 10495 | {base} is 8 a leading "0", "0o" or "0O" is ignored, and when |
| 10496 | {base} is 2 a leading "0b" or "0B" is ignored. |
| 10497 | Text after the number is silently ignored. |
| 10498 | |
Bram Moolenaar | 6ba83ba | 2022-06-12 22:15:57 +0100 | [diff] [blame] | 10499 | Returns 0 if {string} is empty or on error. |
| 10500 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10501 | Can also be used as a |method|: > |
| 10502 | GetText()->str2nr() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 10503 | < |
| 10504 | Return type: |Number| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10505 | |
| 10506 | |
| 10507 | strcharlen({string}) *strcharlen()* |
| 10508 | The result is a Number, which is the number of characters |
| 10509 | in String {string}. Composing characters are ignored. |
| 10510 | |strchars()| can count the number of characters, counting |
| 10511 | composing characters separately. |
| 10512 | |
Bram Moolenaar | 6ba83ba | 2022-06-12 22:15:57 +0100 | [diff] [blame] | 10513 | Returns 0 if {string} is empty or on error. |
| 10514 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10515 | Also see |strlen()|, |strdisplaywidth()| and |strwidth()|. |
| 10516 | |
| 10517 | Can also be used as a |method|: > |
| 10518 | GetText()->strcharlen() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 10519 | < |
| 10520 | Return type: |Number| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10521 | |
| 10522 | |
| 10523 | strcharpart({src}, {start} [, {len} [, {skipcc}]]) *strcharpart()* |
| 10524 | Like |strpart()| but using character index and length instead |
| 10525 | of byte index and length. |
| 10526 | When {skipcc} is omitted or zero, composing characters are |
| 10527 | counted separately. |
zeertzjq | ad38769 | 2024-03-23 08:23:48 +0100 | [diff] [blame] | 10528 | When {skipcc} set to 1, composing characters are treated as a |
| 10529 | part of the preceding base character, similar to |slice()|. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10530 | When a character index is used where a character does not |
| 10531 | exist it is omitted and counted as one character. For |
| 10532 | example: > |
| 10533 | strcharpart('abc', -1, 2) |
| 10534 | < results in 'a'. |
| 10535 | |
Bram Moolenaar | d592deb | 2022-06-17 15:42:40 +0100 | [diff] [blame] | 10536 | Returns an empty string on error. |
| 10537 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10538 | Can also be used as a |method|: > |
| 10539 | GetText()->strcharpart(5) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 10540 | < |
| 10541 | Return type: |String| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10542 | |
| 10543 | |
| 10544 | strchars({string} [, {skipcc}]) *strchars()* |
| 10545 | The result is a Number, which is the number of characters |
| 10546 | in String {string}. |
| 10547 | When {skipcc} is omitted or zero, composing characters are |
| 10548 | counted separately. |
zeertzjq | ad38769 | 2024-03-23 08:23:48 +0100 | [diff] [blame] | 10549 | When {skipcc} set to 1, composing characters are ignored. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10550 | |strcharlen()| always does this. |
| 10551 | |
Bram Moolenaar | d592deb | 2022-06-17 15:42:40 +0100 | [diff] [blame] | 10552 | Returns zero on error. |
| 10553 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10554 | Also see |strlen()|, |strdisplaywidth()| and |strwidth()|. |
| 10555 | |
| 10556 | {skipcc} is only available after 7.4.755. For backward |
| 10557 | compatibility, you can define a wrapper function: > |
| 10558 | if has("patch-7.4.755") |
| 10559 | function s:strchars(str, skipcc) |
| 10560 | return strchars(a:str, a:skipcc) |
| 10561 | endfunction |
| 10562 | else |
| 10563 | function s:strchars(str, skipcc) |
| 10564 | if a:skipcc |
| 10565 | return strlen(substitute(a:str, ".", "x", "g")) |
| 10566 | else |
| 10567 | return strchars(a:str) |
| 10568 | endif |
| 10569 | endfunction |
| 10570 | endif |
| 10571 | < |
| 10572 | Can also be used as a |method|: > |
| 10573 | GetText()->strchars() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 10574 | < |
| 10575 | Return type: |Number| |
| 10576 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10577 | |
| 10578 | strdisplaywidth({string} [, {col}]) *strdisplaywidth()* |
| 10579 | The result is a Number, which is the number of display cells |
| 10580 | String {string} occupies on the screen when it starts at {col} |
| 10581 | (first column is zero). When {col} is omitted zero is used. |
| 10582 | Otherwise it is the screen column where to start. This |
| 10583 | matters for Tab characters. |
| 10584 | The option settings of the current window are used. This |
| 10585 | matters for anything that's displayed differently, such as |
| 10586 | 'tabstop' and 'display'. |
| 10587 | When {string} contains characters with East Asian Width Class |
| 10588 | Ambiguous, this function's return value depends on 'ambiwidth'. |
Bram Moolenaar | d592deb | 2022-06-17 15:42:40 +0100 | [diff] [blame] | 10589 | Returns zero on error. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10590 | Also see |strlen()|, |strwidth()| and |strchars()|. |
| 10591 | |
| 10592 | Can also be used as a |method|: > |
| 10593 | GetText()->strdisplaywidth() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 10594 | < |
| 10595 | Return type: |Number| |
| 10596 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10597 | |
| 10598 | strftime({format} [, {time}]) *strftime()* |
| 10599 | The result is a String, which is a formatted date and time, as |
| 10600 | specified by the {format} string. The given {time} is used, |
| 10601 | or the current time if no time is given. The accepted |
| 10602 | {format} depends on your system, thus this is not portable! |
| 10603 | See the manual page of the C function strftime() for the |
| 10604 | format. The maximum length of the result is 80 characters. |
| 10605 | See also |localtime()|, |getftime()| and |strptime()|. |
| 10606 | The language can be changed with the |:language| command. |
| 10607 | Examples: > |
| 10608 | :echo strftime("%c") Sun Apr 27 11:49:23 1997 |
| 10609 | :echo strftime("%Y %b %d %X") 1997 Apr 27 11:53:25 |
| 10610 | :echo strftime("%y%m%d %T") 970427 11:53:55 |
| 10611 | :echo strftime("%H:%M") 11:55 |
| 10612 | :echo strftime("%c", getftime("file.c")) |
| 10613 | Show mod time of file.c. |
| 10614 | < Not available on all systems. To check use: > |
| 10615 | :if exists("*strftime") |
| 10616 | |
| 10617 | < Can also be used as a |method|: > |
| 10618 | GetFormat()->strftime() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 10619 | < |
| 10620 | Return type: |String| |
| 10621 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10622 | |
| 10623 | strgetchar({str}, {index}) *strgetchar()* |
Bram Moolenaar | 2d8ed02 | 2022-05-21 13:08:16 +0100 | [diff] [blame] | 10624 | Get a Number corresponding to the character at {index} in |
| 10625 | {str}. This uses a zero-based character index, not a byte |
| 10626 | index. Composing characters are considered separate |
| 10627 | characters here. Use |nr2char()| to convert the Number to a |
| 10628 | String. |
Bram Moolenaar | d592deb | 2022-06-17 15:42:40 +0100 | [diff] [blame] | 10629 | Returns -1 if {index} is invalid. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10630 | Also see |strcharpart()| and |strchars()|. |
| 10631 | |
| 10632 | Can also be used as a |method|: > |
| 10633 | GetText()->strgetchar(5) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 10634 | < |
| 10635 | Return type: |Number| |
| 10636 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10637 | |
| 10638 | stridx({haystack}, {needle} [, {start}]) *stridx()* |
| 10639 | The result is a Number, which gives the byte index in |
| 10640 | {haystack} of the first occurrence of the String {needle}. |
| 10641 | If {start} is specified, the search starts at index {start}. |
| 10642 | This can be used to find a second match: > |
| 10643 | :let colon1 = stridx(line, ":") |
| 10644 | :let colon2 = stridx(line, ":", colon1 + 1) |
| 10645 | < The search is done case-sensitive. |
| 10646 | For pattern searches use |match()|. |
| 10647 | -1 is returned if the {needle} does not occur in {haystack}. |
| 10648 | See also |strridx()|. |
| 10649 | Examples: > |
| 10650 | :echo stridx("An Example", "Example") 3 |
| 10651 | :echo stridx("Starting point", "Start") 0 |
| 10652 | :echo stridx("Starting point", "start") -1 |
| 10653 | < *strstr()* *strchr()* |
| 10654 | stridx() works similar to the C function strstr(). When used |
| 10655 | with a single character it works similar to strchr(). |
| 10656 | |
| 10657 | Can also be used as a |method|: > |
| 10658 | GetHaystack()->stridx(needle) |
| 10659 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 10660 | Return type: |Number| |
| 10661 | |
| 10662 | |
| 10663 | string({expr}) *string()* |
| 10664 | Return {expr} converted to a String. If {expr} is a Number, |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10665 | Float, String, Blob or a composition of them, then the result |
| 10666 | can be parsed back with |eval()|. |
| 10667 | {expr} type result ~ |
| 10668 | String 'string' (single quotes are doubled) |
| 10669 | Number 123 |
| 10670 | Float 123.123456 or 1.123456e8 |
| 10671 | Funcref function('name') |
| 10672 | Blob 0z00112233.44556677.8899 |
| 10673 | List [item, item] |
| 10674 | Dictionary {key: value, key: value} |
Bram Moolenaar | f1dcd14 | 2022-12-31 15:30:45 +0000 | [diff] [blame] | 10675 | Class class SomeName |
| 10676 | Object object of SomeName {lnum: 1, col: 3} |
Yegappan Lakshmanan | 3164cf8 | 2024-03-28 10:36:42 +0100 | [diff] [blame] | 10677 | Enum enum EnumName |
Yegappan Lakshmanan | 3cf121e | 2024-03-31 18:45:35 +0200 | [diff] [blame] | 10678 | EnumValue enum name.value {name: str, ordinal: nr} |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10679 | |
| 10680 | When a |List| or |Dictionary| has a recursive reference it is |
| 10681 | replaced by "[...]" or "{...}". Using eval() on the result |
| 10682 | will then fail. |
| 10683 | |
mityu | 7f0bba2 | 2024-03-29 10:14:41 +0100 | [diff] [blame] | 10684 | For an object, invokes the string() method to get a textual |
Yegappan Lakshmanan | d3eae7b | 2024-03-03 16:26:58 +0100 | [diff] [blame] | 10685 | representation of the object. If the method is not present, |
mityu | 7f0bba2 | 2024-03-29 10:14:41 +0100 | [diff] [blame] | 10686 | then the default representation is used. |object-string()| |
Yegappan Lakshmanan | d3eae7b | 2024-03-03 16:26:58 +0100 | [diff] [blame] | 10687 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10688 | Can also be used as a |method|: > |
| 10689 | mylist->string() |
| 10690 | |
| 10691 | < Also see |strtrans()|. |
| 10692 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 10693 | Return type: |String| |
| 10694 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10695 | |
| 10696 | strlen({string}) *strlen()* |
| 10697 | The result is a Number, which is the length of the String |
| 10698 | {string} in bytes. |
| 10699 | If the argument is a Number it is first converted to a String. |
Bram Moolenaar | d592deb | 2022-06-17 15:42:40 +0100 | [diff] [blame] | 10700 | For other types an error is given and zero is returned. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10701 | If you want to count the number of multibyte characters use |
| 10702 | |strchars()|. |
| 10703 | Also see |len()|, |strdisplaywidth()| and |strwidth()|. |
| 10704 | |
| 10705 | Can also be used as a |method|: > |
| 10706 | GetString()->strlen() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 10707 | < |
| 10708 | Return type: |Number| |
| 10709 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10710 | |
| 10711 | strpart({src}, {start} [, {len} [, {chars}]]) *strpart()* |
| 10712 | The result is a String, which is part of {src}, starting from |
| 10713 | byte {start}, with the byte length {len}. |
| 10714 | When {chars} is present and TRUE then {len} is the number of |
| 10715 | characters positions (composing characters are not counted |
| 10716 | separately, thus "1" means one base character and any |
| 10717 | following composing characters). |
| 10718 | To count {start} as characters instead of bytes use |
| 10719 | |strcharpart()|. |
| 10720 | |
| 10721 | When bytes are selected which do not exist, this doesn't |
| 10722 | result in an error, the bytes are simply omitted. |
| 10723 | If {len} is missing, the copy continues from {start} till the |
| 10724 | end of the {src}. > |
| 10725 | strpart("abcdefg", 3, 2) == "de" |
| 10726 | strpart("abcdefg", -2, 4) == "ab" |
| 10727 | strpart("abcdefg", 5, 4) == "fg" |
| 10728 | strpart("abcdefg", 3) == "defg" |
| 10729 | |
| 10730 | < Note: To get the first character, {start} must be 0. For |
| 10731 | example, to get the character under the cursor: > |
| 10732 | strpart(getline("."), col(".") - 1, 1, v:true) |
| 10733 | < |
Bram Moolenaar | d592deb | 2022-06-17 15:42:40 +0100 | [diff] [blame] | 10734 | Returns an empty string on error. |
| 10735 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10736 | Can also be used as a |method|: > |
| 10737 | GetText()->strpart(5) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 10738 | < |
| 10739 | Return type: |String| |
| 10740 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10741 | |
| 10742 | strptime({format}, {timestring}) *strptime()* |
| 10743 | The result is a Number, which is a unix timestamp representing |
| 10744 | the date and time in {timestring}, which is expected to match |
| 10745 | the format specified in {format}. |
| 10746 | |
| 10747 | The accepted {format} depends on your system, thus this is not |
| 10748 | portable! See the manual page of the C function strptime() |
| 10749 | for the format. Especially avoid "%c". The value of $TZ also |
| 10750 | matters. |
| 10751 | |
| 10752 | If the {timestring} cannot be parsed with {format} zero is |
| 10753 | returned. If you do not know the format of {timestring} you |
| 10754 | can try different {format} values until you get a non-zero |
| 10755 | result. |
| 10756 | |
| 10757 | See also |strftime()|. |
| 10758 | Examples: > |
| 10759 | :echo strptime("%Y %b %d %X", "1997 Apr 27 11:49:23") |
| 10760 | < 862156163 > |
| 10761 | :echo strftime("%c", strptime("%y%m%d %T", "970427 11:53:55")) |
| 10762 | < Sun Apr 27 11:53:55 1997 > |
| 10763 | :echo strftime("%c", strptime("%Y%m%d%H%M%S", "19970427115355") + 3600) |
| 10764 | < Sun Apr 27 12:53:55 1997 |
| 10765 | |
| 10766 | Can also be used as a |method|: > |
| 10767 | GetFormat()->strptime(timestring) |
| 10768 | < |
| 10769 | Not available on all systems. To check use: > |
| 10770 | :if exists("*strptime") |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 10771 | < |
| 10772 | Return type: |Number| |
| 10773 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10774 | |
| 10775 | strridx({haystack}, {needle} [, {start}]) *strridx()* |
| 10776 | The result is a Number, which gives the byte index in |
| 10777 | {haystack} of the last occurrence of the String {needle}. |
| 10778 | When {start} is specified, matches beyond this index are |
| 10779 | ignored. This can be used to find a match before a previous |
| 10780 | match: > |
| 10781 | :let lastcomma = strridx(line, ",") |
| 10782 | :let comma2 = strridx(line, ",", lastcomma - 1) |
| 10783 | < The search is done case-sensitive. |
| 10784 | For pattern searches use |match()|. |
| 10785 | -1 is returned if the {needle} does not occur in {haystack}. |
| 10786 | If the {needle} is empty the length of {haystack} is returned. |
| 10787 | See also |stridx()|. Examples: > |
| 10788 | :echo strridx("an angry armadillo", "an") 3 |
| 10789 | < *strrchr()* |
| 10790 | When used with a single character it works similar to the C |
| 10791 | function strrchr(). |
| 10792 | |
| 10793 | Can also be used as a |method|: > |
| 10794 | GetHaystack()->strridx(needle) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 10795 | < |
| 10796 | Return type: |Number| |
| 10797 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10798 | |
| 10799 | strtrans({string}) *strtrans()* |
| 10800 | The result is a String, which is {string} with all unprintable |
| 10801 | characters translated into printable characters |'isprint'|. |
| 10802 | Like they are shown in a window. Example: > |
| 10803 | echo strtrans(@a) |
| 10804 | < This displays a newline in register a as "^@" instead of |
| 10805 | starting a new line. |
| 10806 | |
Bram Moolenaar | d592deb | 2022-06-17 15:42:40 +0100 | [diff] [blame] | 10807 | Returns an empty string on error. |
| 10808 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10809 | Can also be used as a |method|: > |
| 10810 | GetString()->strtrans() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 10811 | < |
| 10812 | Return type: |String| |
| 10813 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10814 | |
Christian Brabandt | 67672ef | 2023-04-24 21:09:54 +0100 | [diff] [blame] | 10815 | strutf16len({string} [, {countcc}]) *strutf16len()* |
| 10816 | The result is a Number, which is the number of UTF-16 code |
| 10817 | units in String {string} (after converting it to UTF-16). |
| 10818 | |
| 10819 | When {countcc} is TRUE, composing characters are counted |
| 10820 | separately. |
| 10821 | When {countcc} is omitted or FALSE, composing characters are |
| 10822 | ignored. |
| 10823 | |
| 10824 | Returns zero on error. |
| 10825 | |
| 10826 | Also see |strlen()| and |strcharlen()|. |
| 10827 | Examples: > |
| 10828 | echo strutf16len('a') returns 1 |
| 10829 | echo strutf16len('©') returns 1 |
| 10830 | echo strutf16len('😊') returns 2 |
| 10831 | echo strutf16len('ą́') returns 1 |
| 10832 | echo strutf16len('ą́', v:true) returns 3 |
a5ob7r | 790f9a8 | 2023-09-25 06:05:47 +0900 | [diff] [blame] | 10833 | < |
Christian Brabandt | 67672ef | 2023-04-24 21:09:54 +0100 | [diff] [blame] | 10834 | Can also be used as a |method|: > |
| 10835 | GetText()->strutf16len() |
| 10836 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 10837 | Return type: |Number| |
| 10838 | |
| 10839 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10840 | strwidth({string}) *strwidth()* |
| 10841 | The result is a Number, which is the number of display cells |
| 10842 | String {string} occupies. A Tab character is counted as one |
| 10843 | cell, alternatively use |strdisplaywidth()|. |
| 10844 | When {string} contains characters with East Asian Width Class |
| 10845 | Ambiguous, this function's return value depends on 'ambiwidth'. |
Bram Moolenaar | d592deb | 2022-06-17 15:42:40 +0100 | [diff] [blame] | 10846 | Returns zero on error. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10847 | Also see |strlen()|, |strdisplaywidth()| and |strchars()|. |
| 10848 | |
| 10849 | Can also be used as a |method|: > |
| 10850 | GetString()->strwidth() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 10851 | < |
| 10852 | Return type: |Number| |
| 10853 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10854 | |
| 10855 | submatch({nr} [, {list}]) *submatch()* *E935* |
| 10856 | Only for an expression in a |:substitute| command or |
| 10857 | substitute() function. |
| 10858 | Returns the {nr}'th submatch of the matched text. When {nr} |
| 10859 | is 0 the whole matched text is returned. |
| 10860 | Note that a NL in the string can stand for a line break of a |
| 10861 | multi-line match or a NUL character in the text. |
| 10862 | Also see |sub-replace-expression|. |
| 10863 | |
| 10864 | If {list} is present and non-zero then submatch() returns |
| 10865 | a list of strings, similar to |getline()| with two arguments. |
| 10866 | NL characters in the text represent NUL characters in the |
| 10867 | text. |
| 10868 | Only returns more than one item for |:substitute|, inside |
| 10869 | |substitute()| this list will always contain one or zero |
| 10870 | items, since there are no real line breaks. |
| 10871 | |
| 10872 | When substitute() is used recursively only the submatches in |
| 10873 | the current (deepest) call can be obtained. |
| 10874 | |
Bram Moolenaar | d592deb | 2022-06-17 15:42:40 +0100 | [diff] [blame] | 10875 | Returns an empty string or list on error. |
| 10876 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10877 | Examples: > |
| 10878 | :s/\d\+/\=submatch(0) + 1/ |
| 10879 | :echo substitute(text, '\d\+', '\=submatch(0) + 1', '') |
| 10880 | < This finds the first number in the line and adds one to it. |
| 10881 | A line break is included as a newline character. |
| 10882 | |
| 10883 | Can also be used as a |method|: > |
| 10884 | GetNr()->submatch() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 10885 | < |
| 10886 | Return type: |String| or list<string> depending on {list} |
| 10887 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10888 | |
| 10889 | substitute({string}, {pat}, {sub}, {flags}) *substitute()* |
| 10890 | The result is a String, which is a copy of {string}, in which |
| 10891 | the first match of {pat} is replaced with {sub}. |
| 10892 | When {flags} is "g", all matches of {pat} in {string} are |
| 10893 | replaced. Otherwise {flags} should be "". |
| 10894 | |
| 10895 | This works like the ":substitute" command (without any flags). |
| 10896 | But the matching with {pat} is always done like the 'magic' |
| 10897 | option is set and 'cpoptions' is empty (to make scripts |
| 10898 | portable). 'ignorecase' is still relevant, use |/\c| or |/\C| |
| 10899 | if you want to ignore or match case and ignore 'ignorecase'. |
| 10900 | 'smartcase' is not used. See |string-match| for how {pat} is |
| 10901 | used. |
| 10902 | |
| 10903 | A "~" in {sub} is not replaced with the previous {sub}. |
| 10904 | Note that some codes in {sub} have a special meaning |
| 10905 | |sub-replace-special|. For example, to replace something with |
| 10906 | "\n" (two characters), use "\\\\n" or '\\n'. |
| 10907 | |
| 10908 | When {pat} does not match in {string}, {string} is returned |
| 10909 | unmodified. |
| 10910 | |
| 10911 | Example: > |
| 10912 | :let &path = substitute(&path, ",\\=[^,]*$", "", "") |
| 10913 | < This removes the last component of the 'path' option. > |
| 10914 | :echo substitute("testing", ".*", "\\U\\0", "") |
| 10915 | < results in "TESTING". |
| 10916 | |
| 10917 | When {sub} starts with "\=", the remainder is interpreted as |
| 10918 | an expression. See |sub-replace-expression|. Example: > |
| 10919 | :echo substitute(s, '%\(\x\x\)', |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 10920 | \ '\=nr2char("0x" .. submatch(1))', 'g') |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10921 | |
| 10922 | < When {sub} is a Funcref that function is called, with one |
| 10923 | optional argument. Example: > |
| 10924 | :echo substitute(s, '%\(\x\x\)', SubNr, 'g') |
| 10925 | < The optional argument is a list which contains the whole |
| 10926 | matched string and up to nine submatches, like what |
| 10927 | |submatch()| returns. Example: > |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 10928 | :echo substitute(s, '%\(\x\x\)', {m -> '0x' .. m[1]}, 'g') |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10929 | |
Bram Moolenaar | d592deb | 2022-06-17 15:42:40 +0100 | [diff] [blame] | 10930 | < Returns an empty string on error. |
| 10931 | |
| 10932 | Can also be used as a |method|: > |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10933 | GetString()->substitute(pat, sub, flags) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 10934 | < |
| 10935 | Return type: |String| |
| 10936 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10937 | |
Bram Moolenaar | c216a7a | 2022-12-05 13:50:55 +0000 | [diff] [blame] | 10938 | swapfilelist() *swapfilelist()* |
| 10939 | Returns a list of swap file names, like what "vim -r" shows. |
| 10940 | See the |-r| command argument. The 'directory' option is used |
| 10941 | for the directories to inspect. If you only want to get a |
| 10942 | list of swap files in the current directory then temporarily |
| 10943 | set 'directory' to a dot: > |
| 10944 | let save_dir = &directory |
| 10945 | let &directory = '.' |
| 10946 | let swapfiles = swapfilelist() |
| 10947 | let &directory = save_dir |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 10948 | < |
| 10949 | Return type: list<string> |
| 10950 | |
Bram Moolenaar | c216a7a | 2022-12-05 13:50:55 +0000 | [diff] [blame] | 10951 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10952 | swapinfo({fname}) *swapinfo()* |
| 10953 | The result is a dictionary, which holds information about the |
| 10954 | swapfile {fname}. The available fields are: |
| 10955 | version Vim version |
| 10956 | user user name |
| 10957 | host host name |
| 10958 | fname original file name |
| 10959 | pid PID of the Vim process that created the swap |
| 10960 | file |
| 10961 | mtime last modification time in seconds |
| 10962 | inode Optional: INODE number of the file |
| 10963 | dirty 1 if file was modified, 0 if not |
| 10964 | Note that "user" and "host" are truncated to at most 39 bytes. |
| 10965 | In case of failure an "error" item is added with the reason: |
| 10966 | Cannot open file: file not found or in accessible |
| 10967 | Cannot read file: cannot read first block |
| 10968 | Not a swap file: does not contain correct block ID |
| 10969 | Magic number mismatch: Info in first block is invalid |
| 10970 | |
| 10971 | Can also be used as a |method|: > |
| 10972 | GetFilename()->swapinfo() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 10973 | < |
| 10974 | Return type: dict<any> or dict<string> |
| 10975 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10976 | |
| 10977 | swapname({buf}) *swapname()* |
| 10978 | The result is the swap file path of the buffer {expr}. |
| 10979 | For the use of {buf}, see |bufname()| above. |
| 10980 | If buffer {buf} is the current buffer, the result is equal to |
| 10981 | |:swapname| (unless there is no swap file). |
| 10982 | If buffer {buf} has no swap file, returns an empty string. |
| 10983 | |
| 10984 | Can also be used as a |method|: > |
| 10985 | GetBufname()->swapname() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 10986 | < |
| 10987 | Return type: |String| |
| 10988 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 10989 | |
| 10990 | synID({lnum}, {col}, {trans}) *synID()* |
| 10991 | The result is a Number, which is the syntax ID at the position |
| 10992 | {lnum} and {col} in the current window. |
| 10993 | The syntax ID can be used with |synIDattr()| and |
| 10994 | |synIDtrans()| to obtain syntax information about text. |
| 10995 | |
| 10996 | {col} is 1 for the leftmost column, {lnum} is 1 for the first |
| 10997 | line. 'synmaxcol' applies, in a longer line zero is returned. |
| 10998 | Note that when the position is after the last character, |
| 10999 | that's where the cursor can be in Insert mode, synID() returns |
| 11000 | zero. {lnum} is used like with |getline()|. |
| 11001 | |
| 11002 | When {trans} is |TRUE|, transparent items are reduced to the |
| 11003 | item that they reveal. This is useful when wanting to know |
| 11004 | the effective color. When {trans} is |FALSE|, the transparent |
| 11005 | item is returned. This is useful when wanting to know which |
| 11006 | syntax item is effective (e.g. inside parens). |
| 11007 | Warning: This function can be very slow. Best speed is |
| 11008 | obtained by going through the file in forward direction. |
| 11009 | |
Bram Moolenaar | d592deb | 2022-06-17 15:42:40 +0100 | [diff] [blame] | 11010 | Returns zero on error. |
| 11011 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11012 | Example (echoes the name of the syntax item under the cursor): > |
| 11013 | :echo synIDattr(synID(line("."), col("."), 1), "name") |
| 11014 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 11015 | Return type: |Number| |
| 11016 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11017 | |
| 11018 | synIDattr({synID}, {what} [, {mode}]) *synIDattr()* |
| 11019 | The result is a String, which is the {what} attribute of |
| 11020 | syntax ID {synID}. This can be used to obtain information |
| 11021 | about a syntax item. |
| 11022 | {mode} can be "gui", "cterm" or "term", to get the attributes |
| 11023 | for that mode. When {mode} is omitted, or an invalid value is |
| 11024 | used, the attributes for the currently active highlighting are |
| 11025 | used (GUI, cterm or term). |
| 11026 | Use synIDtrans() to follow linked highlight groups. |
| 11027 | {what} result |
| 11028 | "name" the name of the syntax item |
| 11029 | "fg" foreground color (GUI: color name used to set |
| 11030 | the color, cterm: color number as a string, |
| 11031 | term: empty string) |
| 11032 | "bg" background color (as with "fg") |
| 11033 | "font" font name (only available in the GUI) |
| 11034 | |highlight-font| |
| 11035 | "sp" special color for the GUI (as with "fg") |
| 11036 | |highlight-guisp| |
| 11037 | "ul" underline color for cterm: number as a string |
| 11038 | "fg#" like "fg", but for the GUI and the GUI is |
| 11039 | running the name in "#RRGGBB" form |
| 11040 | "bg#" like "fg#" for "bg" |
| 11041 | "sp#" like "fg#" for "sp" |
| 11042 | "bold" "1" if bold |
| 11043 | "italic" "1" if italic |
| 11044 | "reverse" "1" if reverse |
| 11045 | "inverse" "1" if inverse (= reverse) |
| 11046 | "standout" "1" if standout |
| 11047 | "underline" "1" if underlined |
| 11048 | "undercurl" "1" if undercurled |
| 11049 | "strike" "1" if strikethrough |
Bram Moolenaar | de78632 | 2022-07-30 14:56:17 +0100 | [diff] [blame] | 11050 | "nocombine" "1" if nocombine |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11051 | |
Bram Moolenaar | d592deb | 2022-06-17 15:42:40 +0100 | [diff] [blame] | 11052 | Returns an empty string on error. |
| 11053 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11054 | Example (echoes the color of the syntax item under the |
| 11055 | cursor): > |
| 11056 | :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg") |
| 11057 | < |
| 11058 | Can also be used as a |method|: > |
| 11059 | :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg") |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 11060 | < |
| 11061 | Return type: |String| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11062 | |
| 11063 | |
| 11064 | synIDtrans({synID}) *synIDtrans()* |
| 11065 | The result is a Number, which is the translated syntax ID of |
| 11066 | {synID}. This is the syntax group ID of what is being used to |
| 11067 | highlight the character. Highlight links given with |
| 11068 | ":highlight link" are followed. |
| 11069 | |
Bram Moolenaar | d592deb | 2022-06-17 15:42:40 +0100 | [diff] [blame] | 11070 | Returns zero on error. |
| 11071 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11072 | Can also be used as a |method|: > |
| 11073 | :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg") |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 11074 | < |
| 11075 | Return type: |Number| |
| 11076 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11077 | |
| 11078 | synconcealed({lnum}, {col}) *synconcealed()* |
| 11079 | The result is a |List| with currently three items: |
| 11080 | 1. The first item in the list is 0 if the character at the |
| 11081 | position {lnum} and {col} is not part of a concealable |
| 11082 | region, 1 if it is. {lnum} is used like with |getline()|. |
| 11083 | 2. The second item in the list is a string. If the first item |
| 11084 | is 1, the second item contains the text which will be |
| 11085 | displayed in place of the concealed text, depending on the |
| 11086 | current setting of 'conceallevel' and 'listchars'. |
| 11087 | 3. The third and final item in the list is a number |
| 11088 | representing the specific syntax region matched in the |
| 11089 | line. When the character is not concealed the value is |
| 11090 | zero. This allows detection of the beginning of a new |
| 11091 | concealable region if there are two consecutive regions |
| 11092 | with the same replacement character. For an example, if |
| 11093 | the text is "123456" and both "23" and "45" are concealed |
| 11094 | and replaced by the character "X", then: |
| 11095 | call returns ~ |
| 11096 | synconcealed(lnum, 1) [0, '', 0] |
| 11097 | synconcealed(lnum, 2) [1, 'X', 1] |
| 11098 | synconcealed(lnum, 3) [1, 'X', 1] |
| 11099 | synconcealed(lnum, 4) [1, 'X', 2] |
| 11100 | synconcealed(lnum, 5) [1, 'X', 2] |
| 11101 | synconcealed(lnum, 6) [0, '', 0] |
| 11102 | |
Christian Brabandt | fe1e2b5 | 2024-04-26 18:42:59 +0200 | [diff] [blame] | 11103 | Note: Doesn't consider |matchadd()| highlighting items, |
| 11104 | since syntax and matching highlighting are two different |
| 11105 | mechanisms |syntax-vs-match|. |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 11106 | < |
| 11107 | Return type: list<any> |
Christian Brabandt | fe1e2b5 | 2024-04-26 18:42:59 +0200 | [diff] [blame] | 11108 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11109 | |
| 11110 | synstack({lnum}, {col}) *synstack()* |
| 11111 | Return a |List|, which is the stack of syntax items at the |
| 11112 | position {lnum} and {col} in the current window. {lnum} is |
| 11113 | used like with |getline()|. Each item in the List is an ID |
| 11114 | like what |synID()| returns. |
| 11115 | The first item in the List is the outer region, following are |
| 11116 | items contained in that one. The last one is what |synID()| |
| 11117 | returns, unless not the whole item is highlighted or it is a |
| 11118 | transparent item. |
| 11119 | This function is useful for debugging a syntax file. |
| 11120 | Example that shows the syntax stack under the cursor: > |
| 11121 | for id in synstack(line("."), col(".")) |
| 11122 | echo synIDattr(id, "name") |
| 11123 | endfor |
| 11124 | < When the position specified with {lnum} and {col} is invalid |
Bram Moolenaar | d592deb | 2022-06-17 15:42:40 +0100 | [diff] [blame] | 11125 | an empty List is returned. The position just after the last |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11126 | character in a line and the first column in an empty line are |
| 11127 | valid positions. |
| 11128 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 11129 | Return type: list<number> or list<any> |
| 11130 | |
| 11131 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11132 | system({expr} [, {input}]) *system()* *E677* |
| 11133 | Get the output of the shell command {expr} as a |String|. See |
| 11134 | |systemlist()| to get the output as a |List|. |
| 11135 | |
| 11136 | When {input} is given and is a |String| this string is written |
| 11137 | to a file and passed as stdin to the command. The string is |
| 11138 | written as-is, you need to take care of using the correct line |
| 11139 | separators yourself. |
| 11140 | If {input} is given and is a |List| it is written to the file |
| 11141 | in a way |writefile()| does with {binary} set to "b" (i.e. |
| 11142 | with a newline between each list item with newlines inside |
| 11143 | list items converted to NULs). |
| 11144 | When {input} is given and is a number that is a valid id for |
| 11145 | an existing buffer then the content of the buffer is written |
| 11146 | to the file line by line, each line terminated by a NL and |
| 11147 | NULs characters where the text has a NL. |
| 11148 | |
| 11149 | Pipes are not used, the 'shelltemp' option is not used. |
| 11150 | |
| 11151 | When prepended by |:silent| the terminal will not be set to |
| 11152 | cooked mode. This is meant to be used for commands that do |
| 11153 | not need the user to type. It avoids stray characters showing |
| 11154 | up on the screen which require |CTRL-L| to remove. > |
| 11155 | :silent let f = system('ls *.vim') |
| 11156 | < |
| 11157 | Note: Use |shellescape()| or |::S| with |expand()| or |
| 11158 | |fnamemodify()| to escape special characters in a command |
| 11159 | argument. Newlines in {expr} may cause the command to fail. |
| 11160 | The characters in 'shellquote' and 'shellxquote' may also |
| 11161 | cause trouble. |
| 11162 | This is not to be used for interactive commands. |
| 11163 | |
| 11164 | The result is a String. Example: > |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 11165 | :let files = system('ls ' .. shellescape(expand('%:h'))) |
| 11166 | :let files = system('ls ' .. expand('%:h:S')) |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11167 | |
| 11168 | < To make the result more system-independent, the shell output |
| 11169 | is filtered to replace <CR> with <NL> for Macintosh, and |
| 11170 | <CR><NL> with <NL> for DOS-like systems. |
| 11171 | To avoid the string being truncated at a NUL, all NUL |
| 11172 | characters are replaced with SOH (0x01). |
| 11173 | |
| 11174 | The command executed is constructed using several options: |
| 11175 | 'shell' 'shellcmdflag' 'shellxquote' {expr} 'shellredir' {tmp} 'shellxquote' |
| 11176 | ({tmp} is an automatically generated file name). |
| 11177 | For Unix, braces are put around {expr} to allow for |
| 11178 | concatenated commands. |
| 11179 | |
| 11180 | The command will be executed in "cooked" mode, so that a |
| 11181 | CTRL-C will interrupt the command (on Unix at least). |
| 11182 | |
| 11183 | The resulting error code can be found in |v:shell_error|. |
| 11184 | This function will fail in |restricted-mode|. |
| 11185 | |
| 11186 | Note that any wrong value in the options mentioned above may |
| 11187 | make the function fail. It has also been reported to fail |
| 11188 | when using a security agent application. |
| 11189 | Unlike ":!cmd" there is no automatic check for changed files. |
| 11190 | Use |:checktime| to force a check. |
| 11191 | |
| 11192 | Can also be used as a |method|: > |
| 11193 | :echo GetCmd()->system() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 11194 | < |
| 11195 | Return type: |String| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11196 | |
| 11197 | |
| 11198 | systemlist({expr} [, {input}]) *systemlist()* |
| 11199 | Same as |system()|, but returns a |List| with lines (parts of |
| 11200 | output separated by NL) with NULs transformed into NLs. Output |
| 11201 | is the same as |readfile()| will output with {binary} argument |
| 11202 | set to "b", except that there is no extra empty item when the |
| 11203 | result ends in a NL. |
| 11204 | Note that on MS-Windows you may get trailing CR characters. |
| 11205 | |
| 11206 | To see the difference between "echo hello" and "echo -n hello" |
| 11207 | use |system()| and |split()|: > |
| 11208 | echo system('echo hello')->split('\n', 1) |
| 11209 | < |
| 11210 | Returns an empty string on error. |
| 11211 | |
| 11212 | Can also be used as a |method|: > |
| 11213 | :echo GetCmd()->systemlist() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 11214 | < |
| 11215 | Return type: list<string> |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11216 | |
| 11217 | |
| 11218 | tabpagebuflist([{arg}]) *tabpagebuflist()* |
| 11219 | The result is a |List|, where each item is the number of the |
| 11220 | buffer associated with each window in the current tab page. |
| 11221 | {arg} specifies the number of the tab page to be used. When |
| 11222 | omitted the current tab page is used. |
| 11223 | When {arg} is invalid the number zero is returned. |
| 11224 | To get a list of all buffers in all tabs use this: > |
| 11225 | let buflist = [] |
| 11226 | for i in range(tabpagenr('$')) |
| 11227 | call extend(buflist, tabpagebuflist(i + 1)) |
| 11228 | endfor |
| 11229 | < Note that a buffer may appear in more than one window. |
| 11230 | |
| 11231 | Can also be used as a |method|: > |
| 11232 | GetTabpage()->tabpagebuflist() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 11233 | < |
| 11234 | Return type: list<number> |
| 11235 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11236 | |
| 11237 | tabpagenr([{arg}]) *tabpagenr()* |
| 11238 | The result is a Number, which is the number of the current |
| 11239 | tab page. The first tab page has number 1. |
| 11240 | |
| 11241 | The optional argument {arg} supports the following values: |
| 11242 | $ the number of the last tab page (the tab page |
| 11243 | count). |
| 11244 | # the number of the last accessed tab page |
| 11245 | (where |g<Tab>| goes to). if there is no |
| 11246 | previous tab page 0 is returned. |
| 11247 | The number can be used with the |:tab| command. |
| 11248 | |
Bram Moolenaar | d592deb | 2022-06-17 15:42:40 +0100 | [diff] [blame] | 11249 | Returns zero on error. |
| 11250 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 11251 | Return type: |Number| |
| 11252 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11253 | |
| 11254 | tabpagewinnr({tabarg} [, {arg}]) *tabpagewinnr()* |
| 11255 | Like |winnr()| but for tab page {tabarg}. |
| 11256 | {tabarg} specifies the number of tab page to be used. |
| 11257 | {arg} is used like with |winnr()|: |
| 11258 | - When omitted the current window number is returned. This is |
| 11259 | the window which will be used when going to this tab page. |
| 11260 | - When "$" the number of windows is returned. |
| 11261 | - When "#" the previous window nr is returned. |
| 11262 | Useful examples: > |
| 11263 | tabpagewinnr(1) " current window of tab page 1 |
| 11264 | tabpagewinnr(4, '$') " number of windows in tab page 4 |
| 11265 | < When {tabarg} is invalid zero is returned. |
| 11266 | |
| 11267 | Can also be used as a |method|: > |
| 11268 | GetTabpage()->tabpagewinnr() |
| 11269 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 11270 | Return type: |Number| |
| 11271 | |
| 11272 | |
| 11273 | tagfiles() *tagfiles()* |
| 11274 | Returns a |List| with the file names used to search for tags |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11275 | for the current buffer. This is the 'tags' option expanded. |
| 11276 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 11277 | Return type: list<string> or list<any> |
| 11278 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11279 | |
| 11280 | taglist({expr} [, {filename}]) *taglist()* |
| 11281 | Returns a |List| of tags matching the regular expression {expr}. |
| 11282 | |
| 11283 | If {filename} is passed it is used to prioritize the results |
| 11284 | in the same way that |:tselect| does. See |tag-priority|. |
| 11285 | {filename} should be the full path of the file. |
| 11286 | |
| 11287 | Each list item is a dictionary with at least the following |
| 11288 | entries: |
| 11289 | name Name of the tag. |
| 11290 | filename Name of the file where the tag is |
| 11291 | defined. It is either relative to the |
| 11292 | current directory or a full path. |
| 11293 | cmd Ex command used to locate the tag in |
| 11294 | the file. |
| 11295 | kind Type of the tag. The value for this |
| 11296 | entry depends on the language specific |
| 11297 | kind values. Only available when |
| 11298 | using a tags file generated by |
Bram Moolenaar | 47c532e | 2022-03-19 15:18:53 +0000 | [diff] [blame] | 11299 | Universal/Exuberant ctags or hdrtag. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11300 | static A file specific tag. Refer to |
| 11301 | |static-tag| for more information. |
| 11302 | More entries may be present, depending on the content of the |
| 11303 | tags file: access, implementation, inherits and signature. |
| 11304 | Refer to the ctags documentation for information about these |
| 11305 | fields. For C code the fields "struct", "class" and "enum" |
| 11306 | may appear, they give the name of the entity the tag is |
| 11307 | contained in. |
| 11308 | |
| 11309 | The ex-command "cmd" can be either an ex search pattern, a |
| 11310 | line number or a line number followed by a byte number. |
| 11311 | |
| 11312 | If there are no matching tags, then an empty list is returned. |
| 11313 | |
| 11314 | To get an exact tag match, the anchors '^' and '$' should be |
| 11315 | used in {expr}. This also make the function work faster. |
| 11316 | Refer to |tag-regexp| for more information about the tag |
| 11317 | search regular expression pattern. |
| 11318 | |
| 11319 | Refer to |'tags'| for information about how the tags file is |
| 11320 | located by Vim. Refer to |tags-file-format| for the format of |
| 11321 | the tags file generated by the different ctags tools. |
| 11322 | |
| 11323 | Can also be used as a |method|: > |
| 11324 | GetTagpattern()->taglist() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 11325 | < |
| 11326 | Return type: list<dict<any>> or list<any> |
| 11327 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11328 | |
| 11329 | tan({expr}) *tan()* |
| 11330 | Return the tangent of {expr}, measured in radians, as a |Float| |
| 11331 | in the range [-inf, inf]. |
| 11332 | {expr} must evaluate to a |Float| or a |Number|. |
Bram Moolenaar | d592deb | 2022-06-17 15:42:40 +0100 | [diff] [blame] | 11333 | Returns 0.0 if {expr} is not a |Float| or a |Number|. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11334 | Examples: > |
| 11335 | :echo tan(10) |
| 11336 | < 0.648361 > |
| 11337 | :echo tan(-4.01) |
| 11338 | < -1.181502 |
| 11339 | |
| 11340 | Can also be used as a |method|: > |
| 11341 | Compute()->tan() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 11342 | < |
| 11343 | Return type: |Float| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11344 | |
| 11345 | |
| 11346 | tanh({expr}) *tanh()* |
| 11347 | Return the hyperbolic tangent of {expr} as a |Float| in the |
| 11348 | range [-1, 1]. |
| 11349 | {expr} must evaluate to a |Float| or a |Number|. |
Bram Moolenaar | d592deb | 2022-06-17 15:42:40 +0100 | [diff] [blame] | 11350 | Returns 0.0 if {expr} is not a |Float| or a |Number|. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11351 | Examples: > |
| 11352 | :echo tanh(0.5) |
| 11353 | < 0.462117 > |
| 11354 | :echo tanh(-1) |
| 11355 | < -0.761594 |
| 11356 | |
| 11357 | Can also be used as a |method|: > |
| 11358 | Compute()->tanh() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 11359 | < |
| 11360 | Return type: |Float| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11361 | |
| 11362 | |
| 11363 | tempname() *tempname()* *temp-file-name* |
| 11364 | The result is a String, which is the name of a file that |
| 11365 | doesn't exist. It can be used for a temporary file. The name |
| 11366 | is different for at least 26 consecutive calls. Example: > |
| 11367 | :let tmpfile = tempname() |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 11368 | :exe "redir > " .. tmpfile |
Christian Brabandt | 5cf5301 | 2024-05-18 10:13:11 +0200 | [diff] [blame] | 11369 | < For Unix, the file will be in a private directory |tempfile| |
| 11370 | that is recursively deleted when Vim exits, on other systems |
| 11371 | temporary files are not cleaned up automatically on exit. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11372 | For MS-Windows forward slashes are used when the 'shellslash' |
| 11373 | option is set, or when 'shellcmdflag' starts with '-' and |
| 11374 | 'shell' does not contain powershell or pwsh. |
| 11375 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 11376 | Return type: |String| |
| 11377 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11378 | |
| 11379 | term_ functions are documented here: |terminal-function-details| |
| 11380 | |
| 11381 | |
| 11382 | terminalprops() *terminalprops()* |
| 11383 | Returns a |Dictionary| with properties of the terminal that Vim |
| 11384 | detected from the response to |t_RV| request. See |
| 11385 | |v:termresponse| for the response itself. If |v:termresponse| |
| 11386 | is empty most values here will be 'u' for unknown. |
| 11387 | cursor_style whether sending |t_RS| works ** |
| 11388 | cursor_blink_mode whether sending |t_RC| works ** |
| 11389 | underline_rgb whether |t_8u| works ** |
| 11390 | mouse mouse type supported |
Bram Moolenaar | 4bc85f2 | 2022-10-21 14:17:24 +0100 | [diff] [blame] | 11391 | kitty whether Kitty terminal was detected |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11392 | |
| 11393 | ** value 'u' for unknown, 'y' for yes, 'n' for no |
| 11394 | |
| 11395 | If the |+termresponse| feature is missing then the result is |
| 11396 | an empty dictionary. |
| 11397 | |
| 11398 | If "cursor_style" is 'y' then |t_RS| will be sent to request the |
| 11399 | current cursor style. |
| 11400 | If "cursor_blink_mode" is 'y' then |t_RC| will be sent to |
| 11401 | request the cursor blink status. |
| 11402 | "cursor_style" and "cursor_blink_mode" are also set if |t_u7| |
| 11403 | is not empty, Vim will detect the working of sending |t_RS| |
| 11404 | and |t_RC| on startup. |
| 11405 | |
| 11406 | When "underline_rgb" is not 'y', then |t_8u| will be made empty. |
| 11407 | This avoids sending it to xterm, which would clear the colors. |
| 11408 | |
| 11409 | For "mouse" the value 'u' is unknown |
| 11410 | |
| 11411 | Also see: |
| 11412 | - 'ambiwidth' - detected by using |t_u7|. |
| 11413 | - |v:termstyleresp| and |v:termblinkresp| for the response to |
| 11414 | |t_RS| and |t_RC|. |
| 11415 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 11416 | Return type: dict<string> |
| 11417 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11418 | |
| 11419 | test_ functions are documented here: |test-functions-details| |
| 11420 | |
| 11421 | |
| 11422 | *timer_info()* |
| 11423 | timer_info([{id}]) |
| 11424 | Return a list with information about timers. |
| 11425 | When {id} is given only information about this timer is |
| 11426 | returned. When timer {id} does not exist an empty list is |
| 11427 | returned. |
| 11428 | When {id} is omitted information about all timers is returned. |
| 11429 | |
| 11430 | For each timer the information is stored in a |Dictionary| with |
| 11431 | these items: |
| 11432 | "id" the timer ID |
| 11433 | "time" time the timer was started with |
| 11434 | "remaining" time until the timer fires |
| 11435 | "repeat" number of times the timer will still fire; |
| 11436 | -1 means forever |
| 11437 | "callback" the callback |
| 11438 | "paused" 1 if the timer is paused, 0 otherwise |
| 11439 | |
| 11440 | Can also be used as a |method|: > |
| 11441 | GetTimer()->timer_info() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 11442 | < |
| 11443 | Return type: list<dict<any>> or list<any> |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11444 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 11445 | {only available when compiled with the |+timers| feature} |
| 11446 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11447 | |
| 11448 | timer_pause({timer}, {paused}) *timer_pause()* |
| 11449 | Pause or unpause a timer. A paused timer does not invoke its |
| 11450 | callback when its time expires. Unpausing a timer may cause |
| 11451 | the callback to be invoked almost immediately if enough time |
| 11452 | has passed. |
| 11453 | |
| 11454 | Pausing a timer is useful to avoid the callback to be called |
| 11455 | for a short time. |
| 11456 | |
| 11457 | If {paused} evaluates to a non-zero Number or a non-empty |
| 11458 | String, then the timer is paused, otherwise it is unpaused. |
| 11459 | See |non-zero-arg|. |
| 11460 | |
| 11461 | Can also be used as a |method|: > |
| 11462 | GetTimer()->timer_pause(1) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 11463 | < |
| 11464 | Return type: |Number| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11465 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 11466 | {only available when compiled with the |+timers| feature} |
| 11467 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11468 | |
| 11469 | *timer_start()* *timer* *timers* |
| 11470 | timer_start({time}, {callback} [, {options}]) |
| 11471 | Create a timer and return the timer ID. |
| 11472 | |
| 11473 | {time} is the waiting time in milliseconds. This is the |
| 11474 | minimum time before invoking the callback. When the system is |
| 11475 | busy or Vim is not waiting for input the time will be longer. |
Bram Moolenaar | dd60c36 | 2023-02-27 15:49:53 +0000 | [diff] [blame] | 11476 | Zero can be used to execute the callback when Vim is back in |
| 11477 | the main loop. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11478 | |
| 11479 | {callback} is the function to call. It can be the name of a |
| 11480 | function or a |Funcref|. It is called with one argument, which |
| 11481 | is the timer ID. The callback is only invoked when Vim is |
| 11482 | waiting for input. |
| 11483 | If you want to show a message look at |popup_notification()| |
| 11484 | to avoid interfering with what the user is doing. |
| 11485 | |
| 11486 | {options} is a dictionary. Supported entries: |
| 11487 | "repeat" Number of times to repeat calling the |
| 11488 | callback. -1 means forever. When not present |
| 11489 | the callback will be called once. |
| 11490 | If the timer causes an error three times in a |
| 11491 | row the repeat is cancelled. This avoids that |
| 11492 | Vim becomes unusable because of all the error |
| 11493 | messages. |
| 11494 | |
Bram Moolenaar | d592deb | 2022-06-17 15:42:40 +0100 | [diff] [blame] | 11495 | Returns -1 on error. |
| 11496 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11497 | Example: > |
| 11498 | func MyHandler(timer) |
| 11499 | echo 'Handler called' |
| 11500 | endfunc |
| 11501 | let timer = timer_start(500, 'MyHandler', |
| 11502 | \ {'repeat': 3}) |
| 11503 | < This will invoke MyHandler() three times at 500 msec |
| 11504 | intervals. |
| 11505 | |
| 11506 | Can also be used as a |method|: > |
| 11507 | GetMsec()->timer_start(callback) |
| 11508 | |
| 11509 | < Not available in the |sandbox|. |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 11510 | |
| 11511 | Return type: |Number| |
| 11512 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11513 | {only available when compiled with the |+timers| feature} |
| 11514 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 11515 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11516 | timer_stop({timer}) *timer_stop()* |
| 11517 | Stop a timer. The timer callback will no longer be invoked. |
| 11518 | {timer} is an ID returned by timer_start(), thus it must be a |
| 11519 | Number. If {timer} does not exist there is no error. |
| 11520 | |
| 11521 | Can also be used as a |method|: > |
| 11522 | GetTimer()->timer_stop() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 11523 | < |
| 11524 | Return type: |Number| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11525 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 11526 | {only available when compiled with the |+timers| feature} |
| 11527 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11528 | |
| 11529 | timer_stopall() *timer_stopall()* |
| 11530 | Stop all timers. The timer callbacks will no longer be |
| 11531 | invoked. Useful if a timer is misbehaving. If there are no |
| 11532 | timers there is no error. |
| 11533 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 11534 | Return type: |Number| |
| 11535 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11536 | {only available when compiled with the |+timers| feature} |
| 11537 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 11538 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11539 | tolower({expr}) *tolower()* |
| 11540 | The result is a copy of the String given, with all uppercase |
| 11541 | characters turned into lowercase (just like applying |gu| to |
Bram Moolenaar | d592deb | 2022-06-17 15:42:40 +0100 | [diff] [blame] | 11542 | the string). Returns an empty string on error. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11543 | |
| 11544 | Can also be used as a |method|: > |
| 11545 | GetText()->tolower() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 11546 | < |
| 11547 | Return type: |String| |
| 11548 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11549 | |
| 11550 | toupper({expr}) *toupper()* |
| 11551 | The result is a copy of the String given, with all lowercase |
| 11552 | characters turned into uppercase (just like applying |gU| to |
Bram Moolenaar | d592deb | 2022-06-17 15:42:40 +0100 | [diff] [blame] | 11553 | the string). Returns an empty string on error. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11554 | |
| 11555 | Can also be used as a |method|: > |
| 11556 | GetText()->toupper() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 11557 | < |
| 11558 | Return type: |String| |
| 11559 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11560 | |
| 11561 | tr({src}, {fromstr}, {tostr}) *tr()* |
| 11562 | The result is a copy of the {src} string with all characters |
| 11563 | which appear in {fromstr} replaced by the character in that |
| 11564 | position in the {tostr} string. Thus the first character in |
| 11565 | {fromstr} is translated into the first character in {tostr} |
| 11566 | and so on. Exactly like the unix "tr" command. |
| 11567 | This code also deals with multibyte characters properly. |
| 11568 | |
Bram Moolenaar | d592deb | 2022-06-17 15:42:40 +0100 | [diff] [blame] | 11569 | Returns an empty string on error. |
| 11570 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11571 | Examples: > |
| 11572 | echo tr("hello there", "ht", "HT") |
| 11573 | < returns "Hello THere" > |
| 11574 | echo tr("<blob>", "<>", "{}") |
| 11575 | < returns "{blob}" |
| 11576 | |
| 11577 | Can also be used as a |method|: > |
| 11578 | GetText()->tr(from, to) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 11579 | < |
| 11580 | Return type: |String| |
| 11581 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11582 | |
| 11583 | trim({text} [, {mask} [, {dir}]]) *trim()* |
| 11584 | Return {text} as a String where any character in {mask} is |
| 11585 | removed from the beginning and/or end of {text}. |
| 11586 | |
Illia Bobyr | 8079917 | 2023-10-17 18:00:50 +0200 | [diff] [blame] | 11587 | If {mask} is not given, or is an empty string, {mask} is all |
| 11588 | characters up to 0x20, which includes Tab, space, NL and CR, |
| 11589 | plus the non-breaking space character 0xa0. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11590 | |
| 11591 | The optional {dir} argument specifies where to remove the |
| 11592 | characters: |
| 11593 | 0 remove from the beginning and end of {text} |
| 11594 | 1 remove only at the beginning of {text} |
| 11595 | 2 remove only at the end of {text} |
| 11596 | When omitted both ends are trimmed. |
| 11597 | |
| 11598 | This function deals with multibyte characters properly. |
Bram Moolenaar | d592deb | 2022-06-17 15:42:40 +0100 | [diff] [blame] | 11599 | Returns an empty string on error. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11600 | |
| 11601 | Examples: > |
| 11602 | echo trim(" some text ") |
| 11603 | < returns "some text" > |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 11604 | echo trim(" \r\t\t\r RESERVE \t\n\x0B\xA0") .. "_TAIL" |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11605 | < returns "RESERVE_TAIL" > |
| 11606 | echo trim("rm<Xrm<>X>rrm", "rm<>") |
| 11607 | < returns "Xrm<>X" (characters in the middle are not removed) > |
| 11608 | echo trim(" vim ", " ", 2) |
| 11609 | < returns " vim" |
| 11610 | |
| 11611 | Can also be used as a |method|: > |
| 11612 | GetText()->trim() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 11613 | < |
| 11614 | Return type: |String| |
| 11615 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11616 | |
| 11617 | trunc({expr}) *trunc()* |
| 11618 | Return the largest integral value with magnitude less than or |
| 11619 | equal to {expr} as a |Float| (truncate towards zero). |
| 11620 | {expr} must evaluate to a |Float| or a |Number|. |
Bram Moolenaar | d592deb | 2022-06-17 15:42:40 +0100 | [diff] [blame] | 11621 | Returns 0.0 if {expr} is not a |Float| or a |Number|. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11622 | Examples: > |
| 11623 | echo trunc(1.456) |
| 11624 | < 1.0 > |
| 11625 | echo trunc(-5.456) |
| 11626 | < -5.0 > |
| 11627 | echo trunc(4.0) |
| 11628 | < 4.0 |
| 11629 | |
| 11630 | Can also be used as a |method|: > |
| 11631 | Compute()->trunc() |
| 11632 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 11633 | Return type: |Float| |
| 11634 | |
| 11635 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11636 | *type()* |
| 11637 | type({expr}) The result is a Number representing the type of {expr}. |
| 11638 | Instead of using the number directly, it is better to use the |
| 11639 | v:t_ variable that has the value: |
| 11640 | Number: 0 |v:t_number| |
| 11641 | String: 1 |v:t_string| |
| 11642 | Funcref: 2 |v:t_func| |
| 11643 | List: 3 |v:t_list| |
| 11644 | Dictionary: 4 |v:t_dict| |
| 11645 | Float: 5 |v:t_float| |
| 11646 | Boolean: 6 |v:t_bool| (v:false and v:true) |
| 11647 | None: 7 |v:t_none| (v:null and v:none) |
| 11648 | Job: 8 |v:t_job| |
| 11649 | Channel: 9 |v:t_channel| |
| 11650 | Blob: 10 |v:t_blob| |
h_east | 596a9f2 | 2023-11-21 21:24:23 +0900 | [diff] [blame] | 11651 | Class: 12 |v:t_class| |
| 11652 | Object: 13 |v:t_object| |
Yegappan Lakshmanan | 2a71b54 | 2023-12-14 20:03:03 +0100 | [diff] [blame] | 11653 | Typealias: 14 |v:t_typealias| |
Yegappan Lakshmanan | 3164cf8 | 2024-03-28 10:36:42 +0100 | [diff] [blame] | 11654 | Enum: 15 |v:t_enum| |
| 11655 | EnumValue: 16 |v:t_enumvalue| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11656 | For backward compatibility, this method can be used: > |
| 11657 | :if type(myvar) == type(0) |
| 11658 | :if type(myvar) == type("") |
| 11659 | :if type(myvar) == type(function("tr")) |
| 11660 | :if type(myvar) == type([]) |
| 11661 | :if type(myvar) == type({}) |
| 11662 | :if type(myvar) == type(0.0) |
| 11663 | :if type(myvar) == type(v:false) |
| 11664 | :if type(myvar) == type(v:none) |
| 11665 | < To check if the v:t_ variables exist use this: > |
| 11666 | :if exists('v:t_number') |
| 11667 | |
| 11668 | < Can also be used as a |method|: > |
| 11669 | mylist->type() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 11670 | < |
| 11671 | Return type: |Number| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11672 | |
| 11673 | |
| 11674 | typename({expr}) *typename()* |
| 11675 | Return a string representation of the type of {expr}. |
| 11676 | Example: > |
| 11677 | echo typename([1, 2, 3]) |
Kota Kato | 66bb9ae | 2023-01-17 18:31:56 +0000 | [diff] [blame] | 11678 | < list<number> ~ |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11679 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 11680 | Return type: |String| |
| 11681 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11682 | |
| 11683 | undofile({name}) *undofile()* |
| 11684 | Return the name of the undo file that would be used for a file |
| 11685 | with name {name} when writing. This uses the 'undodir' |
| 11686 | option, finding directories that exist. It does not check if |
| 11687 | the undo file exists. |
| 11688 | {name} is always expanded to the full path, since that is what |
| 11689 | is used internally. |
| 11690 | If {name} is empty undofile() returns an empty string, since a |
| 11691 | buffer without a file name will not write an undo file. |
| 11692 | Useful in combination with |:wundo| and |:rundo|. |
| 11693 | When compiled without the |+persistent_undo| option this always |
| 11694 | returns an empty string. |
| 11695 | |
| 11696 | Can also be used as a |method|: > |
| 11697 | GetFilename()->undofile() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 11698 | < |
| 11699 | Return type: |String| |
| 11700 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11701 | |
Devin J. Pohly | 5fee111 | 2023-04-23 20:26:59 -0500 | [diff] [blame] | 11702 | undotree([{buf}]) *undotree()* |
| 11703 | Return the current state of the undo tree for the current |
| 11704 | buffer, or for a specific buffer if {buf} is given. The |
| 11705 | result is a dictionary with the following items: |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11706 | "seq_last" The highest undo sequence number used. |
| 11707 | "seq_cur" The sequence number of the current position in |
| 11708 | the undo tree. This differs from "seq_last" |
| 11709 | when some changes were undone. |
| 11710 | "time_cur" Time last used for |:earlier| and related |
| 11711 | commands. Use |strftime()| to convert to |
| 11712 | something readable. |
| 11713 | "save_last" Number of the last file write. Zero when no |
| 11714 | write yet. |
| 11715 | "save_cur" Number of the current position in the undo |
| 11716 | tree. |
| 11717 | "synced" Non-zero when the last undo block was synced. |
| 11718 | This happens when waiting from input from the |
| 11719 | user. See |undo-blocks|. |
| 11720 | "entries" A list of dictionaries with information about |
| 11721 | undo blocks. |
| 11722 | |
| 11723 | The first item in the "entries" list is the oldest undo item. |
| 11724 | Each List item is a |Dictionary| with these items: |
| 11725 | "seq" Undo sequence number. Same as what appears in |
| 11726 | |:undolist|. |
| 11727 | "time" Timestamp when the change happened. Use |
| 11728 | |strftime()| to convert to something readable. |
| 11729 | "newhead" Only appears in the item that is the last one |
| 11730 | that was added. This marks the last change |
| 11731 | and where further changes will be added. |
| 11732 | "curhead" Only appears in the item that is the last one |
| 11733 | that was undone. This marks the current |
| 11734 | position in the undo tree, the block that will |
| 11735 | be used by a redo command. When nothing was |
| 11736 | undone after the last change this item will |
| 11737 | not appear anywhere. |
| 11738 | "save" Only appears on the last block before a file |
| 11739 | write. The number is the write count. The |
| 11740 | first write has number 1, the last one the |
| 11741 | "save_last" mentioned above. |
| 11742 | "alt" Alternate entry. This is again a List of undo |
| 11743 | blocks. Each item may again have an "alt" |
| 11744 | item. |
| 11745 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 11746 | Return type: dict<any> |
| 11747 | |
| 11748 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11749 | uniq({list} [, {func} [, {dict}]]) *uniq()* *E882* |
| 11750 | Remove second and succeeding copies of repeated adjacent |
| 11751 | {list} items in-place. Returns {list}. If you want a list |
| 11752 | to remain unmodified make a copy first: > |
| 11753 | :let newlist = uniq(copy(mylist)) |
| 11754 | < The default compare function uses the string representation of |
| 11755 | each item. For the use of {func} and {dict} see |sort()|. |
| 11756 | |
Bram Moolenaar | d592deb | 2022-06-17 15:42:40 +0100 | [diff] [blame] | 11757 | Returns zero if {list} is not a |List|. |
| 11758 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11759 | Can also be used as a |method|: > |
| 11760 | mylist->uniq() |
Christian Brabandt | 67672ef | 2023-04-24 21:09:54 +0100 | [diff] [blame] | 11761 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 11762 | Return type: list<{type}> |
| 11763 | |
| 11764 | |
Christian Brabandt | 67672ef | 2023-04-24 21:09:54 +0100 | [diff] [blame] | 11765 | *utf16idx()* |
| 11766 | utf16idx({string}, {idx} [, {countcc} [, {charidx}]]) |
Yegappan Lakshmanan | 577922b | 2023-06-08 17:09:45 +0100 | [diff] [blame] | 11767 | Same as |charidx()| but returns the UTF-16 code unit index of |
| 11768 | the byte at {idx} in {string} (after converting it to UTF-16). |
Christian Brabandt | 67672ef | 2023-04-24 21:09:54 +0100 | [diff] [blame] | 11769 | |
| 11770 | When {charidx} is present and TRUE, {idx} is used as the |
| 11771 | character index in the String {string} instead of as the byte |
| 11772 | index. |
Yegappan Lakshmanan | 9570703 | 2023-06-14 13:10:15 +0100 | [diff] [blame] | 11773 | An {idx} in the middle of a UTF-8 sequence is rounded |
| 11774 | downwards to the beginning of that sequence. |
Christian Brabandt | 67672ef | 2023-04-24 21:09:54 +0100 | [diff] [blame] | 11775 | |
Yegappan Lakshmanan | 577922b | 2023-06-08 17:09:45 +0100 | [diff] [blame] | 11776 | Returns -1 if the arguments are invalid or if there are less |
| 11777 | than {idx} bytes in {string}. If there are exactly {idx} bytes |
| 11778 | the length of the string in UTF-16 code units is returned. |
| 11779 | |
Christian Brabandt | 67672ef | 2023-04-24 21:09:54 +0100 | [diff] [blame] | 11780 | See |byteidx()| and |byteidxcomp()| for getting the byte index |
| 11781 | from the UTF-16 index and |charidx()| for getting the |
| 11782 | character index from the UTF-16 index. |
| 11783 | Refer to |string-offset-encoding| for more information. |
| 11784 | Examples: > |
| 11785 | echo utf16idx('a😊😊', 3) returns 2 |
| 11786 | echo utf16idx('a😊😊', 7) returns 4 |
| 11787 | echo utf16idx('a😊😊', 1, 0, 1) returns 2 |
| 11788 | echo utf16idx('a😊😊', 2, 0, 1) returns 4 |
| 11789 | echo utf16idx('aą́c', 6) returns 2 |
| 11790 | echo utf16idx('aą́c', 6, 1) returns 4 |
| 11791 | echo utf16idx('a😊😊', 9) returns -1 |
| 11792 | < |
| 11793 | Can also be used as a |method|: > |
| 11794 | GetName()->utf16idx(idx) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 11795 | < |
| 11796 | Return type: |Number| |
Christian Brabandt | 67672ef | 2023-04-24 21:09:54 +0100 | [diff] [blame] | 11797 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11798 | |
| 11799 | values({dict}) *values()* |
| 11800 | Return a |List| with all the values of {dict}. The |List| is |
| 11801 | in arbitrary order. Also see |items()| and |keys()|. |
Bram Moolenaar | d592deb | 2022-06-17 15:42:40 +0100 | [diff] [blame] | 11802 | Returns zero if {dict} is not a |Dict|. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11803 | |
| 11804 | Can also be used as a |method|: > |
| 11805 | mydict->values() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 11806 | < |
| 11807 | Return type: list<any> |
| 11808 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11809 | |
zeertzjq | 825cf81 | 2023-08-17 22:55:25 +0200 | [diff] [blame] | 11810 | virtcol({expr} [, {list} [, {winid}]]) *virtcol()* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11811 | The result is a Number, which is the screen column of the file |
| 11812 | position given with {expr}. That is, the last screen position |
| 11813 | occupied by the character at that position, when the screen |
| 11814 | would be of unlimited width. When there is a <Tab> at the |
| 11815 | position, the returned Number will be the column at the end of |
| 11816 | the <Tab>. For example, for a <Tab> in column 1, with 'ts' |
| 11817 | set to 8, it returns 8. |conceal| is ignored. |
| 11818 | For the byte position use |col()|. |
LemonBoy | 0f7a3e1 | 2022-05-26 12:10:37 +0100 | [diff] [blame] | 11819 | |
zeertzjq | 02f3eba | 2024-06-12 20:45:24 +0200 | [diff] [blame] | 11820 | For the use of {expr} see |getpos()| and |col()|. |
zeertzjq | d353d27 | 2024-06-13 23:00:25 +0800 | [diff] [blame] | 11821 | When {expr} is "$", it means the end of the cursor line, so |
| 11822 | the result is the number of cells in the cursor line plus one. |
LemonBoy | 0f7a3e1 | 2022-05-26 12:10:37 +0100 | [diff] [blame] | 11823 | |
| 11824 | When 'virtualedit' is used {expr} can be [lnum, col, off], |
| 11825 | where "off" is the offset in screen columns from the start of |
| 11826 | the character. E.g., a position within a <Tab> or after the |
| 11827 | last character. When "off" is omitted zero is used. When |
| 11828 | Virtual editing is active in the current mode, a position |
| 11829 | beyond the end of the line can be returned. Also see |
| 11830 | |'virtualedit'| |
| 11831 | |
zeertzjq | 825cf81 | 2023-08-17 22:55:25 +0200 | [diff] [blame] | 11832 | If {list} is present and non-zero then virtcol() returns a |
| 11833 | List with the first and last screen position occupied by the |
LemonBoy | 0f7a3e1 | 2022-05-26 12:10:37 +0100 | [diff] [blame] | 11834 | character. |
| 11835 | |
zeertzjq | 825cf81 | 2023-08-17 22:55:25 +0200 | [diff] [blame] | 11836 | With the optional {winid} argument the values are obtained for |
| 11837 | that window instead of the current window. |
| 11838 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11839 | Note that only marks in the current file can be used. |
zeertzjq | 02f3eba | 2024-06-12 20:45:24 +0200 | [diff] [blame] | 11840 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11841 | Examples: > |
LemonBoy | 0f7a3e1 | 2022-05-26 12:10:37 +0100 | [diff] [blame] | 11842 | " With text "foo^Lbar" and cursor on the "^L": |
| 11843 | |
| 11844 | virtcol(".") " returns 5 |
| 11845 | virtcol(".", 1) " returns [4, 5] |
| 11846 | virtcol("$") " returns 9 |
| 11847 | |
| 11848 | " With text " there", with 't at 'h': |
| 11849 | |
| 11850 | virtcol("'t") " returns 6 |
zeertzjq | 02f3eba | 2024-06-12 20:45:24 +0200 | [diff] [blame] | 11851 | < |
| 11852 | The first column is 1. 0 or [0, 0] is returned for an error. |
| 11853 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11854 | A more advanced example that echoes the maximum length of |
| 11855 | all lines: > |
| 11856 | echo max(map(range(1, line('$')), "virtcol([v:val, '$'])")) |
| 11857 | |
| 11858 | < Can also be used as a |method|: > |
| 11859 | GetPos()->virtcol() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 11860 | < |
| 11861 | Return type: |Number| |
| 11862 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11863 | |
Bram Moolenaar | 5a6ec10 | 2022-05-27 21:58:00 +0100 | [diff] [blame] | 11864 | virtcol2col({winid}, {lnum}, {col}) *virtcol2col()* |
| 11865 | The result is a Number, which is the byte index of the |
| 11866 | character in window {winid} at buffer line {lnum} and virtual |
| 11867 | column {col}. |
| 11868 | |
zeertzjq | b583eda | 2023-10-14 11:32:28 +0200 | [diff] [blame] | 11869 | If buffer line {lnum} is an empty line, 0 is returned. |
| 11870 | |
Bram Moolenaar | 5a6ec10 | 2022-05-27 21:58:00 +0100 | [diff] [blame] | 11871 | If {col} is greater than the last virtual column in line |
| 11872 | {lnum}, then the byte index of the character at the last |
| 11873 | virtual column is returned. |
| 11874 | |
Yegappan Lakshmanan | b209b86 | 2023-08-15 23:01:44 +0200 | [diff] [blame] | 11875 | For a multi-byte character, the column number of the first |
| 11876 | byte in the character is returned. |
| 11877 | |
Bram Moolenaar | 5a6ec10 | 2022-05-27 21:58:00 +0100 | [diff] [blame] | 11878 | The {winid} argument can be the window number or the |
| 11879 | |window-ID|. If this is zero, then the current window is used. |
| 11880 | |
| 11881 | Returns -1 if the window {winid} doesn't exist or the buffer |
| 11882 | line {lnum} or virtual column {col} is invalid. |
| 11883 | |
| 11884 | See also |screenpos()|, |virtcol()| and |col()|. |
| 11885 | |
| 11886 | Can also be used as a |method|: > |
| 11887 | GetWinid()->virtcol2col(lnum, col) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 11888 | < |
| 11889 | Return type: |Number| |
| 11890 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11891 | |
| 11892 | visualmode([{expr}]) *visualmode()* |
| 11893 | The result is a String, which describes the last Visual mode |
| 11894 | used in the current buffer. Initially it returns an empty |
| 11895 | string, but once Visual mode has been used, it returns "v", |
| 11896 | "V", or "<CTRL-V>" (a single CTRL-V character) for |
| 11897 | character-wise, line-wise, or block-wise Visual mode |
| 11898 | respectively. |
| 11899 | Example: > |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 11900 | :exe "normal " .. visualmode() |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11901 | < This enters the same Visual mode as before. It is also useful |
| 11902 | in scripts if you wish to act differently depending on the |
| 11903 | Visual mode that was used. |
| 11904 | If Visual mode is active, use |mode()| to get the Visual mode |
| 11905 | (e.g., in a |:vmap|). |
| 11906 | If {expr} is supplied and it evaluates to a non-zero Number or |
| 11907 | a non-empty String, then the Visual mode will be cleared and |
| 11908 | the old value is returned. See |non-zero-arg|. |
| 11909 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 11910 | Return type: |String| |
| 11911 | |
| 11912 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11913 | wildmenumode() *wildmenumode()* |
| 11914 | Returns |TRUE| when the wildmenu is active and |FALSE| |
| 11915 | otherwise. See 'wildmenu' and 'wildmode'. |
| 11916 | This can be used in mappings to handle the 'wildcharm' option |
| 11917 | gracefully. (Makes only sense with |mapmode-c| mappings). |
| 11918 | |
| 11919 | For example to make <c-j> work like <down> in wildmode, use: > |
| 11920 | :cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>" |
| 11921 | < |
| 11922 | (Note, this needs the 'wildcharm' option set appropriately). |
| 11923 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 11924 | Return type: |Number| |
| 11925 | |
| 11926 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11927 | win_execute({id}, {command} [, {silent}]) *win_execute()* |
| 11928 | Like `execute()` but in the context of window {id}. |
| 11929 | The window will temporarily be made the current window, |
| 11930 | without triggering autocommands or changing directory. When |
| 11931 | executing {command} autocommands will be triggered, this may |
Bram Moolenaar | b7398fe | 2023-05-14 18:50:25 +0100 | [diff] [blame] | 11932 | have unexpected side effects. Use `:noautocmd` if needed. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11933 | Example: > |
| 11934 | call win_execute(winid, 'set syntax=python') |
| 11935 | < Doing the same with `setwinvar()` would not trigger |
| 11936 | autocommands and not actually show syntax highlighting. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11937 | *E994* |
| 11938 | Not all commands are allowed in popup windows. |
| 11939 | When window {id} does not exist then no error is given and |
| 11940 | an empty string is returned. |
| 11941 | |
| 11942 | Can also be used as a |method|, the base is passed as the |
| 11943 | second argument: > |
| 11944 | GetCommand()->win_execute(winid) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 11945 | < |
| 11946 | Return type: |String| |
| 11947 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11948 | |
| 11949 | win_findbuf({bufnr}) *win_findbuf()* |
| 11950 | Returns a |List| with |window-ID|s for windows that contain |
| 11951 | buffer {bufnr}. When there is none the list is empty. |
| 11952 | |
| 11953 | Can also be used as a |method|: > |
| 11954 | GetBufnr()->win_findbuf() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 11955 | < |
| 11956 | Return type: list<number> or list<any> |
| 11957 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11958 | |
| 11959 | win_getid([{win} [, {tab}]]) *win_getid()* |
| 11960 | Get the |window-ID| for the specified window. |
| 11961 | When {win} is missing use the current window. |
| 11962 | With {win} this is the window number. The top window has |
| 11963 | number 1. |
| 11964 | Without {tab} use the current tab, otherwise the tab with |
| 11965 | number {tab}. The first tab has number one. |
| 11966 | Return zero if the window cannot be found. |
| 11967 | |
| 11968 | Can also be used as a |method|: > |
| 11969 | GetWinnr()->win_getid() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 11970 | < |
| 11971 | Return type: |Number| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 11972 | |
| 11973 | |
| 11974 | win_gettype([{nr}]) *win_gettype()* |
| 11975 | Return the type of the window: |
| 11976 | "autocmd" autocommand window. Temporary window |
| 11977 | used to execute autocommands. |
| 11978 | "command" command-line window |cmdwin| |
| 11979 | (empty) normal window |
| 11980 | "loclist" |location-list-window| |
| 11981 | "popup" popup window |popup| |
| 11982 | "preview" preview window |preview-window| |
| 11983 | "quickfix" |quickfix-window| |
| 11984 | "unknown" window {nr} not found |
| 11985 | |
| 11986 | When {nr} is omitted return the type of the current window. |
| 11987 | When {nr} is given return the type of this window by number or |
| 11988 | |window-ID|. |
| 11989 | |
| 11990 | Also see the 'buftype' option. When running a terminal in a |
| 11991 | popup window then 'buftype' is "terminal" and win_gettype() |
| 11992 | returns "popup". |
| 11993 | |
| 11994 | Can also be used as a |method|: > |
| 11995 | GetWinid()->win_gettype() |
| 11996 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 11997 | Return type: |String| |
| 11998 | |
| 11999 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12000 | win_gotoid({expr}) *win_gotoid()* |
| 12001 | Go to window with ID {expr}. This may also change the current |
| 12002 | tabpage. |
| 12003 | Return TRUE if successful, FALSE if the window cannot be found. |
| 12004 | |
| 12005 | Can also be used as a |method|: > |
| 12006 | GetWinid()->win_gotoid() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 12007 | < |
| 12008 | Return type: |Number| |
| 12009 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12010 | |
| 12011 | win_id2tabwin({expr}) *win_id2tabwin()* |
| 12012 | Return a list with the tab number and window number of window |
| 12013 | with ID {expr}: [tabnr, winnr]. |
| 12014 | Return [0, 0] if the window cannot be found. |
| 12015 | |
| 12016 | Can also be used as a |method|: > |
| 12017 | GetWinid()->win_id2tabwin() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 12018 | < |
| 12019 | Return type: list<number> |
| 12020 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12021 | |
| 12022 | win_id2win({expr}) *win_id2win()* |
| 12023 | Return the window number of window with ID {expr}. |
| 12024 | Return 0 if the window cannot be found in the current tabpage. |
| 12025 | |
| 12026 | Can also be used as a |method|: > |
| 12027 | GetWinid()->win_id2win() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 12028 | < |
| 12029 | Return type: |Number| |
| 12030 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12031 | |
Daniel Steinberg | ee63031 | 2022-01-10 13:36:34 +0000 | [diff] [blame] | 12032 | win_move_separator({nr}, {offset}) *win_move_separator()* |
| 12033 | Move window {nr}'s vertical separator (i.e., the right border) |
| 12034 | by {offset} columns, as if being dragged by the mouse. {nr} |
| 12035 | can be a window number or |window-ID|. A positive {offset} |
| 12036 | moves right and a negative {offset} moves left. Moving a |
| 12037 | window's vertical separator will change the width of the |
| 12038 | window and the width of other windows adjacent to the vertical |
| 12039 | separator. The magnitude of movement may be smaller than |
| 12040 | specified (e.g., as a consequence of maintaining |
| 12041 | 'winminwidth'). Returns TRUE if the window can be found and |
| 12042 | FALSE otherwise. |
Bram Moolenaar | d592deb | 2022-06-17 15:42:40 +0100 | [diff] [blame] | 12043 | This will fail for the rightmost window and a full-width |
| 12044 | window, since it has no separator on the right. |
Bram Moolenaar | 76db9e0 | 2022-11-09 21:21:04 +0000 | [diff] [blame] | 12045 | Only works for the current tab page. *E1308* |
Daniel Steinberg | ee63031 | 2022-01-10 13:36:34 +0000 | [diff] [blame] | 12046 | |
| 12047 | Can also be used as a |method|: > |
| 12048 | GetWinnr()->win_move_separator(offset) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 12049 | < |
| 12050 | Return type: |Number| |
| 12051 | |
Daniel Steinberg | ee63031 | 2022-01-10 13:36:34 +0000 | [diff] [blame] | 12052 | |
| 12053 | win_move_statusline({nr}, {offset}) *win_move_statusline()* |
| 12054 | Move window {nr}'s status line (i.e., the bottom border) by |
| 12055 | {offset} rows, as if being dragged by the mouse. {nr} can be a |
| 12056 | window number or |window-ID|. A positive {offset} moves down |
| 12057 | and a negative {offset} moves up. Moving a window's status |
| 12058 | line will change the height of the window and the height of |
| 12059 | other windows adjacent to the status line. The magnitude of |
| 12060 | movement may be smaller than specified (e.g., as a consequence |
| 12061 | of maintaining 'winminheight'). Returns TRUE if the window can |
| 12062 | be found and FALSE otherwise. |
Bram Moolenaar | 76db9e0 | 2022-11-09 21:21:04 +0000 | [diff] [blame] | 12063 | Only works for the current tab page. |
Daniel Steinberg | ee63031 | 2022-01-10 13:36:34 +0000 | [diff] [blame] | 12064 | |
| 12065 | Can also be used as a |method|: > |
| 12066 | GetWinnr()->win_move_statusline(offset) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 12067 | < |
| 12068 | Return type: |Number| |
| 12069 | |
Daniel Steinberg | ee63031 | 2022-01-10 13:36:34 +0000 | [diff] [blame] | 12070 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12071 | win_screenpos({nr}) *win_screenpos()* |
| 12072 | Return the screen position of window {nr} as a list with two |
| 12073 | numbers: [row, col]. The first window always has position |
| 12074 | [1, 1], unless there is a tabline, then it is [2, 1]. |
| 12075 | {nr} can be the window number or the |window-ID|. Use zero |
| 12076 | for the current window. |
Sean Dewar | 5866bc3 | 2024-03-13 20:17:24 +0100 | [diff] [blame] | 12077 | Returns [0, 0] if the window cannot be found. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12078 | |
| 12079 | Can also be used as a |method|: > |
| 12080 | GetWinid()->win_screenpos() |
| 12081 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 12082 | Return type: list<number> |
| 12083 | |
| 12084 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12085 | win_splitmove({nr}, {target} [, {options}]) *win_splitmove()* |
Sean Dewar | 96cc4ae | 2024-02-20 21:52:31 +0100 | [diff] [blame] | 12086 | Temporarily switch to window {target}, then move window {nr} |
| 12087 | to a new split adjacent to {target}. |
| 12088 | Unlike commands such as |:split|, no new windows are created |
| 12089 | (the |window-ID| of window {nr} is unchanged after the move). |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12090 | |
| 12091 | Both {nr} and {target} can be window numbers or |window-ID|s. |
| 12092 | Both must be in the current tab page. |
| 12093 | |
| 12094 | Returns zero for success, non-zero for failure. |
| 12095 | |
| 12096 | {options} is a |Dictionary| with the following optional entries: |
| 12097 | "vertical" When TRUE, the split is created vertically, |
| 12098 | like with |:vsplit|. |
| 12099 | "rightbelow" When TRUE, the split is made below or to the |
| 12100 | right (if vertical). When FALSE, it is done |
| 12101 | above or to the left (if vertical). When not |
| 12102 | present, the values of 'splitbelow' and |
| 12103 | 'splitright' are used. |
| 12104 | |
| 12105 | Can also be used as a |method|: > |
| 12106 | GetWinid()->win_splitmove(target) |
| 12107 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 12108 | Return type: |Number| |
| 12109 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12110 | |
| 12111 | *winbufnr()* |
| 12112 | winbufnr({nr}) The result is a Number, which is the number of the buffer |
| 12113 | associated with window {nr}. {nr} can be the window number or |
| 12114 | the |window-ID|. |
| 12115 | When {nr} is zero, the number of the buffer in the current |
| 12116 | window is returned. |
| 12117 | When window {nr} doesn't exist, -1 is returned. |
| 12118 | Example: > |
| 12119 | :echo "The file in the current window is " . bufname(winbufnr(0)) |
| 12120 | < |
| 12121 | Can also be used as a |method|: > |
| 12122 | FindWindow()->winbufnr()->bufname() |
| 12123 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 12124 | Return type: |Number| |
| 12125 | |
| 12126 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12127 | *wincol()* |
| 12128 | wincol() The result is a Number, which is the virtual column of the |
| 12129 | cursor in the window. This is counting screen cells from the |
| 12130 | left side of the window. The leftmost column is one. |
| 12131 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 12132 | Return type: |Number| |
| 12133 | |
| 12134 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12135 | *windowsversion()* |
| 12136 | windowsversion() |
| 12137 | The result is a String. For MS-Windows it indicates the OS |
| 12138 | version. E.g, Windows 10 is "10.0", Windows 8 is "6.2", |
| 12139 | Windows XP is "5.1". For non-MS-Windows systems the result is |
| 12140 | an empty string. |
| 12141 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 12142 | Return type: |String| |
| 12143 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12144 | winheight({nr}) *winheight()* |
| 12145 | The result is a Number, which is the height of window {nr}. |
| 12146 | {nr} can be the window number or the |window-ID|. |
| 12147 | When {nr} is zero, the height of the current window is |
| 12148 | returned. When window {nr} doesn't exist, -1 is returned. |
| 12149 | An existing window always has a height of zero or more. |
| 12150 | This excludes any window toolbar line. |
| 12151 | Examples: > |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 12152 | :echo "The current window has " .. winheight(0) .. " lines." |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12153 | |
| 12154 | < Can also be used as a |method|: > |
| 12155 | GetWinid()->winheight() |
| 12156 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 12157 | Return type: |Number| |
| 12158 | |
| 12159 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12160 | winlayout([{tabnr}]) *winlayout()* |
| 12161 | The result is a nested List containing the layout of windows |
| 12162 | in a tabpage. |
| 12163 | |
| 12164 | Without {tabnr} use the current tabpage, otherwise the tabpage |
| 12165 | with number {tabnr}. If the tabpage {tabnr} is not found, |
| 12166 | returns an empty list. |
| 12167 | |
| 12168 | For a leaf window, it returns: |
| 12169 | ['leaf', {winid}] |
| 12170 | For horizontally split windows, which form a column, it |
| 12171 | returns: |
| 12172 | ['col', [{nested list of windows}]] |
| 12173 | For vertically split windows, which form a row, it returns: |
| 12174 | ['row', [{nested list of windows}]] |
| 12175 | |
| 12176 | Example: > |
| 12177 | " Only one window in the tab page |
| 12178 | :echo winlayout() |
| 12179 | ['leaf', 1000] |
| 12180 | " Two horizontally split windows |
| 12181 | :echo winlayout() |
| 12182 | ['col', [['leaf', 1000], ['leaf', 1001]]] |
| 12183 | " The second tab page, with three horizontally split |
| 12184 | " windows, with two vertically split windows in the |
| 12185 | " middle window |
| 12186 | :echo winlayout(2) |
| 12187 | ['col', [['leaf', 1002], ['row', [['leaf', 1003], |
| 12188 | ['leaf', 1001]]], ['leaf', 1000]]] |
| 12189 | < |
| 12190 | Can also be used as a |method|: > |
| 12191 | GetTabnr()->winlayout() |
| 12192 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 12193 | Return type: list<any> |
| 12194 | |
| 12195 | |
| 12196 | winline() *winline()* |
| 12197 | The result is a Number, which is the screen line of the cursor |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12198 | in the window. This is counting screen lines from the top of |
| 12199 | the window. The first line is one. |
| 12200 | If the cursor was moved the view on the file will be updated |
| 12201 | first, this may cause a scroll. |
| 12202 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 12203 | Return type: |Number| |
| 12204 | |
| 12205 | |
| 12206 | winnr([{arg}]) *winnr()* |
| 12207 | The result is a Number, which is the number of the current |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12208 | window. The top window has number 1. |
| 12209 | Returns zero for a popup window. |
| 12210 | |
| 12211 | The optional argument {arg} supports the following values: |
| 12212 | $ the number of the last window (the window |
| 12213 | count). |
| 12214 | # the number of the last accessed window (where |
| 12215 | |CTRL-W_p| goes to). If there is no previous |
| 12216 | window or it is in another tab page 0 is |
Sean Dewar | d64801e | 2024-03-12 20:46:12 +0100 | [diff] [blame] | 12217 | returned. May refer to the current window in |
| 12218 | some cases (e.g. when evaluating 'statusline' |
| 12219 | expressions). |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12220 | {N}j the number of the Nth window below the |
| 12221 | current window (where |CTRL-W_j| goes to). |
| 12222 | {N}k the number of the Nth window above the current |
| 12223 | window (where |CTRL-W_k| goes to). |
| 12224 | {N}h the number of the Nth window left of the |
| 12225 | current window (where |CTRL-W_h| goes to). |
| 12226 | {N}l the number of the Nth window right of the |
| 12227 | current window (where |CTRL-W_l| goes to). |
| 12228 | The number can be used with |CTRL-W_w| and ":wincmd w" |
| 12229 | |:wincmd|. |
Bram Moolenaar | 016188f | 2022-06-06 20:52:59 +0100 | [diff] [blame] | 12230 | When {arg} is invalid an error is given and zero is returned. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12231 | Also see |tabpagewinnr()| and |win_getid()|. |
| 12232 | Examples: > |
| 12233 | let window_count = winnr('$') |
| 12234 | let prev_window = winnr('#') |
| 12235 | let wnum = winnr('3k') |
| 12236 | |
| 12237 | < Can also be used as a |method|: > |
| 12238 | GetWinval()->winnr() |
| 12239 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 12240 | Return type: |Number| |
| 12241 | |
| 12242 | |
| 12243 | winrestcmd() *winrestcmd()* |
| 12244 | Returns a sequence of |:resize| commands that should restore |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12245 | the current window sizes. Only works properly when no windows |
| 12246 | are opened or closed and the current window and tab page is |
| 12247 | unchanged. |
| 12248 | Example: > |
| 12249 | :let cmd = winrestcmd() |
| 12250 | :call MessWithWindowSizes() |
| 12251 | :exe cmd |
| 12252 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 12253 | Return type: |String| |
| 12254 | |
| 12255 | |
| 12256 | winrestview({dict}) *winrestview()* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12257 | Uses the |Dictionary| returned by |winsaveview()| to restore |
| 12258 | the view of the current window. |
| 12259 | Note: The {dict} does not have to contain all values, that are |
| 12260 | returned by |winsaveview()|. If values are missing, those |
| 12261 | settings won't be restored. So you can use: > |
| 12262 | :call winrestview({'curswant': 4}) |
| 12263 | < |
| 12264 | This will only set the curswant value (the column the cursor |
| 12265 | wants to move on vertical movements) of the cursor to column 5 |
| 12266 | (yes, that is 5), while all other settings will remain the |
| 12267 | same. This is useful, if you set the cursor position manually. |
| 12268 | |
| 12269 | If you have changed the values the result is unpredictable. |
| 12270 | If the window size changed the result won't be the same. |
| 12271 | |
| 12272 | Can also be used as a |method|: > |
| 12273 | GetView()->winrestview() |
| 12274 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 12275 | Return type: |Number| |
| 12276 | |
| 12277 | |
| 12278 | winsaveview() *winsaveview()* |
| 12279 | Returns a |Dictionary| that contains information to restore |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12280 | the view of the current window. Use |winrestview()| to |
| 12281 | restore the view. |
| 12282 | This is useful if you have a mapping that jumps around in the |
| 12283 | buffer and you want to go back to the original view. |
| 12284 | This does not save fold information. Use the 'foldenable' |
| 12285 | option to temporarily switch off folding, so that folds are |
| 12286 | not opened when moving around. This may have side effects. |
| 12287 | The return value includes: |
| 12288 | lnum cursor line number |
| 12289 | col cursor column (Note: the first column |
naohiro ono | 56200ee | 2022-01-01 14:59:44 +0000 | [diff] [blame] | 12290 | zero, as opposed to what |getcurpos()| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12291 | returns) |
| 12292 | coladd cursor column offset for 'virtualedit' |
naohiro ono | 56200ee | 2022-01-01 14:59:44 +0000 | [diff] [blame] | 12293 | curswant column for vertical movement (Note: |
| 12294 | the first column is zero, as opposed |
| 12295 | to what |getcurpos()| returns). After |
| 12296 | |$| command it will be a very large |
| 12297 | number equal to |v:maxcol|. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12298 | topline first line in the window |
| 12299 | topfill filler lines, only in diff mode |
| 12300 | leftcol first column displayed; only used when |
| 12301 | 'wrap' is off |
| 12302 | skipcol columns skipped |
| 12303 | Note that no option values are saved. |
| 12304 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 12305 | Return type: dict<number> |
| 12306 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12307 | |
| 12308 | winwidth({nr}) *winwidth()* |
| 12309 | The result is a Number, which is the width of window {nr}. |
| 12310 | {nr} can be the window number or the |window-ID|. |
| 12311 | When {nr} is zero, the width of the current window is |
| 12312 | returned. When window {nr} doesn't exist, -1 is returned. |
| 12313 | An existing window always has a width of zero or more. |
| 12314 | Examples: > |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 12315 | :echo "The current window has " .. winwidth(0) .. " columns." |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12316 | :if winwidth(0) <= 50 |
| 12317 | : 50 wincmd | |
| 12318 | :endif |
| 12319 | < For getting the terminal or screen size, see the 'columns' |
| 12320 | option. |
| 12321 | |
| 12322 | Can also be used as a |method|: > |
| 12323 | GetWinid()->winwidth() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 12324 | < |
| 12325 | Return type: |Number| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12326 | |
| 12327 | |
| 12328 | wordcount() *wordcount()* |
| 12329 | The result is a dictionary of byte/chars/word statistics for |
| 12330 | the current buffer. This is the same info as provided by |
| 12331 | |g_CTRL-G| |
| 12332 | The return value includes: |
| 12333 | bytes Number of bytes in the buffer |
| 12334 | chars Number of chars in the buffer |
| 12335 | words Number of words in the buffer |
| 12336 | cursor_bytes Number of bytes before cursor position |
| 12337 | (not in Visual mode) |
| 12338 | cursor_chars Number of chars before cursor position |
| 12339 | (not in Visual mode) |
| 12340 | cursor_words Number of words before cursor position |
| 12341 | (not in Visual mode) |
| 12342 | visual_bytes Number of bytes visually selected |
| 12343 | (only in Visual mode) |
| 12344 | visual_chars Number of chars visually selected |
| 12345 | (only in Visual mode) |
| 12346 | visual_words Number of words visually selected |
| 12347 | (only in Visual mode) |
| 12348 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 12349 | Return type: dict<number> |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12350 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 12351 | |
| 12352 | writefile({object}, {fname} [, {flags}]) *writefile()* |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12353 | When {object} is a |List| write it to file {fname}. Each list |
| 12354 | item is separated with a NL. Each list item must be a String |
| 12355 | or Number. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12356 | All NL characters are replaced with a NUL character. |
| 12357 | Inserting CR characters needs to be done before passing {list} |
| 12358 | to writefile(). |
Bram Moolenaar | 806a273 | 2022-09-04 15:40:36 +0100 | [diff] [blame] | 12359 | |
| 12360 | When {object} is a |Blob| write the bytes to file {fname} |
| 12361 | unmodified, also when binary mode is not specified. |
| 12362 | |
| 12363 | {flags} must be a String. These characters are recognized: |
| 12364 | |
| 12365 | 'b' Binary mode is used: There will not be a NL after the |
| 12366 | last list item. An empty item at the end does cause the |
| 12367 | last line in the file to end in a NL. |
| 12368 | |
| 12369 | 'a' Append mode is used, lines are appended to the file: > |
| 12370 | :call writefile(["foo"], "event.log", "a") |
| 12371 | :call writefile(["bar"], "event.log", "a") |
| 12372 | < |
| 12373 | 'D' Delete the file when the current function ends. This |
| 12374 | works like: > |
Bram Moolenaar | 938ae28 | 2023-02-20 20:44:55 +0000 | [diff] [blame] | 12375 | :defer delete({fname}) |
Bram Moolenaar | 806a273 | 2022-09-04 15:40:36 +0100 | [diff] [blame] | 12376 | < Fails when not in a function. Also see |:defer|. |
| 12377 | |
| 12378 | 's' fsync() is called after writing the file. This flushes |
| 12379 | the file to disk, if possible. This takes more time but |
| 12380 | avoids losing the file if the system crashes. |
| 12381 | |
| 12382 | 'S' fsync() is not called, even when 'fsync' is set. |
| 12383 | |
| 12384 | When {flags} does not contain "S" or "s" then fsync() is |
| 12385 | called if the 'fsync' option is set. |
| 12386 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12387 | An existing file is overwritten, if possible. |
Bram Moolenaar | 806a273 | 2022-09-04 15:40:36 +0100 | [diff] [blame] | 12388 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12389 | When the write fails -1 is returned, otherwise 0. There is an |
| 12390 | error message if the file can't be created or when writing |
| 12391 | fails. |
Bram Moolenaar | 806a273 | 2022-09-04 15:40:36 +0100 | [diff] [blame] | 12392 | |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12393 | Also see |readfile()|. |
| 12394 | To copy a file byte for byte: > |
| 12395 | :let fl = readfile("foo", "b") |
| 12396 | :call writefile(fl, "foocopy", "b") |
| 12397 | |
| 12398 | < Can also be used as a |method|: > |
| 12399 | GetText()->writefile("thefile") |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 12400 | < |
| 12401 | Return type: |Number| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12402 | |
| 12403 | |
| 12404 | xor({expr}, {expr}) *xor()* |
| 12405 | Bitwise XOR on the two arguments. The arguments are converted |
| 12406 | to a number. A List, Dict or Float argument causes an error. |
Bram Moolenaar | 5a6ec10 | 2022-05-27 21:58:00 +0100 | [diff] [blame] | 12407 | Also see `and()` and `or()`. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12408 | Example: > |
| 12409 | :let bits = xor(bits, 0x80) |
| 12410 | < |
| 12411 | Can also be used as a |method|: > |
| 12412 | :let bits = bits->xor(0x80) |
| 12413 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 12414 | Return type: |Number| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12415 | |
| 12416 | ============================================================================== |
| 12417 | 3. Feature list *feature-list* |
| 12418 | |
| 12419 | There are three types of features: |
| 12420 | 1. Features that are only supported when they have been enabled when Vim |
| 12421 | was compiled |+feature-list|. Example: > |
| 12422 | :if has("cindent") |
| 12423 | < *gui_running* |
| 12424 | 2. Features that are only supported when certain conditions have been met. |
| 12425 | Example: > |
| 12426 | :if has("gui_running") |
| 12427 | < *has-patch* |
| 12428 | 3. Beyond a certain version or at a certain version and including a specific |
| 12429 | patch. The "patch-7.4.248" feature means that the Vim version is 7.5 or |
| 12430 | later, or it is version 7.4 and patch 248 was included. Example: > |
| 12431 | :if has("patch-7.4.248") |
| 12432 | < Note that it's possible for patch 248 to be omitted even though 249 is |
| 12433 | included. Only happens when cherry-picking patches. |
| 12434 | Note that this form only works for patch 7.4.237 and later, before that |
| 12435 | you need to check for the patch and the v:version. Example (checking |
| 12436 | version 6.2.148 or later): > |
| 12437 | :if v:version > 602 || (v:version == 602 && has("patch148")) |
| 12438 | |
| 12439 | Hint: To find out if Vim supports backslashes in a file name (MS-Windows), |
| 12440 | use: `if exists('+shellslash')` |
| 12441 | |
| 12442 | |
| 12443 | acl Compiled with |ACL| support. |
Bram Moolenaar | 2ee347f | 2022-08-26 17:53:44 +0100 | [diff] [blame] | 12444 | all_builtin_terms Compiled with all builtin terminals enabled. (always |
| 12445 | true) |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12446 | amiga Amiga version of Vim. |
| 12447 | arabic Compiled with Arabic support |Arabic|. |
| 12448 | arp Compiled with ARP support (Amiga). |
| 12449 | autocmd Compiled with autocommand support. (always true) |
| 12450 | autochdir Compiled with support for 'autochdir' |
| 12451 | autoservername Automatically enable |clientserver| |
| 12452 | balloon_eval Compiled with |balloon-eval| support. |
| 12453 | balloon_multiline GUI supports multiline balloons. |
| 12454 | beos BeOS version of Vim. |
| 12455 | browse Compiled with |:browse| support, and browse() will |
| 12456 | work. |
| 12457 | browsefilter Compiled with support for |browsefilter|. |
| 12458 | bsd Compiled on an OS in the BSD family (excluding macOS). |
Bram Moolenaar | 2ee347f | 2022-08-26 17:53:44 +0100 | [diff] [blame] | 12459 | builtin_terms Compiled with some builtin terminals. (always true) |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12460 | byte_offset Compiled with support for 'o' in 'statusline' |
| 12461 | channel Compiled with support for |channel| and |job| |
Bram Moolenaar | e1dc76f | 2022-06-25 18:01:32 +0100 | [diff] [blame] | 12462 | cindent Compiled with 'cindent' support. (always true) |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12463 | clientserver Compiled with remote invocation support |clientserver|. |
| 12464 | clipboard Compiled with 'clipboard' support. |
| 12465 | clipboard_working Compiled with 'clipboard' support and it can be used. |
| 12466 | cmdline_compl Compiled with |cmdline-completion| support. |
| 12467 | cmdline_hist Compiled with |cmdline-history| support. |
| 12468 | cmdline_info Compiled with 'showcmd' and 'ruler' support. |
| 12469 | comments Compiled with |'comments'| support. |
| 12470 | compatible Compiled to be very Vi compatible. |
| 12471 | conpty Platform where |ConPTY| can be used. |
| 12472 | cryptv Compiled with encryption support |encryption|. |
| 12473 | cscope Compiled with |cscope| support. |
| 12474 | cursorbind Compiled with |'cursorbind'| (always true) |
| 12475 | debug Compiled with "DEBUG" defined. |
| 12476 | dialog_con Compiled with console dialog support. |
glepnir | df46115 | 2024-04-04 22:23:29 +0200 | [diff] [blame] | 12477 | dialog_con_gui Compiled with console and GUI dialog support. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12478 | dialog_gui Compiled with GUI dialog support. |
| 12479 | diff Compiled with |vimdiff| and 'diff' support. |
| 12480 | digraphs Compiled with support for digraphs. |
| 12481 | directx Compiled with support for DirectX and 'renderoptions'. |
| 12482 | dnd Compiled with support for the "~ register |quote_~|. |
| 12483 | drop_file Compiled with |drop_file| support. |
| 12484 | ebcdic Compiled on a machine with ebcdic character set. |
| 12485 | emacs_tags Compiled with support for Emacs tags. |
| 12486 | eval Compiled with expression evaluation support. Always |
| 12487 | true, of course! |
| 12488 | ex_extra |+ex_extra| (always true) |
| 12489 | extra_search Compiled with support for |'incsearch'| and |
| 12490 | |'hlsearch'| |
| 12491 | farsi Support for Farsi was removed |farsi|. |
Bram Moolenaar | f80f40a | 2022-08-25 16:02:23 +0100 | [diff] [blame] | 12492 | file_in_path Compiled with support for |gf| and |<cfile>| (always |
| 12493 | true) |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12494 | filterpipe When 'shelltemp' is off pipes are used for shell |
| 12495 | read/write/filter commands |
| 12496 | find_in_path Compiled with support for include file searches |
| 12497 | |+find_in_path|. |
| 12498 | float Compiled with support for |Float|. |
| 12499 | fname_case Case in file names matters (for Amiga and MS-Windows |
| 12500 | this is not present). |
| 12501 | folding Compiled with |folding| support. |
| 12502 | footer Compiled with GUI footer support. |gui-footer| |
| 12503 | fork Compiled to use fork()/exec() instead of system(). |
| 12504 | gettext Compiled with message translation |multi-lang| |
| 12505 | gui Compiled with GUI enabled. |
Bram Moolenaar | cbaff5e | 2022-04-08 17:45:08 +0100 | [diff] [blame] | 12506 | gui_athena Compiled with Athena GUI (always false). |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12507 | gui_gnome Compiled with Gnome support (gui_gtk is also defined). |
| 12508 | gui_gtk Compiled with GTK+ GUI (any version). |
| 12509 | gui_gtk2 Compiled with GTK+ 2 GUI (gui_gtk is also defined). |
| 12510 | gui_gtk3 Compiled with GTK+ 3 GUI (gui_gtk is also defined). |
| 12511 | gui_haiku Compiled with Haiku GUI. |
| 12512 | gui_mac Compiled with Macintosh GUI. |
| 12513 | gui_motif Compiled with Motif GUI. |
| 12514 | gui_photon Compiled with Photon GUI. |
| 12515 | gui_running Vim is running in the GUI, or it will start soon. |
| 12516 | gui_win32 Compiled with MS-Windows Win32 GUI. |
| 12517 | gui_win32s idem, and Win32s system being used (Windows 3.1) |
| 12518 | haiku Haiku version of Vim. |
| 12519 | hangul_input Compiled with Hangul input support. |hangul| |
| 12520 | hpux HP-UX version of Vim. |
| 12521 | iconv Can use iconv() for conversion. |
| 12522 | insert_expand Compiled with support for CTRL-X expansion commands in |
| 12523 | Insert mode. (always true) |
| 12524 | job Compiled with support for |channel| and |job| |
| 12525 | ipv6 Compiled with support for IPv6 networking in |channel|. |
Bram Moolenaar | e1dc76f | 2022-06-25 18:01:32 +0100 | [diff] [blame] | 12526 | jumplist Compiled with |jumplist| support. (always true) |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12527 | keymap Compiled with 'keymap' support. |
| 12528 | lambda Compiled with |lambda| support. |
| 12529 | langmap Compiled with 'langmap' support. |
| 12530 | libcall Compiled with |libcall()| support. |
| 12531 | linebreak Compiled with 'linebreak', 'breakat', 'showbreak' and |
| 12532 | 'breakindent' support. |
| 12533 | linux Linux version of Vim. |
| 12534 | lispindent Compiled with support for lisp indenting. |
Bram Moolenaar | e1dc76f | 2022-06-25 18:01:32 +0100 | [diff] [blame] | 12535 | (always true) |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12536 | listcmds Compiled with commands for the buffer list |:files| |
| 12537 | and the argument list |arglist|. |
| 12538 | localmap Compiled with local mappings and abbr. |:map-local| |
| 12539 | lua Compiled with Lua interface |Lua|. |
| 12540 | mac Any Macintosh version of Vim cf. osx |
| 12541 | macunix Synonym for osxdarwin |
| 12542 | menu Compiled with support for |:menu|. |
| 12543 | mksession Compiled with support for |:mksession|. |
| 12544 | modify_fname Compiled with file name modifiers. |filename-modifiers| |
| 12545 | (always true) |
| 12546 | mouse Compiled with support for mouse. |
| 12547 | mouse_dec Compiled with support for Dec terminal mouse. |
| 12548 | mouse_gpm Compiled with support for gpm (Linux console mouse) |
| 12549 | mouse_gpm_enabled GPM mouse is working |
| 12550 | mouse_netterm Compiled with support for netterm mouse. |
| 12551 | mouse_pterm Compiled with support for qnx pterm mouse. |
| 12552 | mouse_sysmouse Compiled with support for sysmouse (*BSD console mouse) |
| 12553 | mouse_sgr Compiled with support for sgr mouse. |
| 12554 | mouse_urxvt Compiled with support for urxvt mouse. |
| 12555 | mouse_xterm Compiled with support for xterm mouse. |
| 12556 | mouseshape Compiled with support for 'mouseshape'. |
| 12557 | multi_byte Compiled with support for 'encoding' (always true) |
| 12558 | multi_byte_encoding 'encoding' is set to a multibyte encoding. |
| 12559 | multi_byte_ime Compiled with support for IME input method. |
| 12560 | multi_lang Compiled with support for multiple languages. |
| 12561 | mzscheme Compiled with MzScheme interface |mzscheme|. |
| 12562 | nanotime Compiled with sub-second time stamp checks. |
| 12563 | netbeans_enabled Compiled with support for |netbeans| and connected. |
| 12564 | netbeans_intg Compiled with support for |netbeans|. |
Bram Moolenaar | e1dc76f | 2022-06-25 18:01:32 +0100 | [diff] [blame] | 12565 | num64 Compiled with 64-bit |Number| support. (always true) |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12566 | ole Compiled with OLE automation support for Win32. |
| 12567 | osx Compiled for macOS cf. mac |
| 12568 | osxdarwin Compiled for macOS, with |mac-darwin-feature| |
| 12569 | packages Compiled with |packages| support. |
| 12570 | path_extra Compiled with up/downwards search in 'path' and 'tags' |
| 12571 | perl Compiled with Perl interface. |
| 12572 | persistent_undo Compiled with support for persistent undo history. |
| 12573 | postscript Compiled with PostScript file printing. |
| 12574 | printer Compiled with |:hardcopy| support. |
| 12575 | profile Compiled with |:profile| support. |
Bram Moolenaar | 71badf9 | 2023-04-22 22:40:14 +0100 | [diff] [blame] | 12576 | prof_nsec Profile results are in nanoseconds. |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12577 | python Python 2.x interface available. |has-python| |
| 12578 | python_compiled Compiled with Python 2.x interface. |has-python| |
| 12579 | python_dynamic Python 2.x interface is dynamically loaded. |has-python| |
| 12580 | python3 Python 3.x interface available. |has-python| |
| 12581 | python3_compiled Compiled with Python 3.x interface. |has-python| |
| 12582 | python3_dynamic Python 3.x interface is dynamically loaded. |has-python| |
Yee Cheng Chin | c13b3d1 | 2023-08-20 21:18:38 +0200 | [diff] [blame] | 12583 | python3_stable Python 3.x interface is using Python Stable ABI. |has-python| |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12584 | pythonx Python 2.x and/or 3.x interface available. |python_x| |
| 12585 | qnx QNX version of Vim. |
| 12586 | quickfix Compiled with |quickfix| support. |
| 12587 | reltime Compiled with |reltime()| support. |
| 12588 | rightleft Compiled with 'rightleft' support. |
| 12589 | ruby Compiled with Ruby interface |ruby|. |
| 12590 | scrollbind Compiled with 'scrollbind' support. (always true) |
| 12591 | showcmd Compiled with 'showcmd' support. |
| 12592 | signs Compiled with |:sign| support. |
Bram Moolenaar | e1dc76f | 2022-06-25 18:01:32 +0100 | [diff] [blame] | 12593 | smartindent Compiled with 'smartindent' support. (always true) |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12594 | sodium Compiled with libsodium for better crypt support |
| 12595 | sound Compiled with sound support, e.g. `sound_playevent()` |
| 12596 | spell Compiled with spell checking support |spell|. |
| 12597 | startuptime Compiled with |--startuptime| support. |
| 12598 | statusline Compiled with support for 'statusline', 'rulerformat' |
| 12599 | and special formats of 'titlestring' and 'iconstring'. |
| 12600 | sun SunOS version of Vim. |
| 12601 | sun_workshop Support for Sun |workshop| has been removed. |
| 12602 | syntax Compiled with syntax highlighting support |syntax|. |
| 12603 | syntax_items There are active syntax highlighting items for the |
| 12604 | current buffer. |
| 12605 | system Compiled to use system() instead of fork()/exec(). |
| 12606 | tag_binary Compiled with binary searching in tags files |
Bram Moolenaar | e1dc76f | 2022-06-25 18:01:32 +0100 | [diff] [blame] | 12607 | |tag-binary-search|. (always true) |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12608 | tag_old_static Support for old static tags was removed, see |
| 12609 | |tag-old-static|. |
| 12610 | tcl Compiled with Tcl interface. |
| 12611 | termguicolors Compiled with true color in terminal support. |
| 12612 | terminal Compiled with |terminal| support. |
| 12613 | terminfo Compiled with terminfo instead of termcap. |
| 12614 | termresponse Compiled with support for |t_RV| and |v:termresponse|. |
| 12615 | textobjects Compiled with support for |text-objects|. |
| 12616 | textprop Compiled with support for |text-properties|. |
| 12617 | tgetent Compiled with tgetent support, able to use a termcap |
| 12618 | or terminfo file. |
| 12619 | timers Compiled with |timer_start()| support. |
| 12620 | title Compiled with window title support |'title'|. |
Bram Moolenaar | e1dc76f | 2022-06-25 18:01:32 +0100 | [diff] [blame] | 12621 | (always true) |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12622 | toolbar Compiled with support for |gui-toolbar|. |
| 12623 | ttyin input is a terminal (tty) |
| 12624 | ttyout output is a terminal (tty) |
| 12625 | unix Unix version of Vim. *+unix* |
| 12626 | unnamedplus Compiled with support for "unnamedplus" in 'clipboard' |
| 12627 | user_commands User-defined commands. (always true) |
| 12628 | vartabs Compiled with variable tabstop support |'vartabstop'|. |
| 12629 | vcon Win32: Virtual console support is working, can use |
| 12630 | 'termguicolors'. Also see |+vtp|. |
| 12631 | vertsplit Compiled with vertically split windows |:vsplit|. |
| 12632 | (always true) |
| 12633 | vim_starting True while initial source'ing takes place. |startup| |
| 12634 | *vim_starting* |
Bram Moolenaar | a6feb16 | 2022-01-02 12:06:33 +0000 | [diff] [blame] | 12635 | vim9script Compiled with |Vim9| script support |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12636 | viminfo Compiled with viminfo support. |
| 12637 | vimscript-1 Compiled Vim script version 1 support |
| 12638 | vimscript-2 Compiled Vim script version 2 support |
| 12639 | vimscript-3 Compiled Vim script version 3 support |
Bram Moolenaar | 8a3b805 | 2022-06-26 12:21:15 +0100 | [diff] [blame] | 12640 | vimscript-4 Compiled Vim script version 4 support |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12641 | virtualedit Compiled with 'virtualedit' option. (always true) |
| 12642 | visual Compiled with Visual mode. (always true) |
| 12643 | visualextra Compiled with extra Visual mode commands. (always |
| 12644 | true) |blockwise-operators|. |
| 12645 | vms VMS version of Vim. |
| 12646 | vreplace Compiled with |gR| and |gr| commands. (always true) |
| 12647 | vtp Compiled for vcon support |+vtp| (check vcon to find |
| 12648 | out if it works in the current console). |
| 12649 | wildignore Compiled with 'wildignore' option. |
| 12650 | wildmenu Compiled with 'wildmenu' option. |
| 12651 | win16 old version for MS-Windows 3.1 (always false) |
| 12652 | win32 Win32 version of Vim (MS-Windows 95 and later, 32 or |
| 12653 | 64 bits) |
| 12654 | win32unix Win32 version of Vim, using Unix files (Cygwin) |
| 12655 | win64 Win64 version of Vim (MS-Windows 64 bit). |
| 12656 | win95 Win32 version for MS-Windows 95/98/ME (always false) |
| 12657 | winaltkeys Compiled with 'winaltkeys' option. |
| 12658 | windows Compiled with support for more than one window. |
| 12659 | (always true) |
| 12660 | writebackup Compiled with 'writebackup' default on. |
Christian Brabandt | e085dfd | 2023-09-30 12:49:18 +0200 | [diff] [blame] | 12661 | xattr Compiled with extended attributes support |xattr| |
| 12662 | (currently only supported on Linux). |
Bram Moolenaar | 1cae5a0 | 2021-12-27 21:28:34 +0000 | [diff] [blame] | 12663 | xfontset Compiled with X fontset support |xfontset|. |
| 12664 | xim Compiled with X input method support |xim|. |
| 12665 | xpm Compiled with pixmap support. |
| 12666 | xpm_w32 Compiled with pixmap support for Win32. (Only for |
| 12667 | backward compatibility. Use "xpm" instead.) |
| 12668 | xsmp Compiled with X session management support. |
| 12669 | xsmp_interact Compiled with interactive X session management support. |
| 12670 | xterm_clipboard Compiled with support for xterm clipboard. |
| 12671 | xterm_save Compiled with support for saving and restoring the |
| 12672 | xterm screen. |
| 12673 | x11 Compiled with X11 support. |
| 12674 | |
| 12675 | |
| 12676 | ============================================================================== |
| 12677 | 4. Matching a pattern in a String *string-match* |
| 12678 | |
| 12679 | This is common between several functions. A regexp pattern as explained at |
| 12680 | |pattern| is normally used to find a match in the buffer lines. When a |
| 12681 | pattern is used to find a match in a String, almost everything works in the |
| 12682 | same way. The difference is that a String is handled like it is one line. |
| 12683 | When it contains a "\n" character, this is not seen as a line break for the |
| 12684 | pattern. It can be matched with a "\n" in the pattern, or with ".". Example: |
| 12685 | > |
| 12686 | :let a = "aaaa\nxxxx" |
| 12687 | :echo matchstr(a, "..\n..") |
| 12688 | aa |
| 12689 | xx |
| 12690 | :echo matchstr(a, "a.x") |
| 12691 | a |
| 12692 | x |
| 12693 | |
| 12694 | Don't forget that "^" will only match at the first character of the String and |
| 12695 | "$" at the last character of the string. They don't match after or before a |
| 12696 | "\n". |
| 12697 | |
| 12698 | vim:tw=78:ts=8:noet:ft=help:norl: |