blob: bb7366d44c52aba841940924a8c62f01ebaf1fb2 [file] [log] [blame]
thincacf8695d2024-01-28 18:57:23 +01001" String
2
3echo 'It''s a string'
4echo 'tab: \t, new line: \n, backslash: \\'
5echo "tab: \t, new line: \n, backslash: \\"
6
dkearnse3e39342024-02-02 07:44:26 +11007" String escape sequences
8
9echo "\316 - \31 - \3 - \x1f - \xf - \X1F - \XF - \u02a4 - \U000002a4 - \b - \e - \f - \n - \r - \t - \\ - \" - \<C-W>"
10echo '\316 \31 \3 \x1f \xf \X1F \XF \u02a4 \U000002a4 \b \e \f \n \r \t \\ \" \<C-W>'
11echo "\3160 - \x1f0 - \X1F0 - \u02a40 - \U000002a40"
12
13echo $"\316 - \31 - \3 - \x1f - \xf - \X1F - \XF - \u02a4 - \U000002a4 - \b - \e - \f - \n - \r - \t - \\ - \" - \<C-W>"
14echo $'\316 \31 \3 \x1f \xf \X1F \XF \u02a4 \U000002a4 \b \e \f \n \r \t \\ \" \<C-W>'
15echo $"\3160 - \x1f0 - \X1F0 - \u02a40 - \U000002a40"
16
17echo "\<C-a>"
18echo "\<*C-a>"
19echo "\<C->>"
20echo "\<*C->>"
21echo "\<C->>>"
22echo "\<*C->>>"
23
Doug Kearns695522d2025-01-10 20:02:17 +010024echo ''''
25echo '''foo'
26echo 'foo'''
27echo 'foo''bar'
28
29" Unreported issue (incorrectly matches as vimString vimMark vimOper NONE)
30" https://github.com/tpope/vim-unimpaired/blob/6d44a6dc2ec34607c41ec78acf81657248580bf1/plugin/unimpaired.vim#L232
31let cmd = 'put!=repeat(nr2char(10), v:count1)|silent '']+'
32
thincacf8695d2024-01-28 18:57:23 +010033" String interpolation
34
35echo 'Don''t highlight interpolation: {{ {1 + 2} }}'
36echo "Don't highlight interpolation: {{ {1 + 2} }}"
37echo $'Highlight interpolation:\t{{ { string({'foo': 'bar'}) } }}'
38echo $'Highlight interpolation:\t{{ { $'nested: {{ {1 + 2} }}' } }}'
39echo $"Highlight interpolation:\t{{ { string({"foo": "bar"}) } }}"
40echo $"Highlight interpolation:\t{{ { $"nested: {{ {1 + 2} }}" } }}"
dkearns5cd86c62024-03-12 07:40:58 +110041
Doug Kearns695522d2025-01-10 20:02:17 +010042echo $''''
43echo $'''foo'
44echo $'foo'''
45echo $'foo''bar'
46
dkearns5cd86c62024-03-12 07:40:58 +110047" Number
48
49" Hexadecimal
50echo 0xFF
51echo 0XFF
52echo -0xFF
53echo -0XFF
54
55" Decimal
56echo 255
57echo -255
58
59" Octal
60echo 0377
61echo 0o377
62echo 0O377
63echo -0377
64echo -0o377
65echo -0O377
66
67" Binary
68echo 0b11111111
69echo 0B11111111
70echo -0b11111111
71echo -0B11111111
72
73" Float
dkearns982e1912024-03-28 20:06:03 +110074echo 123.456
75echo +0.0001
76echo 55.0
77echo -0.123
78echo 1.234e03
79echo 1.0E-6
80echo -3.1416e+88
dkearns5cd86c62024-03-12 07:40:58 +110081
82" Blob
dkearns982e1912024-03-28 20:06:03 +110083echo 0z
dkearns5cd86c62024-03-12 07:40:58 +110084echo 0zFF00ED015DAF
85echo 0zFF00.ED01.5DAF
86echo 0zFF.00.ED.01.5D.AF
Doug Kearns1718e7d2025-01-08 18:20:47 +010087
Doug Kearns1aa287e2025-02-10 22:00:27 +010088" List
89
90echo []
91echo [42]
92echo [[11, 12], [21, 22], [31, 32]]
93echo [1,
94 \ 2,
95 \ 3,
96 \ 4
97 \]
98echo [1, 'two', 1 + 2, "fo" .. "ur"]
99
100" Issue #5830 (Incorrect syntax highlighting in Vim script when omitting space in list of string)
101let l = ['a','b','c']
102
Doug Kearns3dca5122025-03-09 16:30:28 +0100103" Dictionary
104
105echo {}
106echo { 'foo': 21 * 2 }
107echo { "foo": 21 * 2 }
108echo { 42: 21 * 2 }
109
110echo { "foo": { 'bar': 21 * 2 } }
111echo { "foo": { "bar": 21 * 2 } }
112echo { "foo": { 42: 21 * 2 } }
113echo { "foo": #{ bar: 21 * 2 } }
114echo { "foo": #{ -bar-: 21 * 2 } }
115echo { "foo": #{ 42: 21 * 2 } }
116
117echo { 'foo': { 'bar': 21 * 2 } }
118echo { 'foo': { "bar": 21 * 2 } }
119echo { 'foo': { 42: 21 * 2 } }
120echo { 'foo': #{ bar: 21 * 2 } }
121echo { 'foo': #{ -bar-: 21 * 2 } }
122echo { 'foo': #{ 42: 21 * 2 } }
123
124echo { 42: { 'bar': 21 * 2 } }
125echo { 42: { "bar": 21 * 2 } }
126echo { 42: { 42: 21 * 2 } }
127echo { 42: #{ bar: 21 * 2 } }
128echo { 42: #{ -bar-: 21 * 2 } }
129echo { 42: #{ 42: 21 * 2 } }
130
131echo {
132 "\ comment
133 \ "foo": { "bar": 21 * 2 }
134 \}
135
136" TODO: arbitrary expression keys
137
138" Literal Dictionary
139
140echo #{}
141echo #{ foo: 21 * 2 }
142echo #{ -foo-: 21 * 2 }
143echo #{ 42: 21 * 2 }
144
145echo #{ foo: #{ bar: 21 * 2 } }
146echo #{ foo: #{ -bar-: 21 * 2 } }
147echo #{ foo: #{ 42: 21 * 2 } }
148echo #{ foo: { "bar": 21 * 2 } }
149echo #{ foo: { 'bar': 21 * 2 } }
150echo #{ foo: { 42: 21 * 2 } }
151
152echo #{ -foo-: #{ bar: 21 * 2 } }
153echo #{ -foo-: #{ -bar-: 21 * 2 } }
154echo #{ -foo-: #{ 42: 21 * 2 } }
155echo #{ -foo-: { "bar": 21 * 2 } }
156echo #{ -foo-: { 'bar': 21 * 2 } }
157echo #{ -foo-: { 42: 21 * 2 } }
158
159echo #{ 42: #{ bar: 21 * 2 } }
160echo #{ 42: #{ -bar-: 21 * 2 } }
161echo #{ 42: #{ 42: 21 * 2 } }
162echo #{ 42: { "bar": 21 * 2 } }
163echo #{ 42: { 'bar': 21 * 2 } }
164echo #{ 42: { 42: 21 * 2 } }
165
166echo #{
167 "\ comment
168 \ foo: #{
169 \ bar: 21 * 2
170 \ }
171 \}
172
173" match as keys not scope dictionaries
174echo #{ b: 42, w: 42, t: 42, g: 42, l: 42, s: 42, a: 42, v: 42 }
175
Doug Kearns722fbd12025-03-28 19:36:37 +0100176" Tuple
177
178echo ()
179echo (42,)
180echo ((11, 12), (21, 22), (31, 32))
181echo (1,
182 \ 2,
183 \ 3,
184 \ 4
185 \)
186echo (1, 'two', 1 + 2, "fo" .. "ur")
187
188echo foo + (42, 87)
189echo (42, 87) + foo
190
Doug Kearnsa9c06422025-02-12 20:44:17 +0100191" Register
192
193echo @"
194echo @0 @1 @2 @3 @4 @5 @6 @7 @8 @9
195echo @-
196echo @a @b @c @d @e @f @g @h @i @j @k @l @m @n @o @p @q @r @s @t @u @v @w @x @y @z
197echo @A @B @C @D @E @F @G @H @I @J @K @L @M @N @O @P @Q @R @S @T @U @V @W @X @Y @Z
198echo @: @. @% @# @= @* @+ @~ @_ @/
199
Doug Kearns8dec6c22025-01-19 14:02:06 +0100200" Operators
201
Doug Kearnsc273f1a2025-01-20 21:53:01 +0100202" Ternary
203echo expr ? expr : expr
204
205echo lnum == 1 ? "top" : lnum
206echo lnum == 1 ? "top" : lnum == 1000 ? "last" : lnum
207
208echo lnum == 1
209 \ ? "top"
210 \ : lnum == 1000
211 \ ? "last"
212 \ : lnum
213echo lnum == 1 ?
214 \ "top" :
215 \ lnum == 1000 ?
216 \ "last" :
217 \ lnum
218
219echo 1 ? 1 : 0
220echo "foo" ? "foo" : "bar"
221echo foo ? foo : bar
222echo g:foo ? g:foo : g:bar
223echo $FOO ? $FOO : $BAR
224echo True() ? True() : False()
225echo @a ? @a : @b
226echo (1) ? (1) : (0)
227
228" Falsy
229echo expr ?? expr
230
231echo theList ?? 'list is empty'
232echo GetName() ?? 'unknown'
233
234echo theList
235 \ ?? 'list is empty'
236echo theList ??
237 \ 'list is empty'
238
239echo 1 ?? 1
240echo "foo" ?? "foo"
241echo foo ?? foo
242echo g:foo ?? g:foo
243echo $FOO ?? $FOO
244echo True() ?? True()
245echo @a ?? @a
246echo (1) ?? (1)
247
Doug Kearns8dec6c22025-01-19 14:02:06 +0100248" Comparison - using 'ignorcase'
249echo expr == expr
250echo expr != expr
251echo expr > expr
252echo expr >= expr
253echo expr < expr
254echo expr <= expr
255echo expr =~ expr
256echo expr !~ expr
257echo expr is expr
258echo expr isnot expr
259
260" Comparison - match case
261echo expr ==# expr
262echo expr !=# expr
263echo expr ># expr
264echo expr >=# expr
265echo expr <# expr
266echo expr <=# expr
267echo expr =~# expr
268echo expr !~# expr
269echo expr is# expr
270echo expr isnot# expr
271
272" Comparison - ignore case
273echo expr ==? expr
274echo expr !=? expr
275echo expr >? expr
276echo expr >=? expr
277echo expr <? expr
278echo expr <=? expr
279echo expr =~? expr
280echo expr !~? expr
281echo expr is? expr
282echo expr isnot? expr
283
Doug Kearns1aa287e2025-02-10 22:00:27 +0100284" Unreported issue ("is" incorrectly matches as "echo vimNumber *vimCommand* vimNumber")
Doug Kearns8dec6c22025-01-19 14:02:06 +0100285echo 42 is 42
Doug Kearns1718e7d2025-01-08 18:20:47 +0100286
Doug Kearns1aa287e2025-02-10 22:00:27 +0100287" Line continuation
288let foo = foo +
289 \
290 "\ comment
291 \
292 "\ comment
293 \ bar +
294 \ "baz"
295
296let foo = foo +
297 "\ comment
298 \
299 "\ comment
300 \
301 \ bar +
302 \ "baz"
303
Doug Kearnsa9c06422025-02-12 20:44:17 +0100304" Function calls
305
306call Foo(v:true, v:false, v:null)
307
Doug Kearnsc273f1a2025-01-20 21:53:01 +0100308
Doug Kearns1718e7d2025-01-08 18:20:47 +0100309" Issue #16221 (vimString becomes vimVar when preceded by !)
310let bar = !'g:bar'->exists()
311
Doug Kearnsc273f1a2025-01-20 21:53:01 +0100312
313" Issue #14423 (vim.vim: Opt out of vimSearch*)
314
315?truthy
316let truthy = 0
317\ ? (0
318\ )
319\ : (1
320\ )
321echo truthy
322
323function Foo()
324 ?truthy
325 let truthy = 0
326 \ ? (0
327 \ )
328 \ : (1
329 \ )
330 echo truthy
331endfunction
332