Mercurial > vim
comparison runtime/doc/eval.txt @ 17857:4935244c1128 v8.1.1925
patch 8.1.1925: more functions can be used as methods
Commit: https://github.com/vim/vim/commit/4c313b13fb7bfa694ec6d2a13175e8650c007b2a
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Aug 24 22:58:31 2019 +0200
patch 8.1.1925: more functions can be used as methods
Problem: More functions can be used as methods.
Solution: Make various functions usable as a method.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 24 Aug 2019 23:00:04 +0200 |
parents | 285f7a700185 |
children | cc953757ed2a |
comparison
equal
deleted
inserted
replaced
17856:786c5c8ba565 | 17857:4935244c1128 |
---|---|
2448 getbufinfo([{expr}]) List information about buffers | 2448 getbufinfo([{expr}]) List information about buffers |
2449 getbufline({expr}, {lnum} [, {end}]) | 2449 getbufline({expr}, {lnum} [, {end}]) |
2450 List lines {lnum} to {end} of buffer {expr} | 2450 List lines {lnum} to {end} of buffer {expr} |
2451 getbufvar({expr}, {varname} [, {def}]) | 2451 getbufvar({expr}, {varname} [, {def}]) |
2452 any variable {varname} in buffer {expr} | 2452 any variable {varname} in buffer {expr} |
2453 getchangelist({expr}) List list of change list items | 2453 getchangelist([{expr}]) List list of change list items |
2454 getchar([expr]) Number get one character from the user | 2454 getchar([expr]) Number get one character from the user |
2455 getcharmod() Number modifiers for the last typed character | 2455 getcharmod() Number modifiers for the last typed character |
2456 getcharsearch() Dict last character search | 2456 getcharsearch() Dict last character search |
2457 getcmdline() String return the current command-line | 2457 getcmdline() String return the current command-line |
2458 getcmdpos() Number return cursor position in command-line | 2458 getcmdpos() Number return cursor position in command-line |
4814 non-existing buffers, an empty |List| is returned. | 4814 non-existing buffers, an empty |List| is returned. |
4815 | 4815 |
4816 Example: > | 4816 Example: > |
4817 :let lines = getbufline(bufnr("myfile"), 1, "$") | 4817 :let lines = getbufline(bufnr("myfile"), 1, "$") |
4818 | 4818 |
4819 < Can also be used as a |method|: > | |
4820 GetBufnr()->getbufline(lnum) | |
4821 | |
4819 getbufvar({expr}, {varname} [, {def}]) *getbufvar()* | 4822 getbufvar({expr}, {varname} [, {def}]) *getbufvar()* |
4820 The result is the value of option or local buffer variable | 4823 The result is the value of option or local buffer variable |
4821 {varname} in buffer {expr}. Note that the name without "b:" | 4824 {varname} in buffer {expr}. Note that the name without "b:" |
4822 must be used. | 4825 must be used. |
4823 When {varname} is empty returns a dictionary with all the | 4826 When {varname} is empty returns a dictionary with all the |
4833 When the buffer or variable doesn't exist {def} or an empty | 4836 When the buffer or variable doesn't exist {def} or an empty |
4834 string is returned, there is no error message. | 4837 string is returned, there is no error message. |
4835 Examples: > | 4838 Examples: > |
4836 :let bufmodified = getbufvar(1, "&mod") | 4839 :let bufmodified = getbufvar(1, "&mod") |
4837 :echo "todo myvar = " . getbufvar("todo", "myvar") | 4840 :echo "todo myvar = " . getbufvar("todo", "myvar") |
4838 < | 4841 |
4839 getchangelist({expr}) *getchangelist()* | 4842 < Can also be used as a |method|: > |
4843 GetBufnr()->getbufvar(varname) | |
4844 < | |
4845 getchangelist([{expr}]) *getchangelist()* | |
4840 Returns the |changelist| for the buffer {expr}. For the use | 4846 Returns the |changelist| for the buffer {expr}. For the use |
4841 of {expr}, see |bufname()| above. If buffer {expr} doesn't | 4847 of {expr}, see |bufname()| above. If buffer {expr} doesn't |
4842 exist, an empty list is returned. | 4848 exist, an empty list is returned. |
4843 | 4849 |
4844 The returned list contains two entries: a list with the change | 4850 The returned list contains two entries: a list with the change |
4849 coladd column offset for 'virtualedit' | 4855 coladd column offset for 'virtualedit' |
4850 lnum line number | 4856 lnum line number |
4851 If buffer {expr} is the current buffer, then the current | 4857 If buffer {expr} is the current buffer, then the current |
4852 position refers to the position in the list. For other | 4858 position refers to the position in the list. For other |
4853 buffers, it is set to the length of the list. | 4859 buffers, it is set to the length of the list. |
4860 | |
4861 Can also be used as a |method|: > | |
4862 GetBufnr()->getchangelist() | |
4854 | 4863 |
4855 getchar([expr]) *getchar()* | 4864 getchar([expr]) *getchar()* |
4856 Get a single character from the user or input stream. | 4865 Get a single character from the user or input stream. |
4857 If [expr] is omitted, wait until a character is available. | 4866 If [expr] is omitted, wait until a character is available. |
4858 If [expr] is 0, only get a character when one is available. | 4867 If [expr] is 0, only get a character when one is available. |
5049 are returned. The 'wildignorecase' option always applies. | 5058 are returned. The 'wildignorecase' option always applies. |
5050 | 5059 |
5051 If there are no matches, an empty list is returned. An | 5060 If there are no matches, an empty list is returned. An |
5052 invalid value for {type} produces an error. | 5061 invalid value for {type} produces an error. |
5053 | 5062 |
5063 Can also be used as a |method|: > | |
5064 GetPattern()->getcompletion('color') | |
5065 < | |
5054 *getcurpos()* | 5066 *getcurpos()* |
5055 getcurpos() Get the position of the cursor. This is like getpos('.'), but | 5067 getcurpos() Get the position of the cursor. This is like getpos('.'), but |
5056 includes an extra item in the list: | 5068 includes an extra item in the list: |
5057 [bufnum, lnum, col, off, curswant] ~ | 5069 [bufnum, lnum, col, off, curswant] ~ |
5058 The "curswant" number is the preferred column when moving the | 5070 The "curswant" number is the preferred column when moving the |
5095 :echo getcwd(-1) | 5107 :echo getcwd(-1) |
5096 " Get the working directory of tabpage 3 | 5108 " Get the working directory of tabpage 3 |
5097 :echo getcwd(-1, 3) | 5109 :echo getcwd(-1, 3) |
5098 " Get the working directory of current tabpage | 5110 " Get the working directory of current tabpage |
5099 :echo getcwd(-1, 0) | 5111 :echo getcwd(-1, 0) |
5112 | |
5113 < Can also be used as a |method|: > | |
5114 GetWinnr()->getcwd() | |
5100 < | 5115 < |
5101 getenv({name}) *getenv()* | 5116 getenv({name}) *getenv()* |
5102 Return the value of environment variable {name}. | 5117 Return the value of environment variable {name}. |
5103 When the variable does not exist |v:null| is returned. That | 5118 When the variable does not exist |v:null| is returned. That |
5104 is different from a variable set to an empty string, although | 5119 is different from a variable set to an empty string, although |
5105 some systems interpret the empty value as the variable being | 5120 some systems interpret the empty value as the variable being |
5106 deleted. See also |expr-env|. | 5121 deleted. See also |expr-env|. |
5122 | |
5123 Can also be used as a |method|: > | |
5124 GetVarname()->getenv() | |
5107 | 5125 |
5108 getfontname([{name}]) *getfontname()* | 5126 getfontname([{name}]) *getfontname()* |
5109 Without an argument returns the name of the normal font being | 5127 Without an argument returns the name of the normal font being |
5110 used. Like what is used for the Normal highlight group | 5128 used. Like what is used for the Normal highlight group |
5111 |hl-Normal|. | 5129 |hl-Normal|. |
5132 :echo getfperm("/etc/passwd") | 5150 :echo getfperm("/etc/passwd") |
5133 :echo getfperm(expand("~/.vimrc")) | 5151 :echo getfperm(expand("~/.vimrc")) |
5134 < This will hopefully (from a security point of view) display | 5152 < This will hopefully (from a security point of view) display |
5135 the string "rw-r--r--" or even "rw-------". | 5153 the string "rw-r--r--" or even "rw-------". |
5136 | 5154 |
5155 Can also be used as a |method|: > | |
5156 GetFilename()->getfperm() | |
5157 < | |
5137 For setting permissions use |setfperm()|. | 5158 For setting permissions use |setfperm()|. |
5138 | 5159 |
5139 getfsize({fname}) *getfsize()* | 5160 getfsize({fname}) *getfsize()* |
5140 The result is a Number, which is the size in bytes of the | 5161 The result is a Number, which is the size in bytes of the |
5141 given file {fname}. | 5162 given file {fname}. |
5142 If {fname} is a directory, 0 is returned. | 5163 If {fname} is a directory, 0 is returned. |
5143 If the file {fname} can't be found, -1 is returned. | 5164 If the file {fname} can't be found, -1 is returned. |
5144 If the size of {fname} is too big to fit in a Number then -2 | 5165 If the size of {fname} is too big to fit in a Number then -2 |
5145 is returned. | 5166 is returned. |
5146 | 5167 |
5168 Can also be used as a |method|: > | |
5169 GetFilename()->getfsize() | |
5170 | |
5147 getftime({fname}) *getftime()* | 5171 getftime({fname}) *getftime()* |
5148 The result is a Number, which is the last modification time of | 5172 The result is a Number, which is the last modification time of |
5149 the given file {fname}. The value is measured as seconds | 5173 the given file {fname}. The value is measured as seconds |
5150 since 1st Jan 1970, and may be passed to strftime(). See also | 5174 since 1st Jan 1970, and may be passed to strftime(). See also |
5151 |localtime()| and |strftime()|. | 5175 |localtime()| and |strftime()|. |
5152 If the file {fname} can't be found -1 is returned. | 5176 If the file {fname} can't be found -1 is returned. |
5177 | |
5178 Can also be used as a |method|: > | |
5179 GetFilename()->getftime() | |
5153 | 5180 |
5154 getftype({fname}) *getftype()* | 5181 getftype({fname}) *getftype()* |
5155 The result is a String, which is a description of the kind of | 5182 The result is a String, which is a description of the kind of |
5156 file of the given file {fname}. | 5183 file of the given file {fname}. |
5157 If {fname} does not exist an empty string is returned. | 5184 If {fname} does not exist an empty string is returned. |
5170 < Note that a type such as "link" will only be returned on | 5197 < Note that a type such as "link" will only be returned on |
5171 systems that support it. On some systems only "dir" and | 5198 systems that support it. On some systems only "dir" and |
5172 "file" are returned. On MS-Windows a symbolic link to a | 5199 "file" are returned. On MS-Windows a symbolic link to a |
5173 directory returns "dir" instead of "link". | 5200 directory returns "dir" instead of "link". |
5174 | 5201 |
5202 Can also be used as a |method|: > | |
5203 GetFilename()->getftype() | |
5204 | |
5175 getjumplist([{winnr} [, {tabnr}]]) *getjumplist()* | 5205 getjumplist([{winnr} [, {tabnr}]]) *getjumplist()* |
5176 Returns the |jumplist| for the specified window. | 5206 Returns the |jumplist| for the specified window. |
5177 | 5207 |
5178 Without arguments use the current window. | 5208 Without arguments use the current window. |
5179 With {winnr} only use this window in the current tab page. | 5209 With {winnr} only use this window in the current tab page. |
5189 col column number | 5219 col column number |
5190 coladd column offset for 'virtualedit' | 5220 coladd column offset for 'virtualedit' |
5191 filename filename if available | 5221 filename filename if available |
5192 lnum line number | 5222 lnum line number |
5193 | 5223 |
5194 *getline()* | 5224 Can also be used as a |method|: > |
5225 GetWinnr()->getjumplist() | |
5226 | |
5227 < *getline()* | |
5195 getline({lnum} [, {end}]) | 5228 getline({lnum} [, {end}]) |
5196 Without {end} the result is a String, which is line {lnum} | 5229 Without {end} the result is a String, which is line {lnum} |
5197 from the current buffer. Example: > | 5230 from the current buffer. Example: > |
5198 getline(1) | 5231 getline(1) |
5199 < When {lnum} is a String that doesn't start with a | 5232 < When {lnum} is a String that doesn't start with a |
5211 When {end} is before {lnum} an empty |List| is returned. | 5244 When {end} is before {lnum} an empty |List| is returned. |
5212 Example: > | 5245 Example: > |
5213 :let start = line('.') | 5246 :let start = line('.') |
5214 :let end = search("^$") - 1 | 5247 :let end = search("^$") - 1 |
5215 :let lines = getline(start, end) | 5248 :let lines = getline(start, end) |
5249 | |
5250 < Can also be used as a |method|: > | |
5251 ComputeLnum()->getline() | |
5216 | 5252 |
5217 < To get lines from another buffer see |getbufline()| | 5253 < To get lines from another buffer see |getbufline()| |
5218 | 5254 |
5219 getloclist({nr} [, {what}]) *getloclist()* | 5255 getloclist({nr} [, {what}]) *getloclist()* |
5220 Returns a list with all the entries in the location list for | 5256 Returns a list with all the entries in the location list for |
5286 This can be used to save and restore the position of a mark: > | 5322 This can be used to save and restore the position of a mark: > |
5287 let save_a_mark = getpos("'a") | 5323 let save_a_mark = getpos("'a") |
5288 ... | 5324 ... |
5289 call setpos("'a", save_a_mark) | 5325 call setpos("'a", save_a_mark) |
5290 < Also see |getcurpos()| and |setpos()|. | 5326 < Also see |getcurpos()| and |setpos()|. |
5327 | |
5328 Can also be used as a |method|: > | |
5329 GetMark()->getpos() | |
5291 | 5330 |
5292 | 5331 |
5293 getqflist([{what}]) *getqflist()* | 5332 getqflist([{what}]) *getqflist()* |
5294 Returns a list with all the current quickfix errors. Each | 5333 Returns a list with all the current quickfix errors. Each |
5295 list item is a dictionary with these entries: | 5334 list item is a dictionary with these entries: |
5403 (see |NL-used-for-Nul|). | 5442 (see |NL-used-for-Nul|). |
5404 When the register was not set an empty list is returned. | 5443 When the register was not set an empty list is returned. |
5405 | 5444 |
5406 If {regname} is not specified, |v:register| is used. | 5445 If {regname} is not specified, |v:register| is used. |
5407 | 5446 |
5447 Can also be used as a |method|: > | |
5448 GetRegname()->getreg() | |
5449 | |
5408 | 5450 |
5409 getregtype([{regname}]) *getregtype()* | 5451 getregtype([{regname}]) *getregtype()* |
5410 The result is a String, which is type of register {regname}. | 5452 The result is a String, which is type of register {regname}. |
5411 The value will be one of: | 5453 The value will be one of: |
5412 "v" for |characterwise| text | 5454 "v" for |characterwise| text |
5414 "<CTRL-V>{width}" for |blockwise-visual| text | 5456 "<CTRL-V>{width}" for |blockwise-visual| text |
5415 "" for an empty or unknown register | 5457 "" for an empty or unknown register |
5416 <CTRL-V> is one character with value 0x16. | 5458 <CTRL-V> is one character with value 0x16. |
5417 If {regname} is not specified, |v:register| is used. | 5459 If {regname} is not specified, |v:register| is used. |
5418 | 5460 |
5461 Can also be used as a |method|: > | |
5462 GetRegname()->getregtype() | |
5463 | |
5419 gettabinfo([{arg}]) *gettabinfo()* | 5464 gettabinfo([{arg}]) *gettabinfo()* |
5420 If {arg} is not specified, then information about all the tab | 5465 If {arg} is not specified, then information about all the tab |
5421 pages is returned as a List. Each List item is a Dictionary. | 5466 pages is returned as a List. Each List item is a Dictionary. |
5422 Otherwise, {arg} specifies the tab page number and information | 5467 Otherwise, {arg} specifies the tab page number and information |
5423 about that one is returned. If the tab page does not exist an | 5468 about that one is returned. If the tab page does not exist an |
5426 Each List item is a Dictionary with the following entries: | 5471 Each List item is a Dictionary with the following entries: |
5427 tabnr tab page number. | 5472 tabnr tab page number. |
5428 variables a reference to the dictionary with | 5473 variables a reference to the dictionary with |
5429 tabpage-local variables | 5474 tabpage-local variables |
5430 windows List of |window-ID|s in the tab page. | 5475 windows List of |window-ID|s in the tab page. |
5476 | |
5477 Can also be used as a |method|: > | |
5478 GetTabnr()->gettabinfo() | |
5431 | 5479 |
5432 gettabvar({tabnr}, {varname} [, {def}]) *gettabvar()* | 5480 gettabvar({tabnr}, {varname} [, {def}]) *gettabvar()* |
5433 Get the value of a tab-local variable {varname} in tab page | 5481 Get the value of a tab-local variable {varname} in tab page |
5434 {tabnr}. |t:var| | 5482 {tabnr}. |t:var| |
5435 Tabs are numbered starting with one. | 5483 Tabs are numbered starting with one. |
5436 When {varname} is empty a dictionary with all tab-local | 5484 When {varname} is empty a dictionary with all tab-local |
5437 variables is returned. | 5485 variables is returned. |
5438 Note that the name without "t:" must be used. | 5486 Note that the name without "t:" must be used. |
5439 When the tab or variable doesn't exist {def} or an empty | 5487 When the tab or variable doesn't exist {def} or an empty |
5440 string is returned, there is no error message. | 5488 string is returned, there is no error message. |
5489 | |
5490 Can also be used as a |method|: > | |
5491 GetTabnr()->gettabvar(varname) | |
5441 | 5492 |
5442 gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()* | 5493 gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()* |
5443 Get the value of window-local variable {varname} in window | 5494 Get the value of window-local variable {varname} in window |
5444 {winnr} in tab page {tabnr}. | 5495 {winnr} in tab page {tabnr}. |
5445 When {varname} is empty a dictionary with all window-local | 5496 When {varname} is empty a dictionary with all window-local |
5462 :let list_is_on = gettabwinvar(1, 2, '&list') | 5513 :let list_is_on = gettabwinvar(1, 2, '&list') |
5463 :echo "myvar = " . gettabwinvar(3, 1, 'myvar') | 5514 :echo "myvar = " . gettabwinvar(3, 1, 'myvar') |
5464 < | 5515 < |
5465 To obtain all window-local variables use: > | 5516 To obtain all window-local variables use: > |
5466 gettabwinvar({tabnr}, {winnr}, '&') | 5517 gettabwinvar({tabnr}, {winnr}, '&') |
5518 | |
5519 < Can also be used as a |method|: > | |
5520 GetTabnr()->gettabvar(winnr, varname) | |
5467 | 5521 |
5468 gettagstack([{nr}]) *gettagstack()* | 5522 gettagstack([{nr}]) *gettagstack()* |
5469 The result is a Dict, which is the tag stack of window {nr}. | 5523 The result is a Dict, which is the tag stack of window {nr}. |
5470 {nr} can be the window number or the |window-ID|. | 5524 {nr} can be the window number or the |window-ID|. |
5471 When {nr} is not specified, the current window is used. | 5525 When {nr} is not specified, the current window is used. |
8004 readable by the group, not accessible by others. "xx-x-----" | 8058 readable by the group, not accessible by others. "xx-x-----" |
8005 would do the same thing. | 8059 would do the same thing. |
8006 | 8060 |
8007 Returns non-zero for success, zero for failure. | 8061 Returns non-zero for success, zero for failure. |
8008 | 8062 |
8063 Can also be used as a |method|: > | |
8064 GetFilename()->setfperm(mode) | |
8065 < | |
8009 To read permissions see |getfperm()|. | 8066 To read permissions see |getfperm()|. |
8010 | 8067 |
8011 | 8068 |
8012 setline({lnum}, {text}) *setline()* | 8069 setline({lnum}, {text}) *setline()* |
8013 Set line {lnum} of the current buffer to {text}. To insert | 8070 Set line {lnum} of the current buffer to {text}. To insert |