comparison runtime/doc/eval.txt @ 17914:af3d441845cd v8.1.1953

patch 8.1.1953: more functions can be used as a method Commit: https://github.com/vim/vim/commit/f9f24ce7a0e5988fedf2e2ff751818f9b07510a6 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Aug 31 21:17:39 2019 +0200 patch 8.1.1953: more functions can be used as a method Problem: More functions can be used as a method. Solution: Allow more functions to be used as a method.
author Bram Moolenaar <Bram@vim.org>
date Sat, 31 Aug 2019 21:30:04 +0200
parents 9fac6d0de69a
children 2e53305f2239
comparison
equal deleted inserted replaced
17913:be8ab5bb74ce 17914:af3d441845cd
5772 " window n in tab page m 5772 " window n in tab page m
5773 :echo haslocaldir(n, m) 5773 :echo haslocaldir(n, m)
5774 " tab page m 5774 " tab page m
5775 :echo haslocaldir(-1, m) 5775 :echo haslocaldir(-1, m)
5776 < 5776 <
5777 Can also be used as a |method|: >
5778 GetWinnr()->haslocaldir()
5779
5777 hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()* 5780 hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()*
5778 The result is a Number, which is 1 if there is a mapping that 5781 The result is a Number, which is 1 if there is a mapping that
5779 contains {what} in somewhere in the rhs (what it is mapped to) 5782 contains {what} in somewhere in the rhs (what it is mapped to)
5780 and this mapping exists in one of the modes indicated by 5783 and this mapping exists in one of the modes indicated by
5781 {mode}. 5784 {mode}.
5800 : map <Leader>d \ABCdoit 5803 : map <Leader>d \ABCdoit
5801 :endif 5804 :endif
5802 < This installs the mapping to "\ABCdoit" only if there isn't 5805 < This installs the mapping to "\ABCdoit" only if there isn't
5803 already a mapping to "\ABCdoit". 5806 already a mapping to "\ABCdoit".
5804 5807
5808 Can also be used as a |method|: >
5809 GetRHS()->hasmapto()
5810
5805 histadd({history}, {item}) *histadd()* 5811 histadd({history}, {item}) *histadd()*
5806 Add the String {item} to the history {history} which can be 5812 Add the String {item} to the history {history} which can be
5807 one of: *hist-names* 5813 one of: *hist-names*
5808 "cmd" or ":" command line history 5814 "cmd" or ":" command line history
5809 "search" or "/" search pattern history 5815 "search" or "/" search pattern history
5821 Example: > 5827 Example: >
5822 :call histadd("input", strftime("%Y %b %d")) 5828 :call histadd("input", strftime("%Y %b %d"))
5823 :let date=input("Enter date: ") 5829 :let date=input("Enter date: ")
5824 < This function is not available in the |sandbox|. 5830 < This function is not available in the |sandbox|.
5825 5831
5832 Can also be used as a |method|, the base is used for the
5833 second argument: >
5834 GetPattern()->histadd('search')
5835
5826 histdel({history} [, {item}]) *histdel()* 5836 histdel({history} [, {item}]) *histdel()*
5827 Clear {history}, i.e. delete all its entries. See |hist-names| 5837 Clear {history}, i.e. delete all its entries. See |hist-names|
5828 for the possible values of {history}. 5838 for the possible values of {history}.
5829 5839
5830 If the parameter {item} evaluates to a String, it is used as a 5840 If the parameter {item} evaluates to a String, it is used as a
5852 < 5862 <
5853 To delete the last search pattern and use the last-but-one for 5863 To delete the last search pattern and use the last-but-one for
5854 the "n" command and 'hlsearch': > 5864 the "n" command and 'hlsearch': >
5855 :call histdel("search", -1) 5865 :call histdel("search", -1)
5856 :let @/ = histget("search", -1) 5866 :let @/ = histget("search", -1)
5867 <
5868 Can also be used as a |method|: >
5869 GetHistory()->histdel()
5857 5870
5858 histget({history} [, {index}]) *histget()* 5871 histget({history} [, {index}]) *histget()*
5859 The result is a String, the entry with Number {index} from 5872 The result is a String, the entry with Number {index} from
5860 {history}. See |hist-names| for the possible values of 5873 {history}. See |hist-names| for the possible values of
5861 {history}, and |:history-indexing| for {index}. If there is 5874 {history}, and |:history-indexing| for {index}. If there is
5868 5881
5869 < Define an Ex command ":H {num}" that supports re-execution of 5882 < Define an Ex command ":H {num}" that supports re-execution of
5870 the {num}th entry from the output of |:history|. > 5883 the {num}th entry from the output of |:history|. >
5871 :command -nargs=1 H execute histget("cmd", 0+<args>) 5884 :command -nargs=1 H execute histget("cmd", 0+<args>)
5872 < 5885 <
5886 Can also be used as a |method|: >
5887 GetHistory()->histget()
5888
5873 histnr({history}) *histnr()* 5889 histnr({history}) *histnr()*
5874 The result is the Number of the current entry in {history}. 5890 The result is the Number of the current entry in {history}.
5875 See |hist-names| for the possible values of {history}. 5891 See |hist-names| for the possible values of {history}.
5876 If an error occurred, -1 is returned. 5892 If an error occurred, -1 is returned.
5877 5893
5878 Example: > 5894 Example: >
5879 :let inp_index = histnr("expr") 5895 :let inp_index = histnr("expr")
5896
5897 < Can also be used as a |method|: >
5898 GetHistory()->histnr()
5880 < 5899 <
5881 hlexists({name}) *hlexists()* 5900 hlexists({name}) *hlexists()*
5882 The result is a Number, which is non-zero if a highlight group 5901 The result is a Number, which is non-zero if a highlight group
5883 called {name} exists. This is when the group has been 5902 called {name} exists. This is when the group has been
5884 defined in some way. Not necessarily when highlighting has 5903 defined in some way. Not necessarily when highlighting has
5885 been defined for it, it may also have been used for a syntax 5904 been defined for it, it may also have been used for a syntax
5886 item. 5905 item.
5887 *highlight_exists()* 5906 *highlight_exists()*
5888 Obsolete name: highlight_exists(). 5907 Obsolete name: highlight_exists().
5889 5908
5909 Can also be used as a |method|: >
5910 GetName()->hlexists()
5911 <
5890 *hlID()* 5912 *hlID()*
5891 hlID({name}) The result is a Number, which is the ID of the highlight group 5913 hlID({name}) The result is a Number, which is the ID of the highlight group
5892 with name {name}. When the highlight group doesn't exist, 5914 with name {name}. When the highlight group doesn't exist,
5893 zero is returned. 5915 zero is returned.
5894 This can be used to retrieve information about the highlight 5916 This can be used to retrieve information about the highlight
5895 group. For example, to get the background color of the 5917 group. For example, to get the background color of the
5896 "Comment" group: > 5918 "Comment" group: >
5897 :echo synIDattr(synIDtrans(hlID("Comment")), "bg") 5919 :echo synIDattr(synIDtrans(hlID("Comment")), "bg")
5898 < *highlightID()* 5920 < *highlightID()*
5899 Obsolete name: highlightID(). 5921 Obsolete name: highlightID().
5922
5923 Can also be used as a |method|: >
5924 GetName()->hlID()
5900 5925
5901 hostname() *hostname()* 5926 hostname() *hostname()*
5902 The result is a String, which is the name of the machine on 5927 The result is a String, which is the name of the machine on
5903 which Vim is currently running. Machine names greater than 5928 which Vim is currently running. Machine names greater than
5904 256 characters long are truncated. 5929 256 characters long are truncated.
5920 echo iconv(utf8_str, "utf-8", &enc) 5945 echo iconv(utf8_str, "utf-8", &enc)
5921 < Note that Vim uses UTF-8 for all Unicode encodings, conversion 5946 < Note that Vim uses UTF-8 for all Unicode encodings, conversion
5922 from/to UCS-2 is automatically changed to use UTF-8. You 5947 from/to UCS-2 is automatically changed to use UTF-8. You
5923 cannot use UCS-2 in a string anyway, because of the NUL bytes. 5948 cannot use UCS-2 in a string anyway, because of the NUL bytes.
5924 5949
5950 Can also be used as a |method|: >
5951 GetText()->iconv('latin1', 'utf-8')
5952 <
5925 *indent()* 5953 *indent()*
5926 indent({lnum}) The result is a Number, which is indent of line {lnum} in the 5954 indent({lnum}) The result is a Number, which is indent of line {lnum} in the
5927 current buffer. The indent is counted in spaces, the value 5955 current buffer. The indent is counted in spaces, the value
5928 of 'tabstop' is relevant. {lnum} is used just like in 5956 of 'tabstop' is relevant. {lnum} is used just like in
5929 |getline()|. 5957 |getline()|.
5930 When {lnum} is invalid -1 is returned. 5958 When {lnum} is invalid -1 is returned.
5931 5959
5960 Can also be used as a |method|: >
5961 GetLnum()->indent()
5932 5962
5933 index({object}, {expr} [, {start} [, {ic}]]) *index()* 5963 index({object}, {expr} [, {start} [, {ic}]]) *index()*
5934 If {object} is a |List| return the lowest index where the item 5964 If {object} is a |List| return the lowest index where the item
5935 has a value equal to {expr}. There is no automatic 5965 has a value equal to {expr}. There is no automatic
5936 conversion, so the String "4" is different from the Number 4. 5966 conversion, so the String "4" is different from the Number 4.
5947 -1 is returned when {expr} is not found in {object}. 5977 -1 is returned when {expr} is not found in {object}.
5948 Example: > 5978 Example: >
5949 :let idx = index(words, "the") 5979 :let idx = index(words, "the")
5950 :if index(numbers, 123) >= 0 5980 :if index(numbers, 123) >= 0
5951 5981
5982 < Can also be used as a |method|: >
5983 GetObject()->index(what)
5952 5984
5953 input({prompt} [, {text} [, {completion}]]) *input()* 5985 input({prompt} [, {text} [, {completion}]]) *input()*
5954 The result is a String, which is whatever the user typed on 5986 The result is a String, which is whatever the user typed on
5955 the command-line. The {prompt} argument is either a prompt 5987 the command-line. The {prompt} argument is either a prompt
5956 string, or a blank string (for no prompt). A '\n' can be used 5988 string, or a blank string (for no prompt). A '\n' can be used
5993 : call inputsave() 6025 : call inputsave()
5994 : let g:Foo = input("enter search pattern: ") 6026 : let g:Foo = input("enter search pattern: ")
5995 : call inputrestore() 6027 : call inputrestore()
5996 :endfunction 6028 :endfunction
5997 6029
6030 < Can also be used as a |method|: >
6031 GetPrompt()->input()
6032
5998 inputdialog({prompt} [, {text} [, {cancelreturn}]]) *inputdialog()* 6033 inputdialog({prompt} [, {text} [, {cancelreturn}]]) *inputdialog()*
5999 Like |input()|, but when the GUI is running and text dialogs 6034 Like |input()|, but when the GUI is running and text dialogs
6000 are supported, a dialog window pops up to input the text. 6035 are supported, a dialog window pops up to input the text.
6001 Example: > 6036 Example: >
6002 :let n = inputdialog("value for shiftwidth", shiftwidth()) 6037 :let n = inputdialog("value for shiftwidth", shiftwidth())
6006 < When the dialog is cancelled {cancelreturn} is returned. When 6041 < When the dialog is cancelled {cancelreturn} is returned. When
6007 omitted an empty string is returned. 6042 omitted an empty string is returned.
6008 Hitting <Enter> works like pressing the OK button. Hitting 6043 Hitting <Enter> works like pressing the OK button. Hitting
6009 <Esc> works like pressing the Cancel button. 6044 <Esc> works like pressing the Cancel button.
6010 NOTE: Command-line completion is not supported. 6045 NOTE: Command-line completion is not supported.
6046
6047 Can also be used as a |method|: >
6048 GetPrompt()->inputdialog()
6011 6049
6012 inputlist({textlist}) *inputlist()* 6050 inputlist({textlist}) *inputlist()*
6013 {textlist} must be a |List| of strings. This |List| is 6051 {textlist} must be a |List| of strings. This |List| is
6014 displayed, one string per line. The user will be prompted to 6052 displayed, one string per line. The user will be prompted to
6015 enter a number, which is returned. 6053 enter a number, which is returned.
6023 the start of the string. And put a prompt in the first item. 6061 the start of the string. And put a prompt in the first item.
6024 Example: > 6062 Example: >
6025 let color = inputlist(['Select color:', '1. red', 6063 let color = inputlist(['Select color:', '1. red',
6026 \ '2. green', '3. blue']) 6064 \ '2. green', '3. blue'])
6027 6065
6066 < Can also be used as a |method|: >
6067 GetChoices()->inputlist()
6068
6028 inputrestore() *inputrestore()* 6069 inputrestore() *inputrestore()*
6029 Restore typeahead that was saved with a previous |inputsave()|. 6070 Restore typeahead that was saved with a previous |inputsave()|.
6030 Should be called the same number of times inputsave() is 6071 Should be called the same number of times inputsave() is
6031 called. Calling it more often is harmless though. 6072 called. Calling it more often is harmless though.
6032 Returns 1 when there is nothing to restore, 0 otherwise. 6073 Returns 1 when there is nothing to restore, 0 otherwise.
6048 |history| stack. 6089 |history| stack.
6049 The result is a String, which is whatever the user actually 6090 The result is a String, which is whatever the user actually
6050 typed on the command-line in response to the issued prompt. 6091 typed on the command-line in response to the issued prompt.
6051 NOTE: Command-line completion is not supported. 6092 NOTE: Command-line completion is not supported.
6052 6093
6094 Can also be used as a |method|: >
6095 GetPrompt()->inputsecret()
6096
6053 insert({object}, {item} [, {idx}]) *insert()* 6097 insert({object}, {item} [, {idx}]) *insert()*
6054 When {object} is a |List| or a |Blob| insert {item} at the start 6098 When {object} is a |List| or a |Blob| insert {item} at the start
6055 of it. 6099 of it.
6056 6100
6057 If {idx} is specified insert {item} before the item with index 6101 If {idx} is specified insert {item} before the item with index
6080 isdirectory({directory}) *isdirectory()* 6124 isdirectory({directory}) *isdirectory()*
6081 The result is a Number, which is |TRUE| when a directory 6125 The result is a Number, which is |TRUE| when a directory
6082 with the name {directory} exists. If {directory} doesn't 6126 with the name {directory} exists. If {directory} doesn't
6083 exist, or isn't a directory, the result is |FALSE|. {directory} 6127 exist, or isn't a directory, the result is |FALSE|. {directory}
6084 is any expression, which is used as a String. 6128 is any expression, which is used as a String.
6129
6130 Can also be used as a |method|: >
6131 GetName()->isdirectory()
6085 6132
6086 isinf({expr}) *isinf()* 6133 isinf({expr}) *isinf()*
6087 Return 1 if {expr} is a positive infinity, or -1 a negative 6134 Return 1 if {expr} is a positive infinity, or -1 a negative
6088 infinity, otherwise 0. > 6135 infinity, otherwise 0. >
6089 :echo isinf(1.0 / 0.0) 6136 :echo isinf(1.0 / 0.0)
6106 :echo islocked('alist') " 1 6153 :echo islocked('alist') " 1
6107 :echo islocked('alist[1]') " 0 6154 :echo islocked('alist[1]') " 0
6108 6155
6109 < When {expr} is a variable that does not exist you get an error 6156 < When {expr} is a variable that does not exist you get an error
6110 message. Use |exists()| to check for existence. 6157 message. Use |exists()| to check for existence.
6158
6159 Can also be used as a |method|: >
6160 GetName()->islocked()
6111 6161
6112 isnan({expr}) *isnan()* 6162 isnan({expr}) *isnan()*
6113 Return |TRUE| if {expr} is a float with value NaN. > 6163 Return |TRUE| if {expr} is a float with value NaN. >
6114 echo isnan(0.0 / 0.0) 6164 echo isnan(0.0 / 0.0)
6115 < 1 6165 < 1