blob: 9786ff8ca5d01d2c26307e8cbe11e481f455574a [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 Kearnsa9c06422025-02-12 20:44:17 +0100176" Register
177
178echo @"
179echo @0 @1 @2 @3 @4 @5 @6 @7 @8 @9
180echo @-
181echo @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
182echo @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
183echo @: @. @% @# @= @* @+ @~ @_ @/
184
Doug Kearns8dec6c22025-01-19 14:02:06 +0100185" Operators
186
Doug Kearnsc273f1a2025-01-20 21:53:01 +0100187" Ternary
188echo expr ? expr : expr
189
190echo lnum == 1 ? "top" : lnum
191echo lnum == 1 ? "top" : lnum == 1000 ? "last" : lnum
192
193echo lnum == 1
194 \ ? "top"
195 \ : lnum == 1000
196 \ ? "last"
197 \ : lnum
198echo lnum == 1 ?
199 \ "top" :
200 \ lnum == 1000 ?
201 \ "last" :
202 \ lnum
203
204echo 1 ? 1 : 0
205echo "foo" ? "foo" : "bar"
206echo foo ? foo : bar
207echo g:foo ? g:foo : g:bar
208echo $FOO ? $FOO : $BAR
209echo True() ? True() : False()
210echo @a ? @a : @b
211echo (1) ? (1) : (0)
212
213" Falsy
214echo expr ?? expr
215
216echo theList ?? 'list is empty'
217echo GetName() ?? 'unknown'
218
219echo theList
220 \ ?? 'list is empty'
221echo theList ??
222 \ 'list is empty'
223
224echo 1 ?? 1
225echo "foo" ?? "foo"
226echo foo ?? foo
227echo g:foo ?? g:foo
228echo $FOO ?? $FOO
229echo True() ?? True()
230echo @a ?? @a
231echo (1) ?? (1)
232
Doug Kearns8dec6c22025-01-19 14:02:06 +0100233" Comparison - using 'ignorcase'
234echo expr == expr
235echo expr != expr
236echo expr > expr
237echo expr >= expr
238echo expr < expr
239echo expr <= expr
240echo expr =~ expr
241echo expr !~ expr
242echo expr is expr
243echo expr isnot expr
244
245" Comparison - match case
246echo expr ==# expr
247echo expr !=# expr
248echo expr ># expr
249echo expr >=# expr
250echo expr <# expr
251echo expr <=# expr
252echo expr =~# expr
253echo expr !~# expr
254echo expr is# expr
255echo expr isnot# expr
256
257" Comparison - ignore case
258echo expr ==? expr
259echo expr !=? expr
260echo expr >? expr
261echo expr >=? expr
262echo expr <? expr
263echo expr <=? expr
264echo expr =~? expr
265echo expr !~? expr
266echo expr is? expr
267echo expr isnot? expr
268
Doug Kearns1aa287e2025-02-10 22:00:27 +0100269" Unreported issue ("is" incorrectly matches as "echo vimNumber *vimCommand* vimNumber")
Doug Kearns8dec6c22025-01-19 14:02:06 +0100270echo 42 is 42
Doug Kearns1718e7d2025-01-08 18:20:47 +0100271
Doug Kearns1aa287e2025-02-10 22:00:27 +0100272" Line continuation
273let foo = foo +
274 \
275 "\ comment
276 \
277 "\ comment
278 \ bar +
279 \ "baz"
280
281let foo = foo +
282 "\ comment
283 \
284 "\ comment
285 \
286 \ bar +
287 \ "baz"
288
Doug Kearnsa9c06422025-02-12 20:44:17 +0100289" Function calls
290
291call Foo(v:true, v:false, v:null)
292
Doug Kearnsc273f1a2025-01-20 21:53:01 +0100293
Doug Kearns1718e7d2025-01-08 18:20:47 +0100294" Issue #16221 (vimString becomes vimVar when preceded by !)
295let bar = !'g:bar'->exists()
296
Doug Kearnsc273f1a2025-01-20 21:53:01 +0100297
298" Issue #14423 (vim.vim: Opt out of vimSearch*)
299
300?truthy
301let truthy = 0
302\ ? (0
303\ )
304\ : (1
305\ )
306echo truthy
307
308function Foo()
309 ?truthy
310 let truthy = 0
311 \ ? (0
312 \ )
313 \ : (1
314 \ )
315 echo truthy
316endfunction
317