comparison runtime/doc/eval.txt @ 18017:988e5a868b60 v8.1.2004

patch 8.1.2004: more functions can be used as methods Commit: https://github.com/vim/vim/commit/f6ed61e1489e40eada55a4f1782e1ed82bcad7d9 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Sep 7 19:05:09 2019 +0200 patch 8.1.2004: 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, 07 Sep 2019 19:15:04 +0200
parents 8ae333756614
children 8a2fb21c23c0
comparison
equal deleted inserted replaced
18016:834b7854aa3c 18017:988e5a868b60
8893 8893
8894 < MS-Windows: {callback} doesn't work for this function. 8894 < MS-Windows: {callback} doesn't work for this function.
8895 8895
8896 Returns the sound ID, which can be passed to `sound_stop()`. 8896 Returns the sound ID, which can be passed to `sound_stop()`.
8897 Returns zero if the sound could not be played. 8897 Returns zero if the sound could not be played.
8898 {only available when compiled with the |+sound| feature} 8898
8899 Can also be used as a |method|: >
8900 GetSoundName()->sound_playevent()
8901
8902 < {only available when compiled with the |+sound| feature}
8899 8903
8900 *sound_playfile()* 8904 *sound_playfile()*
8901 sound_playfile({path} [, {callback}]) 8905 sound_playfile({path} [, {callback}])
8902 Like `sound_playevent()` but play sound file {path}. {path} 8906 Like `sound_playevent()` but play sound file {path}. {path}
8903 must be a full path. On Ubuntu you may find files to play 8907 must be a full path. On Ubuntu you may find files to play
8904 with this command: > 8908 with this command: >
8905 :!find /usr/share/sounds -type f | grep -v index.theme 8909 :!find /usr/share/sounds -type f | grep -v index.theme
8910
8911 < Can also be used as a |method|: >
8912 GetSoundPath()->sound_playfile()
8913
8906 < {only available when compiled with the |+sound| feature} 8914 < {only available when compiled with the |+sound| feature}
8907 8915
8908 8916
8909 sound_stop({id}) *sound_stop()* 8917 sound_stop({id}) *sound_stop()*
8910 Stop playing sound {id}. {id} must be previously returned by 8918 Stop playing sound {id}. {id} must be previously returned by
8911 `sound_playevent()` or `sound_playfile()`. 8919 `sound_playevent()` or `sound_playfile()`.
8912 8920
8913 On MS-Windows, this does not work for event sound started by 8921 On MS-Windows, this does not work for event sound started by
8914 `sound_playevent()`. To stop event sounds, use `sound_clear()`. 8922 `sound_playevent()`. To stop event sounds, use `sound_clear()`.
8915 8923
8916 {only available when compiled with the |+sound| feature} 8924 Can also be used as a |method|: >
8925 soundid->sound_stop()
8926
8927 < {only available when compiled with the |+sound| feature}
8917 8928
8918 *soundfold()* 8929 *soundfold()*
8919 soundfold({word}) 8930 soundfold({word})
8920 Return the sound-folded equivalent of {word}. Uses the first 8931 Return the sound-folded equivalent of {word}. Uses the first
8921 language in 'spelllang' for the current window that supports 8932 language in 'spelllang' for the current window that supports
8922 soundfolding. 'spell' must be set. When no sound folding is 8933 soundfolding. 'spell' must be set. When no sound folding is
8923 possible the {word} is returned unmodified. 8934 possible the {word} is returned unmodified.
8924 This can be used for making spelling suggestions. Note that 8935 This can be used for making spelling suggestions. Note that
8925 the method can be quite slow. 8936 the method can be quite slow.
8926 8937
8938 Can also be used as a |method|: >
8939 GetWord()->soundfold()
8940 <
8927 *spellbadword()* 8941 *spellbadword()*
8928 spellbadword([{sentence}]) 8942 spellbadword([{sentence}])
8929 Without argument: The result is the badly spelled word under 8943 Without argument: The result is the badly spelled word under
8930 or after the cursor. The cursor is moved to the start of the 8944 or after the cursor. The cursor is moved to the start of the
8931 bad word. When no bad word is found in the cursor line the 8945 bad word. When no bad word is found in the cursor line the
8948 8962
8949 The spelling information for the current window is used. The 8963 The spelling information for the current window is used. The
8950 'spell' option must be set and the value of 'spelllang' is 8964 'spell' option must be set and the value of 'spelllang' is
8951 used. 8965 used.
8952 8966
8967 Can also be used as a |method|: >
8968 GetText()->spellbadword()
8969 <
8953 *spellsuggest()* 8970 *spellsuggest()*
8954 spellsuggest({word} [, {max} [, {capital}]]) 8971 spellsuggest({word} [, {max} [, {capital}]])
8955 Return a |List| with spelling suggestions to replace {word}. 8972 Return a |List| with spelling suggestions to replace {word}.
8956 When {max} is given up to this number of suggestions are 8973 When {max} is given up to this number of suggestions are
8957 returned. Otherwise up to 25 suggestions are returned. 8974 returned. Otherwise up to 25 suggestions are returned.
8971 8988
8972 The spelling information for the current window is used. The 8989 The spelling information for the current window is used. The
8973 'spell' option must be set and the values of 'spelllang' and 8990 'spell' option must be set and the values of 'spelllang' and
8974 'spellsuggest' are used. 8991 'spellsuggest' are used.
8975 8992
8993 Can also be used as a |method|: >
8994 GetWord()->spellsuggest()
8976 8995
8977 split({expr} [, {pattern} [, {keepempty}]]) *split()* 8996 split({expr} [, {pattern} [, {keepempty}]]) *split()*
8978 Make a |List| out of {expr}. When {pattern} is omitted or 8997 Make a |List| out of {expr}. When {pattern} is omitted or
8979 empty each white-separated sequence of characters becomes an 8998 empty each white-separated sequence of characters becomes an
8980 item. 8999 item.
9067 different base the result will be zero. Similarly, when 9086 different base the result will be zero. Similarly, when
9068 {base} is 8 a leading "0" is ignored, and when {base} is 2 a 9087 {base} is 8 a leading "0" is ignored, and when {base} is 2 a
9069 leading "0b" or "0B" is ignored. 9088 leading "0b" or "0B" is ignored.
9070 Text after the number is silently ignored. 9089 Text after the number is silently ignored.
9071 9090
9091 Can also be used as a |method|: >
9092 GetText()->str2nr()
9093
9094 strcharpart({src}, {start} [, {len}]) *strcharpart()*
9095 Like |strpart()| but using character index and length instead
9096 of byte index and length.
9097 When a character index is used where a character does not
9098 exist it is assumed to be one character. For example: >
9099 strcharpart('abc', -1, 2)
9100 < results in 'a'.
9101
9102 Can also be used as a |method|: >
9103 GetText()->strcharpart(5)
9072 9104
9073 strchars({expr} [, {skipcc}]) *strchars()* 9105 strchars({expr} [, {skipcc}]) *strchars()*
9074 The result is a Number, which is the number of characters 9106 The result is a Number, which is the number of characters
9075 in String {expr}. 9107 in String {expr}.
9076 When {skipcc} is omitted or zero, composing characters are 9108 When {skipcc} is omitted or zero, composing characters are
9092 return strchars(a:str) 9124 return strchars(a:str)
9093 endif 9125 endif
9094 endfunction 9126 endfunction
9095 endif 9127 endif
9096 < 9128 <
9097 strcharpart({src}, {start} [, {len}]) *strcharpart()* 9129 Can also be used as a |method|: >
9098 Like |strpart()| but using character index and length instead 9130 GetText()->strchars()
9099 of byte index and length.
9100 When a character index is used where a character does not
9101 exist it is assumed to be one character. For example: >
9102 strcharpart('abc', -1, 2)
9103 < results in 'a'.
9104 9131
9105 strdisplaywidth({expr} [, {col}]) *strdisplaywidth()* 9132 strdisplaywidth({expr} [, {col}]) *strdisplaywidth()*
9106 The result is a Number, which is the number of display cells 9133 The result is a Number, which is the number of display cells
9107 String {expr} occupies on the screen when it starts at {col} 9134 String {expr} occupies on the screen when it starts at {col}
9108 (first column is zero). When {col} is omitted zero is used. 9135 (first column is zero). When {col} is omitted zero is used.
9112 matters for anything that's displayed differently, such as 9139 matters for anything that's displayed differently, such as
9113 'tabstop' and 'display'. 9140 'tabstop' and 'display'.
9114 When {expr} contains characters with East Asian Width Class 9141 When {expr} contains characters with East Asian Width Class
9115 Ambiguous, this function's return value depends on 'ambiwidth'. 9142 Ambiguous, this function's return value depends on 'ambiwidth'.
9116 Also see |strlen()|, |strwidth()| and |strchars()|. 9143 Also see |strlen()|, |strwidth()| and |strchars()|.
9144
9145 Can also be used as a |method|: >
9146 GetText()->strdisplaywidth()
9117 9147
9118 strftime({format} [, {time}]) *strftime()* 9148 strftime({format} [, {time}]) *strftime()*
9119 The result is a String, which is a formatted date and time, as 9149 The result is a String, which is a formatted date and time, as
9120 specified by the {format} string. The given {time} is used, 9150 specified by the {format} string. The given {time} is used,
9121 or the current time if no time is given. The accepted 9151 or the current time if no time is given. The accepted
9132 :echo strftime("%c", getftime("file.c")) 9162 :echo strftime("%c", getftime("file.c"))
9133 Show mod time of file.c. 9163 Show mod time of file.c.
9134 < Not available on all systems. To check use: > 9164 < Not available on all systems. To check use: >
9135 :if exists("*strftime") 9165 :if exists("*strftime")
9136 9166
9167 < Can also be used as a |method|: >
9168 GetFormat()->strftime()
9169
9137 strgetchar({str}, {index}) *strgetchar()* 9170 strgetchar({str}, {index}) *strgetchar()*
9138 Get character {index} from {str}. This uses a character 9171 Get character {index} from {str}. This uses a character
9139 index, not a byte index. Composing characters are considered 9172 index, not a byte index. Composing characters are considered
9140 separate characters here. 9173 separate characters here.
9141 Also see |strcharpart()| and |strchars()|. 9174 Also see |strcharpart()| and |strchars()|.
9175
9176 Can also be used as a |method|: >
9177 GetText()->strgetchar(5)
9142 9178
9143 stridx({haystack}, {needle} [, {start}]) *stridx()* 9179 stridx({haystack}, {needle} [, {start}]) *stridx()*
9144 The result is a Number, which gives the byte index in 9180 The result is a Number, which gives the byte index in
9145 {haystack} of the first occurrence of the String {needle}. 9181 {haystack} of the first occurrence of the String {needle}.
9146 If {start} is specified, the search starts at index {start}. 9182 If {start} is specified, the search starts at index {start}.
9157 :echo stridx("Starting point", "start") -1 9193 :echo stridx("Starting point", "start") -1
9158 < *strstr()* *strchr()* 9194 < *strstr()* *strchr()*
9159 stridx() works similar to the C function strstr(). When used 9195 stridx() works similar to the C function strstr(). When used
9160 with a single character it works similar to strchr(). 9196 with a single character it works similar to strchr().
9161 9197
9198 Can also be used as a |method|: >
9199 GetHaystack()->stridx(needle)
9162 *string()* 9200 *string()*
9163 string({expr}) Return {expr} converted to a String. If {expr} is a Number, 9201 string({expr}) Return {expr} converted to a String. If {expr} is a Number,
9164 Float, String, Blob or a composition of them, then the result 9202 Float, String, Blob or a composition of them, then the result
9165 can be parsed back with |eval()|. 9203 can be parsed back with |eval()|.
9166 {expr} type result ~ 9204 {expr} type result ~
9209 9247
9210 < Note: To get the first character, {start} must be 0. For 9248 < Note: To get the first character, {start} must be 0. For
9211 example, to get three bytes under and after the cursor: > 9249 example, to get three bytes under and after the cursor: >
9212 strpart(getline("."), col(".") - 1, 3) 9250 strpart(getline("."), col(".") - 1, 3)
9213 < 9251 <
9252 Can also be used as a |method|: >
9253 GetText()->strpart(5)
9254
9214 strridx({haystack}, {needle} [, {start}]) *strridx()* 9255 strridx({haystack}, {needle} [, {start}]) *strridx()*
9215 The result is a Number, which gives the byte index in 9256 The result is a Number, which gives the byte index in
9216 {haystack} of the last occurrence of the String {needle}. 9257 {haystack} of the last occurrence of the String {needle}.
9217 When {start} is specified, matches beyond this index are 9258 When {start} is specified, matches beyond this index are
9218 ignored. This can be used to find a match before a previous 9259 ignored. This can be used to find a match before a previous
9227 :echo strridx("an angry armadillo", "an") 3 9268 :echo strridx("an angry armadillo", "an") 3
9228 < *strrchr()* 9269 < *strrchr()*
9229 When used with a single character it works similar to the C 9270 When used with a single character it works similar to the C
9230 function strrchr(). 9271 function strrchr().
9231 9272
9273 Can also be used as a |method|: >
9274 GetHaystack()->strridx(needle)
9275
9232 strtrans({expr}) *strtrans()* 9276 strtrans({expr}) *strtrans()*
9233 The result is a String, which is {expr} with all unprintable 9277 The result is a String, which is {expr} with all unprintable
9234 characters translated into printable characters |'isprint'|. 9278 characters translated into printable characters |'isprint'|.
9235 Like they are shown in a window. Example: > 9279 Like they are shown in a window. Example: >
9236 echo strtrans(@a) 9280 echo strtrans(@a)
9274 Examples: > 9318 Examples: >
9275 :s/\d\+/\=submatch(0) + 1/ 9319 :s/\d\+/\=submatch(0) + 1/
9276 :echo substitute(text, '\d\+', '\=submatch(0) + 1', '') 9320 :echo substitute(text, '\d\+', '\=submatch(0) + 1', '')
9277 < This finds the first number in the line and adds one to it. 9321 < This finds the first number in the line and adds one to it.
9278 A line break is included as a newline character. 9322 A line break is included as a newline character.
9323
9324 Can also be used as a |method|: >
9325 GetNr()->submatch()
9279 9326
9280 substitute({expr}, {pat}, {sub}, {flags}) *substitute()* 9327 substitute({expr}, {pat}, {sub}, {flags}) *substitute()*
9281 The result is a String, which is a copy of {expr}, in which 9328 The result is a String, which is a copy of {expr}, in which
9282 the first match of {pat} is replaced with {sub}. 9329 the first match of {pat} is replaced with {sub}.
9283 When {flags} is "g", all matches of {pat} in {expr} are 9330 When {flags} is "g", all matches of {pat} in {expr} are
9338 Cannot open file: file not found or in accessible 9385 Cannot open file: file not found or in accessible
9339 Cannot read file: cannot read first block 9386 Cannot read file: cannot read first block
9340 Not a swap file: does not contain correct block ID 9387 Not a swap file: does not contain correct block ID
9341 Magic number mismatch: Info in first block is invalid 9388 Magic number mismatch: Info in first block is invalid
9342 9389
9390 Can also be used as a |method|: >
9391 GetFilename()->swapinfo()
9392
9343 swapname({expr}) *swapname()* 9393 swapname({expr}) *swapname()*
9344 The result is the swap file path of the buffer {expr}. 9394 The result is the swap file path of the buffer {expr}.
9345 For the use of {expr}, see |bufname()| above. 9395 For the use of {expr}, see |bufname()| above.
9346 If buffer {expr} is the current buffer, the result is equal to 9396 If buffer {expr} is the current buffer, the result is equal to
9347 |:swapname| (unless no swap file). 9397 |:swapname| (unless no swap file).
9348 If buffer {expr} has no swap file, returns an empty string. 9398 If buffer {expr} has no swap file, returns an empty string.
9399
9400 Can also be used as a |method|: >
9401 GetBufname()->swapname()
9349 9402
9350 synID({lnum}, {col}, {trans}) *synID()* 9403 synID({lnum}, {col}, {trans}) *synID()*
9351 The result is a Number, which is the syntax ID at the position 9404 The result is a Number, which is the syntax ID at the position
9352 {lnum} and {col} in the current window. 9405 {lnum} and {col} in the current window.
9353 The syntax ID can be used with |synIDattr()| and 9406 The syntax ID can be used with |synIDattr()| and