1 " Vim script for exists() function test
2 " Script-local variables are checked here
4 " Existing script-local variable
7 if exists('s:script_var')
13 " Non-existing script-local variable
15 echo 's:script_var: 0'
16 if !exists('s:script_var')
22 " Existing script-local list
23 let s:script_list = ["blue", "orange"]
24 echo 's:script_list: 1'
25 if exists('s:script_list')
31 " Non-existing script-local list
33 echo 's:script_list: 0'
34 if !exists('s:script_list')
40 " Existing script-local dictionary
41 let s:script_dict = {"xcord":100, "ycord":2}
42 echo 's:script_dict: 1'
43 if exists('s:script_dict')
49 " Non-existing script-local dictionary
51 echo 's:script_dict: 0'
52 if !exists('s:script_dict')
58 " Existing script curly-brace variable
60 let s:curly_{str}_var = 1
61 echo 's:curly_' . str . '_var: 1'
62 if exists('s:curly_{str}_var')
68 " Non-existing script-local curly-brace variable
69 unlet s:curly_{str}_var
70 echo 's:curly_' . str . '_var: 0'
71 if !exists('s:curly_{str}_var')
77 " Existing script-local function
78 function! s:my_script_func()
81 echo '*s:my_script_func: 1'
82 if exists('*s:my_script_func')
88 " Non-existing script-local function
89 delfunction s:my_script_func
91 echo '*s:my_script_func: 0'
92 if !exists('*s:my_script_func')