blob: 51a3676029d002e1709d3120852d8c067c18fb91 [file] [log] [blame]
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001" Test for various Normal mode commands
2
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01003source shared.vim
Bram Moolenaar5a4c3082019-12-01 15:23:11 +01004source check.vim
Bram Moolenaarca68ae12020-03-30 19:32:53 +02005source view_util.vim
Bram Moolenaar62aec932022-01-29 21:45:34 +00006import './vim9.vim' as v9
Bram Moolenaar7a1d3282022-06-16 13:04:45 +01007source screendump.vim
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01008
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01009func Setup_NewWindow()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020010 10new
11 call setline(1, range(1,100))
12endfunc
13
Bram Moolenaar1bbb6192018-11-10 16:02:01 +010014func MyFormatExpr()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020015 " Adds '->$' at lines having numbers followed by trailing whitespace
16 for ln in range(v:lnum, v:lnum+v:count-1)
17 let line = getline(ln)
18 if getline(ln) =~# '\d\s\+$'
19 call setline(ln, substitute(line, '\s\+$', '', '') . '->$')
20 endif
21 endfor
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020022endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020023
Bram Moolenaar1bbb6192018-11-10 16:02:01 +010024func CountSpaces(type, ...)
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020025 " for testing operatorfunc
26 " will count the number of spaces
27 " and return the result in g:a
28 let sel_save = &selection
29 let &selection = "inclusive"
30 let reg_save = @@
31
32 if a:0 " Invoked from Visual mode, use gv command.
33 silent exe "normal! gvy"
34 elseif a:type == 'line'
35 silent exe "normal! '[V']y"
36 else
37 silent exe "normal! `[v`]y"
38 endif
Bram Moolenaar777e7c22021-10-25 17:07:04 +010039 let g:a = strlen(substitute(@@, '[^ ]', '', 'g'))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020040 let &selection = sel_save
41 let @@ = reg_save
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020042endfunc
43
Bram Moolenaar1bbb6192018-11-10 16:02:01 +010044func OpfuncDummy(type, ...)
Bram Moolenaar4a08b0d2016-11-05 21:55:13 +010045 " for testing operatorfunc
Bram Moolenaar777e7c22021-10-25 17:07:04 +010046 let g:opt = &linebreak
Bram Moolenaar4a08b0d2016-11-05 21:55:13 +010047
48 if a:0 " Invoked from Visual mode, use gv command.
49 silent exe "normal! gvy"
50 elseif a:type == 'line'
51 silent exe "normal! '[V']y"
52 else
53 silent exe "normal! `[v`]y"
54 endif
55 " Create a new dummy window
56 new
Bram Moolenaar777e7c22021-10-25 17:07:04 +010057 let g:bufnr = bufnr('%')
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020058endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020059
Bram Moolenaar1671f442020-03-10 07:48:13 +010060func Test_normal00_optrans()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020061 new
62 call append(0, ['1 This is a simple test: abcd', '2 This is the second line', '3 this is the third line'])
63 1
64 exe "norm! Sfoobar\<esc>"
65 call assert_equal(['foobar', '2 This is the second line', '3 this is the third line', ''], getline(1,'$'))
66 2
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020067 exe "norm! $vbsone"
68 call assert_equal(['foobar', '2 This is the second one', '3 this is the third line', ''], getline(1,'$'))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020069 norm! VS Second line here
70 call assert_equal(['foobar', ' Second line here', '3 this is the third line', ''], getline(1, '$'))
71 %d
72 call append(0, ['4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line'])
73 call append(0, ['1 This is a simple test: abcd', '2 This is the second line', '3 this is the third line'])
74
75 1
76 norm! 2D
77 call assert_equal(['3 this is the third line', '4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line', ''], getline(1,'$'))
78 set cpo+=#
79 norm! 4D
80 call assert_equal(['', '4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line', ''], getline(1,'$'))
81
82 " clean up
83 set cpo-=#
84 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020085endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020086
Bram Moolenaar1bbb6192018-11-10 16:02:01 +010087func Test_normal01_keymodel()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020088 call Setup_NewWindow()
89 " Test 1: depending on 'keymodel' <s-down> does something different
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020090 50
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020091 call feedkeys("V\<S-Up>y", 'tx')
92 call assert_equal(['47', '48', '49', '50'], getline("'<", "'>"))
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020093 set keymodel=startsel
94 50
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020095 call feedkeys("V\<S-Up>y", 'tx')
96 call assert_equal(['49', '50'], getline("'<", "'>"))
97 " Start visual mode when keymodel = startsel
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020098 50
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020099 call feedkeys("\<S-Up>y", 'tx')
100 call assert_equal(['49', '5'], getreg(0, 0, 1))
Bram Moolenaar1671f442020-03-10 07:48:13 +0100101 " Use the different Shift special keys
102 50
103 call feedkeys("\<S-Right>\<S-Left>\<S-Up>\<S-Down>\<S-Home>\<S-End>y", 'tx')
104 call assert_equal(['50'], getline("'<", "'>"))
105 call assert_equal(['50', ''], getreg(0, 0, 1))
106
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200107 " Do not start visual mode when keymodel=
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200108 set keymodel=
109 50
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200110 call feedkeys("\<S-Up>y$", 'tx')
111 call assert_equal(['42'], getreg(0, 0, 1))
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200112 " Stop visual mode when keymodel=stopsel
113 set keymodel=stopsel
114 50
115 call feedkeys("Vkk\<Up>yy", 'tx')
116 call assert_equal(['47'], getreg(0, 0, 1))
117
118 set keymodel=
119 50
120 call feedkeys("Vkk\<Up>yy", 'tx')
121 call assert_equal(['47', '48', '49', '50'], getreg(0, 0, 1))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200122
Bram Moolenaard7e5e942020-10-07 16:54:52 +0200123 " Test for using special keys to start visual selection
124 %d
125 call setline(1, ['red fox tail', 'red fox tail', 'red fox tail'])
126 set keymodel=startsel
127 " Test for <S-PageUp> and <S-PageDown>
128 call cursor(1, 1)
129 call feedkeys("\<S-PageDown>y", 'xt')
130 call assert_equal([0, 1, 1, 0], getpos("'<"))
131 call assert_equal([0, 3, 1, 0], getpos("'>"))
132 call feedkeys("Gz\<CR>8|\<S-PageUp>y", 'xt')
133 call assert_equal([0, 2, 1, 0], getpos("'<"))
134 call assert_equal([0, 3, 8, 0], getpos("'>"))
135 " Test for <S-C-Home> and <S-C-End>
136 call cursor(2, 12)
137 call feedkeys("\<S-C-Home>y", 'xt')
138 call assert_equal([0, 1, 1, 0], getpos("'<"))
139 call assert_equal([0, 2, 12, 0], getpos("'>"))
140 call cursor(1, 4)
141 call feedkeys("\<S-C-End>y", 'xt')
142 call assert_equal([0, 1, 4, 0], getpos("'<"))
143 call assert_equal([0, 3, 13, 0], getpos("'>"))
144 " Test for <S-C-Left> and <S-C-Right>
145 call cursor(2, 5)
146 call feedkeys("\<S-C-Right>y", 'xt')
147 call assert_equal([0, 2, 5, 0], getpos("'<"))
148 call assert_equal([0, 2, 9, 0], getpos("'>"))
149 call cursor(2, 9)
150 call feedkeys("\<S-C-Left>y", 'xt')
151 call assert_equal([0, 2, 5, 0], getpos("'<"))
152 call assert_equal([0, 2, 9, 0], getpos("'>"))
153
154 set keymodel&
155
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200156 " clean up
157 bw!
158endfunc
159
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100160func Test_normal03_join()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200161 " basic join test
162 call Setup_NewWindow()
163 50
164 norm! VJ
165 call assert_equal('50 51', getline('.'))
166 $
167 norm! J
168 call assert_equal('100', getline('.'))
169 $
170 norm! V9-gJ
171 call assert_equal('919293949596979899100', getline('.'))
172 call setline(1, range(1,100))
173 $
174 :j 10
175 call assert_equal('100', getline('.'))
Bram Moolenaar004a6782020-04-11 17:09:31 +0200176 call assert_beeps('normal GVJ')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200177 " clean up
178 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200179endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200180
Bram Moolenaar004a6782020-04-11 17:09:31 +0200181" basic filter test
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100182func Test_normal04_filter()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200183 " only test on non windows platform
Bram Moolenaar004a6782020-04-11 17:09:31 +0200184 CheckNotMSWindows
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200185 call Setup_NewWindow()
186 1
187 call feedkeys("!!sed -e 's/^/| /'\n", 'tx')
188 call assert_equal('| 1', getline('.'))
189 90
190 :sil :!echo one
191 call feedkeys('.', 'tx')
192 call assert_equal('| 90', getline('.'))
193 95
194 set cpo+=!
195 " 2 <CR>, 1: for executing the command,
196 " 2: clear hit-enter-prompt
197 call feedkeys("!!\n", 'tx')
198 call feedkeys(":!echo one\n\n", 'tx')
199 call feedkeys(".", 'tx')
200 call assert_equal('one', getline('.'))
201 set cpo-=!
202 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200203endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200204
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100205func Test_normal05_formatexpr()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200206 " basic formatexpr test
207 call Setup_NewWindow()
208 %d_
209 call setline(1, ['here: 1 ', '2', 'here: 3 ', '4', 'not here: '])
210 1
211 set formatexpr=MyFormatExpr()
212 norm! gqG
213 call assert_equal(['here: 1->$', '2', 'here: 3->$', '4', 'not here: '], getline(1,'$'))
214 set formatexpr=
215 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200216endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200217
Bram Moolenaard77f9d52016-09-04 15:13:39 +0200218func Test_normal05_formatexpr_newbuf()
219 " Edit another buffer in the 'formatexpr' function
220 new
221 func! Format()
222 edit another
223 endfunc
224 set formatexpr=Format()
225 norm gqG
226 bw!
227 set formatexpr=
228endfunc
229
230func Test_normal05_formatexpr_setopt()
231 " Change the 'formatexpr' value in the function
232 new
233 func! Format()
234 set formatexpr=
235 endfunc
236 set formatexpr=Format()
237 norm gqG
238 bw!
239 set formatexpr=
240endfunc
241
Bram Moolenaar2eaeaf32020-05-03 16:04:43 +0200242" When 'formatexpr' returns non-zero, internal formatting is used.
243func Test_normal_formatexpr_returns_nonzero()
244 new
245 call setline(1, ['one', 'two'])
246 func! Format()
247 return 1
248 endfunc
249 setlocal formatexpr=Format()
250 normal VGgq
251 call assert_equal(['one two'], getline(1, '$'))
Yee Cheng Chin1881abf2022-12-08 09:41:24 +0000252
Bram Moolenaar2eaeaf32020-05-03 16:04:43 +0200253 setlocal formatexpr=
254 delfunc Format
Yee Cheng Chin1881abf2022-12-08 09:41:24 +0000255 bwipe!
Bram Moolenaar2eaeaf32020-05-03 16:04:43 +0200256endfunc
257
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +0000258" Test for using a script-local function for 'formatexpr'
259func Test_formatexpr_scriptlocal_func()
260 func! s:Format()
261 let g:FormatArgs = [v:lnum, v:count]
262 endfunc
263 set formatexpr=s:Format()
264 call assert_equal(expand('<SID>') .. 'Format()', &formatexpr)
265 new | only
266 call setline(1, range(1, 40))
267 let g:FormatArgs = []
268 normal! 2GVjgq
269 call assert_equal([2, 2], g:FormatArgs)
270 bw!
271 set formatexpr=<SID>Format()
272 call assert_equal(expand('<SID>') .. 'Format()', &formatexpr)
273 new | only
274 call setline(1, range(1, 40))
275 let g:FormatArgs = []
276 normal! 4GVjgq
277 call assert_equal([4, 2], g:FormatArgs)
278 bw!
279 let &formatexpr = 's:Format()'
280 new | only
281 call setline(1, range(1, 40))
282 let g:FormatArgs = []
283 normal! 6GVjgq
284 call assert_equal([6, 2], g:FormatArgs)
285 bw!
286 let &formatexpr = '<SID>Format()'
287 new | only
288 call setline(1, range(1, 40))
289 let g:FormatArgs = []
290 normal! 8GVjgq
291 call assert_equal([8, 2], g:FormatArgs)
292 setlocal formatexpr=
293 delfunc s:Format
294 bw!
295endfunc
296
Bram Moolenaar004a6782020-04-11 17:09:31 +0200297" basic test for formatprg
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100298func Test_normal06_formatprg()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200299 " only test on non windows platform
Bram Moolenaar004a6782020-04-11 17:09:31 +0200300 CheckNotMSWindows
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100301
302 " uses sed to number non-empty lines
Bram Moolenaarb152b6a2022-09-29 21:37:33 +0100303 call writefile(['#!/bin/sh', 'sed ''/./=''|sed ''/./{', 'N', 's/\n/ /', '}'''], 'Xsed_format.sh', 'D')
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100304 call system('chmod +x ./Xsed_format.sh')
305 let text = ['a', '', 'c', '', ' ', 'd', 'e']
306 let expected = ['1 a', '', '3 c', '', '5 ', '6 d', '7 e']
307
308 10new
309 call setline(1, text)
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200310 set formatprg=./Xsed_format.sh
311 norm! gggqG
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100312 call assert_equal(expected, getline(1, '$'))
Bram Moolenaar004a6782020-04-11 17:09:31 +0200313 %d
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100314
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100315 call setline(1, text)
316 set formatprg=donothing
317 setlocal formatprg=./Xsed_format.sh
318 norm! gggqG
319 call assert_equal(expected, getline(1, '$'))
Bram Moolenaar004a6782020-04-11 17:09:31 +0200320 %d
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100321
Bram Moolenaar004a6782020-04-11 17:09:31 +0200322 " Check for the command-line ranges added to 'formatprg'
323 set formatprg=cat
324 call setline(1, ['one', 'two', 'three', 'four', 'five'])
325 call feedkeys('gggqG', 'xt')
326 call assert_equal('.,$!cat', @:)
327 call feedkeys('2Ggq2j', 'xt')
328 call assert_equal('.,.+2!cat', @:)
329
330 bw!
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200331 " clean up
332 set formatprg=
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100333 setlocal formatprg=
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200334endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200335
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100336func Test_normal07_internalfmt()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200337 " basic test for internal formmatter to textwidth of 12
338 let list=range(1,11)
339 call map(list, 'v:val." "')
340 10new
341 call setline(1, list)
342 set tw=12
Bram Moolenaar004a6782020-04-11 17:09:31 +0200343 norm! ggVGgq
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200344 call assert_equal(['1 2 3', '4 5 6', '7 8 9', '10 11 '], getline(1, '$'))
345 " clean up
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100346 set tw=0
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200347 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200348endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200349
Bram Moolenaar004a6782020-04-11 17:09:31 +0200350" basic tests for foldopen/folddelete
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100351func Test_normal08_fold()
Bram Moolenaar004a6782020-04-11 17:09:31 +0200352 CheckFeature folding
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200353 call Setup_NewWindow()
354 50
355 setl foldenable fdm=marker
356 " First fold
357 norm! V4jzf
358 " check that folds have been created
359 call assert_equal(['50/*{{{*/', '51', '52', '53', '54/*}}}*/'], getline(50,54))
360 " Second fold
361 46
362 norm! V10jzf
363 " check that folds have been created
364 call assert_equal('46/*{{{*/', getline(46))
365 call assert_equal('60/*}}}*/', getline(60))
366 norm! k
367 call assert_equal('45', getline('.'))
368 norm! j
369 call assert_equal('46/*{{{*/', getline('.'))
370 norm! j
371 call assert_equal('61', getline('.'))
372 norm! k
373 " open a fold
374 norm! Vzo
375 norm! k
376 call assert_equal('45', getline('.'))
377 norm! j
378 call assert_equal('46/*{{{*/', getline('.'))
379 norm! j
380 call assert_equal('47', getline('.'))
381 norm! k
382 norm! zcVzO
383 call assert_equal('46/*{{{*/', getline('.'))
384 norm! j
385 call assert_equal('47', getline('.'))
386 norm! j
387 call assert_equal('48', getline('.'))
388 norm! j
389 call assert_equal('49', getline('.'))
390 norm! j
391 call assert_equal('50/*{{{*/', getline('.'))
392 norm! j
393 call assert_equal('51', getline('.'))
394 " delete folds
395 :46
396 " collapse fold
397 norm! V14jzC
398 " delete all folds recursively
399 norm! VzD
400 call assert_equal(['46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60'], getline(46,60))
401
402 " clean up
403 setl nofoldenable fdm=marker
404 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200405endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200406
Bram Moolenaar2228cd72021-11-22 14:16:08 +0000407func Test_normal09a_operatorfunc()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200408 " Test operatorfunc
409 call Setup_NewWindow()
410 " Add some spaces for counting
411 50,60s/$/ /
412 unlet! g:a
413 let g:a=0
414 nmap <buffer><silent> ,, :set opfunc=CountSpaces<CR>g@
415 vmap <buffer><silent> ,, :<C-U>call CountSpaces(visualmode(), 1)<CR>
416 50
417 norm V2j,,
418 call assert_equal(6, g:a)
419 norm V,,
420 call assert_equal(2, g:a)
421 norm ,,l
422 call assert_equal(0, g:a)
423 50
424 exe "norm 0\<c-v>10j2l,,"
425 call assert_equal(11, g:a)
426 50
427 norm V10j,,
428 call assert_equal(22, g:a)
429
430 " clean up
431 unmap <buffer> ,,
432 set opfunc=
Bram Moolenaar4a08b0d2016-11-05 21:55:13 +0100433 unlet! g:a
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200434 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200435endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200436
Bram Moolenaar2228cd72021-11-22 14:16:08 +0000437func Test_normal09b_operatorfunc()
Bram Moolenaar4a08b0d2016-11-05 21:55:13 +0100438 " Test operatorfunc
439 call Setup_NewWindow()
440 " Add some spaces for counting
441 50,60s/$/ /
442 unlet! g:opt
443 set linebreak
444 nmap <buffer><silent> ,, :set opfunc=OpfuncDummy<CR>g@
445 50
446 norm ,,j
447 exe "bd!" g:bufnr
448 call assert_true(&linebreak)
449 call assert_equal(g:opt, &linebreak)
450 set nolinebreak
451 norm ,,j
452 exe "bd!" g:bufnr
453 call assert_false(&linebreak)
454 call assert_equal(g:opt, &linebreak)
455
456 " clean up
457 unmap <buffer> ,,
458 set opfunc=
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200459 call assert_fails('normal Vg@', 'E774:')
Bram Moolenaar4a08b0d2016-11-05 21:55:13 +0100460 bw!
461 unlet! g:opt
462endfunc
463
Bram Moolenaar2228cd72021-11-22 14:16:08 +0000464func OperatorfuncRedo(_)
465 let g:opfunc_count = v:count
466endfunc
467
Bram Moolenaarb3bd1d32022-01-02 13:05:45 +0000468func Underscorize(_)
469 normal! '[V']r_
470endfunc
471
Bram Moolenaar2228cd72021-11-22 14:16:08 +0000472func Test_normal09c_operatorfunc()
473 " Test redoing operatorfunc
474 new
475 call setline(1, 'some text')
476 set operatorfunc=OperatorfuncRedo
477 normal v3g@
478 call assert_equal(3, g:opfunc_count)
479 let g:opfunc_count = 0
480 normal .
481 call assert_equal(3, g:opfunc_count)
482
483 bw!
484 unlet g:opfunc_count
Bram Moolenaarb3bd1d32022-01-02 13:05:45 +0000485
486 " Test redoing Visual mode
487 set operatorfunc=Underscorize
488 new
489 call setline(1, ['first', 'first', 'third', 'third', 'second'])
naohiro ono5c75eed2022-01-03 11:15:47 +0000490 normal! 1GVjg@
Bram Moolenaarb3bd1d32022-01-02 13:05:45 +0000491 normal! 5G.
492 normal! 3G.
493 call assert_equal(['_____', '_____', '_____', '_____', '______'], getline(1, '$'))
494 bwipe!
Bram Moolenaar2228cd72021-11-22 14:16:08 +0000495 set operatorfunc=
496endfunc
497
Yegappan Lakshmanan2172bff2021-12-08 10:46:21 +0000498" Test for different ways of setting the 'operatorfunc' option
499func Test_opfunc_callback()
500 new
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000501 func OpFunc1(callnr, type)
502 let g:OpFunc1Args = [a:callnr, a:type]
503 endfunc
504 func OpFunc2(type)
505 let g:OpFunc2Args = [a:type]
Yegappan Lakshmanan2172bff2021-12-08 10:46:21 +0000506 endfunc
507
Yegappan Lakshmanan6ae8fae2021-12-12 16:26:44 +0000508 let lines =<< trim END
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000509 #" Test for using a function name
510 LET &opfunc = 'g:OpFunc2'
511 LET g:OpFunc2Args = []
Yegappan Lakshmanan6ae8fae2021-12-12 16:26:44 +0000512 normal! g@l
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000513 call assert_equal(['char'], g:OpFunc2Args)
514
515 #" Test for using a function()
516 set opfunc=function('g:OpFunc1',\ [10])
517 LET g:OpFunc1Args = []
518 normal! g@l
519 call assert_equal([10, 'char'], g:OpFunc1Args)
Yegappan Lakshmanan2172bff2021-12-08 10:46:21 +0000520
Yegappan Lakshmanan6ae8fae2021-12-12 16:26:44 +0000521 #" Using a funcref variable to set 'operatorfunc'
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000522 VAR Fn = function('g:OpFunc1', [11])
Yegappan Lakshmanan6ae8fae2021-12-12 16:26:44 +0000523 LET &opfunc = Fn
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000524 LET g:OpFunc1Args = []
Yegappan Lakshmanan6ae8fae2021-12-12 16:26:44 +0000525 normal! g@l
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000526 call assert_equal([11, 'char'], g:OpFunc1Args)
Yegappan Lakshmanan2172bff2021-12-08 10:46:21 +0000527
Yegappan Lakshmanan6ae8fae2021-12-12 16:26:44 +0000528 #" Using a string(funcref_variable) to set 'operatorfunc'
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000529 LET Fn = function('g:OpFunc1', [12])
Yegappan Lakshmanan6ae8fae2021-12-12 16:26:44 +0000530 LET &operatorfunc = string(Fn)
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000531 LET g:OpFunc1Args = []
Yegappan Lakshmanan6ae8fae2021-12-12 16:26:44 +0000532 normal! g@l
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000533 call assert_equal([12, 'char'], g:OpFunc1Args)
Yegappan Lakshmanan2172bff2021-12-08 10:46:21 +0000534
Yegappan Lakshmanan6ae8fae2021-12-12 16:26:44 +0000535 #" Test for using a funcref()
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000536 set operatorfunc=funcref('g:OpFunc1',\ [13])
537 LET g:OpFunc1Args = []
Yegappan Lakshmanan6ae8fae2021-12-12 16:26:44 +0000538 normal! g@l
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000539 call assert_equal([13, 'char'], g:OpFunc1Args)
Yegappan Lakshmanan2172bff2021-12-08 10:46:21 +0000540
Yegappan Lakshmanan6ae8fae2021-12-12 16:26:44 +0000541 #" Using a funcref variable to set 'operatorfunc'
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000542 LET Fn = funcref('g:OpFunc1', [14])
Yegappan Lakshmanan6ae8fae2021-12-12 16:26:44 +0000543 LET &opfunc = Fn
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000544 LET g:OpFunc1Args = []
Yegappan Lakshmanan6ae8fae2021-12-12 16:26:44 +0000545 normal! g@l
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000546 call assert_equal([14, 'char'], g:OpFunc1Args)
Yegappan Lakshmanan2172bff2021-12-08 10:46:21 +0000547
Yegappan Lakshmanan6ae8fae2021-12-12 16:26:44 +0000548 #" Using a string(funcref_variable) to set 'operatorfunc'
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000549 LET Fn = funcref('g:OpFunc1', [15])
Yegappan Lakshmanan6ae8fae2021-12-12 16:26:44 +0000550 LET &opfunc = string(Fn)
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000551 LET g:OpFunc1Args = []
Yegappan Lakshmanan6ae8fae2021-12-12 16:26:44 +0000552 normal! g@l
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000553 call assert_equal([15, 'char'], g:OpFunc1Args)
Yegappan Lakshmanan2172bff2021-12-08 10:46:21 +0000554
Yegappan Lakshmanan6ae8fae2021-12-12 16:26:44 +0000555 #" Test for using a lambda function using set
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000556 VAR optval = "LSTART a LMIDDLE OpFunc1(16, a) LEND"
Yegappan Lakshmanan6ae8fae2021-12-12 16:26:44 +0000557 LET optval = substitute(optval, ' ', '\\ ', 'g')
558 exe "set opfunc=" .. optval
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000559 LET g:OpFunc1Args = []
Yegappan Lakshmanan6ae8fae2021-12-12 16:26:44 +0000560 normal! g@l
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000561 call assert_equal([16, 'char'], g:OpFunc1Args)
Yegappan Lakshmanan2172bff2021-12-08 10:46:21 +0000562
Yegappan Lakshmanan6ae8fae2021-12-12 16:26:44 +0000563 #" Test for using a lambda function using LET
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000564 LET &opfunc = LSTART a LMIDDLE OpFunc1(17, a) LEND
565 LET g:OpFunc1Args = []
Yegappan Lakshmanan6ae8fae2021-12-12 16:26:44 +0000566 normal! g@l
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000567 call assert_equal([17, 'char'], g:OpFunc1Args)
Yegappan Lakshmanan2172bff2021-12-08 10:46:21 +0000568
Yegappan Lakshmanan6ae8fae2021-12-12 16:26:44 +0000569 #" Set 'operatorfunc' to a string(lambda expression)
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000570 LET &opfunc = 'LSTART a LMIDDLE OpFunc1(18, a) LEND'
571 LET g:OpFunc1Args = []
Yegappan Lakshmanan6ae8fae2021-12-12 16:26:44 +0000572 normal! g@l
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000573 call assert_equal([18, 'char'], g:OpFunc1Args)
Yegappan Lakshmanan2172bff2021-12-08 10:46:21 +0000574
Yegappan Lakshmanan6ae8fae2021-12-12 16:26:44 +0000575 #" Set 'operatorfunc' to a variable with a lambda expression
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000576 VAR Lambda = LSTART a LMIDDLE OpFunc1(19, a) LEND
Yegappan Lakshmanan6ae8fae2021-12-12 16:26:44 +0000577 LET &opfunc = Lambda
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000578 LET g:OpFunc1Args = []
Yegappan Lakshmanan6ae8fae2021-12-12 16:26:44 +0000579 normal! g@l
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000580 call assert_equal([19, 'char'], g:OpFunc1Args)
Yegappan Lakshmanan2172bff2021-12-08 10:46:21 +0000581
Yegappan Lakshmanan6ae8fae2021-12-12 16:26:44 +0000582 #" Set 'operatorfunc' to a string(variable with a lambda expression)
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000583 LET Lambda = LSTART a LMIDDLE OpFunc1(20, a) LEND
Yegappan Lakshmanan6ae8fae2021-12-12 16:26:44 +0000584 LET &opfunc = string(Lambda)
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000585 LET g:OpFunc1Args = []
Yegappan Lakshmanan6ae8fae2021-12-12 16:26:44 +0000586 normal! g@l
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000587 call assert_equal([20, 'char'], g:OpFunc1Args)
Yegappan Lakshmanan2172bff2021-12-08 10:46:21 +0000588
Yegappan Lakshmanan6ae8fae2021-12-12 16:26:44 +0000589 #" Try to use 'operatorfunc' after the function is deleted
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000590 func g:TmpOpFunc1(type)
591 let g:TmpOpFunc1Args = [21, a:type]
Yegappan Lakshmanan6ae8fae2021-12-12 16:26:44 +0000592 endfunc
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000593 LET &opfunc = function('g:TmpOpFunc1')
594 delfunc g:TmpOpFunc1
Yegappan Lakshmanan6ae8fae2021-12-12 16:26:44 +0000595 call test_garbagecollect_now()
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000596 LET g:TmpOpFunc1Args = []
Yegappan Lakshmanan6ae8fae2021-12-12 16:26:44 +0000597 call assert_fails('normal! g@l', 'E117:')
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000598 call assert_equal([], g:TmpOpFunc1Args)
Yegappan Lakshmanan2172bff2021-12-08 10:46:21 +0000599
Yegappan Lakshmanan6ae8fae2021-12-12 16:26:44 +0000600 #" Try to use a function with two arguments for 'operatorfunc'
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000601 func g:TmpOpFunc2(x, y)
602 let g:TmpOpFunc2Args = [a:x, a:y]
Yegappan Lakshmanan6ae8fae2021-12-12 16:26:44 +0000603 endfunc
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000604 set opfunc=TmpOpFunc2
605 LET g:TmpOpFunc2Args = []
Yegappan Lakshmanan6ae8fae2021-12-12 16:26:44 +0000606 call assert_fails('normal! g@l', 'E119:')
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000607 call assert_equal([], g:TmpOpFunc2Args)
608 delfunc TmpOpFunc2
Yegappan Lakshmanan2172bff2021-12-08 10:46:21 +0000609
Yegappan Lakshmanan6ae8fae2021-12-12 16:26:44 +0000610 #" Try to use a lambda function with two arguments for 'operatorfunc'
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000611 LET &opfunc = LSTART a, b LMIDDLE OpFunc1(22, b) LEND
612 LET g:OpFunc1Args = []
Yegappan Lakshmanan6ae8fae2021-12-12 16:26:44 +0000613 call assert_fails('normal! g@l', 'E119:')
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000614 call assert_equal([], g:OpFunc1Args)
Yegappan Lakshmanan2172bff2021-12-08 10:46:21 +0000615
Yegappan Lakshmanan6ae8fae2021-12-12 16:26:44 +0000616 #" Test for clearing the 'operatorfunc' option
617 set opfunc=''
618 set opfunc&
619 call assert_fails("set opfunc=function('abc')", "E700:")
620 call assert_fails("set opfunc=funcref('abc')", "E700:")
Yegappan Lakshmanan2172bff2021-12-08 10:46:21 +0000621
Yegappan Lakshmanan6ae8fae2021-12-12 16:26:44 +0000622 #" set 'operatorfunc' to a non-existing function
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000623 LET &opfunc = function('g:OpFunc1', [23])
Yegappan Lakshmanan6ae8fae2021-12-12 16:26:44 +0000624 call assert_fails("set opfunc=function('NonExistingFunc')", 'E700:')
625 call assert_fails("LET &opfunc = function('NonExistingFunc')", 'E700:')
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000626 LET g:OpFunc1Args = []
Yegappan Lakshmanan6ae8fae2021-12-12 16:26:44 +0000627 normal! g@l
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000628 call assert_equal([23, 'char'], g:OpFunc1Args)
Yegappan Lakshmanan6ae8fae2021-12-12 16:26:44 +0000629 END
Bram Moolenaar62aec932022-01-29 21:45:34 +0000630 call v9.CheckTransLegacySuccess(lines)
Yegappan Lakshmanan2172bff2021-12-08 10:46:21 +0000631
Yegappan Lakshmanandb1a4102021-12-17 16:21:20 +0000632 " Test for using a script-local function name
633 func s:OpFunc3(type)
634 let g:OpFunc3Args = [a:type]
635 endfunc
636 set opfunc=s:OpFunc3
637 let g:OpFunc3Args = []
638 normal! g@l
639 call assert_equal(['char'], g:OpFunc3Args)
640
641 let &opfunc = 's:OpFunc3'
642 let g:OpFunc3Args = []
643 normal! g@l
644 call assert_equal(['char'], g:OpFunc3Args)
645 delfunc s:OpFunc3
646
Yegappan Lakshmanan2172bff2021-12-08 10:46:21 +0000647 " Using Vim9 lambda expression in legacy context should fail
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000648 set opfunc=(a)\ =>\ OpFunc1(24,\ a)
649 let g:OpFunc1Args = []
Yegappan Lakshmanan2172bff2021-12-08 10:46:21 +0000650 call assert_fails('normal! g@l', 'E117:')
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000651 call assert_equal([], g:OpFunc1Args)
Yegappan Lakshmanan2172bff2021-12-08 10:46:21 +0000652
Yegappan Lakshmanan6ae8fae2021-12-12 16:26:44 +0000653 " set 'operatorfunc' to a partial with dict. This used to cause a crash.
654 func SetOpFunc()
655 let operator = {'execute': function('OperatorExecute')}
656 let &opfunc = operator.execute
657 endfunc
658 func OperatorExecute(_) dict
659 endfunc
660 call SetOpFunc()
661 call test_garbagecollect_now()
662 set operatorfunc=
663 delfunc SetOpFunc
664 delfunc OperatorExecute
Yegappan Lakshmanan2172bff2021-12-08 10:46:21 +0000665
666 " Vim9 tests
667 let lines =<< trim END
668 vim9script
669
Yegappan Lakshmanan2172bff2021-12-08 10:46:21 +0000670 def g:Vim9opFunc(val: number, type: string): void
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000671 g:OpFunc1Args = [val, type]
Yegappan Lakshmanan2172bff2021-12-08 10:46:21 +0000672 enddef
Yegappan Lakshmanandb1a4102021-12-17 16:21:20 +0000673
674 # Test for using a def function with opfunc
Yegappan Lakshmanan2172bff2021-12-08 10:46:21 +0000675 set opfunc=function('g:Vim9opFunc',\ [60])
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000676 g:OpFunc1Args = []
Yegappan Lakshmanan2172bff2021-12-08 10:46:21 +0000677 normal! g@l
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000678 assert_equal([60, 'char'], g:OpFunc1Args)
Yegappan Lakshmanandb1a4102021-12-17 16:21:20 +0000679
680 # Test for using a global function name
681 &opfunc = g:OpFunc2
682 g:OpFunc2Args = []
683 normal! g@l
684 assert_equal(['char'], g:OpFunc2Args)
685 bw!
686
687 # Test for using a script-local function name
Bram Moolenaar62b191c2022-02-12 20:34:50 +0000688 def LocalOpFunc(type: string): void
Yegappan Lakshmanandb1a4102021-12-17 16:21:20 +0000689 g:LocalOpFuncArgs = [type]
690 enddef
Bram Moolenaar62b191c2022-02-12 20:34:50 +0000691 &opfunc = LocalOpFunc
Yegappan Lakshmanandb1a4102021-12-17 16:21:20 +0000692 g:LocalOpFuncArgs = []
693 normal! g@l
694 assert_equal(['char'], g:LocalOpFuncArgs)
695 bw!
Yegappan Lakshmanan2172bff2021-12-08 10:46:21 +0000696 END
Bram Moolenaar62aec932022-01-29 21:45:34 +0000697 call v9.CheckScriptSuccess(lines)
Yegappan Lakshmanan2172bff2021-12-08 10:46:21 +0000698
Yegappan Lakshmanane7f4abd2021-12-24 20:47:38 +0000699 " setting 'opfunc' to a script local function outside of a script context
700 " should fail
701 let cleanup =<< trim END
702 call writefile([execute('messages')], 'Xtest.out')
703 qall
704 END
Bram Moolenaarb152b6a2022-09-29 21:37:33 +0100705 call writefile(cleanup, 'Xverify.vim', 'D')
Yegappan Lakshmanane7f4abd2021-12-24 20:47:38 +0000706 call RunVim([], [], "-c \"set opfunc=s:abc\" -S Xverify.vim")
707 call assert_match('E81: Using <SID> not in a', readfile('Xtest.out')[0])
708 call delete('Xtest.out')
Yegappan Lakshmanane7f4abd2021-12-24 20:47:38 +0000709
Yegappan Lakshmanan2172bff2021-12-08 10:46:21 +0000710 " cleanup
711 set opfunc&
Yegappan Lakshmanan04ef1fb2021-12-12 20:08:05 +0000712 delfunc OpFunc1
713 delfunc OpFunc2
714 unlet g:OpFunc1Args g:OpFunc2Args
Yegappan Lakshmanan2172bff2021-12-08 10:46:21 +0000715 %bw!
716endfunc
717
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100718func Test_normal10_expand()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200719 " Test for expand()
720 10new
721 call setline(1, ['1', 'ifooar,,cbar'])
722 2
723 norm! $
Bram Moolenaar65f08472017-09-10 18:16:20 +0200724 call assert_equal('cbar', expand('<cword>'))
725 call assert_equal('ifooar,,cbar', expand('<cWORD>'))
726
727 call setline(1, ['prx = list[idx];'])
728 1
729 let expected = ['', 'prx', 'prx', 'prx',
730 \ 'list', 'list', 'list', 'list', 'list', 'list', 'list',
731 \ 'idx', 'idx', 'idx', 'idx',
732 \ 'list[idx]',
733 \ '];',
734 \ ]
735 for i in range(1, 16)
736 exe 'norm ' . i . '|'
737 call assert_equal(expected[i], expand('<cexpr>'), 'i == ' . i)
738 endfor
739
Bram Moolenaard7e5e942020-10-07 16:54:52 +0200740 " Test for <cexpr> in state.val and ptr->val
741 call setline(1, 'x = state.val;')
742 call cursor(1, 10)
743 call assert_equal('state.val', expand('<cexpr>'))
744 call setline(1, 'x = ptr->val;')
745 call cursor(1, 9)
746 call assert_equal('ptr->val', expand('<cexpr>'))
747
Bram Moolenaarae6f8652017-12-20 22:32:20 +0100748 if executable('echo')
749 " Test expand(`...`) i.e. backticks command expansion.
Bram Moolenaar077ff432019-10-28 00:42:21 +0100750 call assert_equal('abcde', expand('`echo abcde`'))
Bram Moolenaarae6f8652017-12-20 22:32:20 +0100751 endif
752
753 " Test expand(`=...`) i.e. backticks expression expansion
754 call assert_equal('5', expand('`=2+3`'))
Bram Moolenaar8b633132020-03-20 18:20:51 +0100755 call assert_equal('3.14', expand('`=3.14`'))
Bram Moolenaarae6f8652017-12-20 22:32:20 +0100756
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200757 " clean up
758 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200759endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200760
Bram Moolenaard7e5e942020-10-07 16:54:52 +0200761" Test for expand() in latin1 encoding
762func Test_normal_expand_latin1()
763 new
764 let save_enc = &encoding
765 set encoding=latin1
766 call setline(1, 'val = item->color;')
767 call cursor(1, 11)
768 call assert_equal('color', expand("<cword>"))
769 call assert_equal('item->color', expand("<cexpr>"))
770 let &encoding = save_enc
771 bw!
772endfunc
773
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100774func Test_normal11_showcmd()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200775 " test for 'showcmd'
776 10new
777 exe "norm! ofoobar\<esc>"
778 call assert_equal(2, line('$'))
779 set showcmd
780 exe "norm! ofoobar2\<esc>"
781 call assert_equal(3, line('$'))
782 exe "norm! VAfoobar3\<esc>"
783 call assert_equal(3, line('$'))
784 exe "norm! 0d3\<del>2l"
785 call assert_equal('obar2foobar3', getline('.'))
Bram Moolenaard1ad99b2020-10-04 16:16:54 +0200786 " test for the visual block size displayed in the status line
787 call setline(1, ['aaaaa', 'bbbbb', 'ccccc'])
788 call feedkeys("ggl\<C-V>lljj", 'xt')
789 redraw!
790 call assert_match('3x3$', Screenline(&lines))
791 call feedkeys("\<C-V>", 'xt')
792 " test for visually selecting a multi-byte character
793 call setline(1, ["\U2206"])
794 call feedkeys("ggv", 'xt')
795 redraw!
796 call assert_match('1-3$', Screenline(&lines))
797 call feedkeys("v", 'xt')
Bram Moolenaard7e5e942020-10-07 16:54:52 +0200798 " test for visually selecting the end of line
799 call setline(1, ["foobar"])
800 call feedkeys("$vl", 'xt')
801 redraw!
802 call assert_match('2$', Screenline(&lines))
803 call feedkeys("y", 'xt')
804 call assert_equal("r\n", @")
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200805 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200806endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200807
Bram Moolenaar1671f442020-03-10 07:48:13 +0100808" Test for nv_error and normal command errors
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100809func Test_normal12_nv_error()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200810 10new
811 call setline(1, range(1,5))
812 " should not do anything, just beep
Bram Moolenaarf5f1e102020-03-08 05:13:15 +0100813 call assert_beeps('exe "norm! <c-k>"')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200814 call assert_equal(map(range(1,5), 'string(v:val)'), getline(1,'$'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +0100815 call assert_beeps('normal! G2dd')
816 call assert_beeps("normal! g\<C-A>")
817 call assert_beeps("normal! g\<C-X>")
818 call assert_beeps("normal! g\<C-B>")
Bram Moolenaar1671f442020-03-10 07:48:13 +0100819 call assert_beeps("normal! vQ\<Esc>")
820 call assert_beeps("normal! 2[[")
821 call assert_beeps("normal! 2]]")
822 call assert_beeps("normal! 2[]")
823 call assert_beeps("normal! 2][")
824 call assert_beeps("normal! 4[z")
825 call assert_beeps("normal! 4]z")
826 call assert_beeps("normal! 4[c")
827 call assert_beeps("normal! 4]c")
828 call assert_beeps("normal! 200%")
829 call assert_beeps("normal! %")
830 call assert_beeps("normal! 2{")
831 call assert_beeps("normal! 2}")
832 call assert_beeps("normal! r\<Right>")
833 call assert_beeps("normal! 8ry")
834 call assert_beeps('normal! "@')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200835 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200836endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200837
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100838func Test_normal13_help()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200839 " Test for F1
840 call assert_equal(1, winnr())
841 call feedkeys("\<f1>", 'txi')
842 call assert_match('help\.txt', bufname('%'))
843 call assert_equal(2, winnr('$'))
844 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200845endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200846
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100847func Test_normal14_page()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200848 " basic test for Ctrl-F and Ctrl-B
849 call Setup_NewWindow()
850 exe "norm! \<c-f>"
851 call assert_equal('9', getline('.'))
852 exe "norm! 2\<c-f>"
853 call assert_equal('25', getline('.'))
854 exe "norm! 2\<c-b>"
855 call assert_equal('18', getline('.'))
856 1
857 set scrolloff=5
858 exe "norm! 2\<c-f>"
859 call assert_equal('21', getline('.'))
860 exe "norm! \<c-b>"
861 call assert_equal('13', getline('.'))
862 1
863 set scrolloff=99
864 exe "norm! \<c-f>"
865 call assert_equal('13', getline('.'))
866 set scrolloff=0
867 100
868 exe "norm! $\<c-b>"
869 call assert_equal('92', getline('.'))
870 call assert_equal([0, 92, 1, 0, 1], getcurpos())
871 100
872 set nostartofline
873 exe "norm! $\<c-b>"
874 call assert_equal('92', getline('.'))
naohiro ono56200ee2022-01-01 14:59:44 +0000875 call assert_equal([0, 92, 2, 0, v:maxcol], getcurpos())
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200876 " cleanup
877 set startofline
878 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200879endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200880
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100881func Test_normal14_page_eol()
Bram Moolenaarbc54f3f2016-09-04 14:34:28 +0200882 10new
883 norm oxxxxxxx
884 exe "norm 2\<c-f>"
885 " check with valgrind that cursor is put back in column 1
886 exe "norm 2\<c-b>"
887 bw!
888endfunc
889
Bram Moolenaar1671f442020-03-10 07:48:13 +0100890" Test for errors with z command
891func Test_normal_z_error()
892 call assert_beeps('normal! z2p')
Christian Brabandt2fa93842021-05-30 22:17:25 +0200893 call assert_beeps('normal! zq')
Yegappan Lakshmananb0ad2d92022-01-27 13:16:59 +0000894 call assert_beeps('normal! cz1')
Bram Moolenaar1671f442020-03-10 07:48:13 +0100895endfunc
896
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100897func Test_normal15_z_scroll_vert()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200898 " basic test for z commands that scroll the window
899 call Setup_NewWindow()
900 100
901 norm! >>
902 " Test for z<cr>
903 exe "norm! z\<cr>"
904 call assert_equal(' 100', getline('.'))
905 call assert_equal(100, winsaveview()['topline'])
906 call assert_equal([0, 100, 2, 0, 9], getcurpos())
907
908 " Test for zt
909 21
910 norm! >>0zt
911 call assert_equal(' 21', getline('.'))
912 call assert_equal(21, winsaveview()['topline'])
913 call assert_equal([0, 21, 1, 0, 8], getcurpos())
914
915 " Test for zb
916 30
917 norm! >>$ztzb
918 call assert_equal(' 30', getline('.'))
919 call assert_equal(30, winsaveview()['topline']+winheight(0)-1)
naohiro ono56200ee2022-01-01 14:59:44 +0000920 call assert_equal([0, 30, 3, 0, v:maxcol], getcurpos())
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200921
922 " Test for z-
923 1
924 30
925 norm! 0z-
926 call assert_equal(' 30', getline('.'))
927 call assert_equal(30, winsaveview()['topline']+winheight(0)-1)
928 call assert_equal([0, 30, 2, 0, 9], getcurpos())
929
930 " Test for z{height}<cr>
931 call assert_equal(10, winheight(0))
932 exe "norm! z12\<cr>"
933 call assert_equal(12, winheight(0))
Yegappan Lakshmananb0ad2d92022-01-27 13:16:59 +0000934 exe "norm! z15\<Del>0\<cr>"
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200935 call assert_equal(10, winheight(0))
936
937 " Test for z.
938 1
939 21
940 norm! 0z.
941 call assert_equal(' 21', getline('.'))
942 call assert_equal(17, winsaveview()['topline'])
943 call assert_equal([0, 21, 2, 0, 9], getcurpos())
944
945 " Test for zz
946 1
947 21
948 norm! 0zz
949 call assert_equal(' 21', getline('.'))
950 call assert_equal(17, winsaveview()['topline'])
951 call assert_equal([0, 21, 1, 0, 8], getcurpos())
952
953 " Test for z+
954 11
955 norm! zt
956 norm! z+
957 call assert_equal(' 21', getline('.'))
958 call assert_equal(21, winsaveview()['topline'])
959 call assert_equal([0, 21, 2, 0, 9], getcurpos())
960
961 " Test for [count]z+
962 1
963 norm! 21z+
964 call assert_equal(' 21', getline('.'))
965 call assert_equal(21, winsaveview()['topline'])
966 call assert_equal([0, 21, 2, 0, 9], getcurpos())
967
Bram Moolenaar8a9bc952020-10-02 18:48:07 +0200968 " Test for z+ with [count] greater than buffer size
969 1
970 norm! 1000z+
971 call assert_equal(' 100', getline('.'))
972 call assert_equal(100, winsaveview()['topline'])
973 call assert_equal([0, 100, 2, 0, 9], getcurpos())
974
975 " Test for z+ from the last buffer line
976 norm! Gz.z+
977 call assert_equal(' 100', getline('.'))
978 call assert_equal(100, winsaveview()['topline'])
979 call assert_equal([0, 100, 2, 0, 9], getcurpos())
980
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200981 " Test for z^
982 norm! 22z+0
983 norm! z^
984 call assert_equal(' 21', getline('.'))
985 call assert_equal(12, winsaveview()['topline'])
986 call assert_equal([0, 21, 2, 0, 9], getcurpos())
987
Bram Moolenaar8a9bc952020-10-02 18:48:07 +0200988 " Test for z^ from first buffer line
989 norm! ggz^
990 call assert_equal('1', getline('.'))
991 call assert_equal(1, winsaveview()['topline'])
992 call assert_equal([0, 1, 1, 0, 1], getcurpos())
993
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200994 " Test for [count]z^
995 1
996 norm! 30z^
997 call assert_equal(' 21', getline('.'))
998 call assert_equal(12, winsaveview()['topline'])
999 call assert_equal([0, 21, 2, 0, 9], getcurpos())
1000
1001 " cleanup
1002 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001003endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001004
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001005func Test_normal16_z_scroll_hor()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001006 " basic test for z commands that scroll the window
1007 10new
1008 15vsp
1009 set nowrap listchars=
1010 let lineA='abcdefghijklmnopqrstuvwxyz'
1011 let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
1012 $put =lineA
1013 $put =lineB
1014 1d
1015
Bram Moolenaar1671f442020-03-10 07:48:13 +01001016 " Test for zl and zh with a count
1017 norm! 0z10l
1018 call assert_equal([11, 1], [col('.'), wincol()])
1019 norm! z4h
1020 call assert_equal([11, 5], [col('.'), wincol()])
1021 normal! 2gg
1022
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001023 " Test for zl
1024 1
1025 norm! 5zl
1026 call assert_equal(lineA, getline('.'))
1027 call assert_equal(6, col('.'))
1028 call assert_equal(5, winsaveview()['leftcol'])
1029 norm! yl
1030 call assert_equal('f', @0)
1031
1032 " Test for zh
1033 norm! 2zh
1034 call assert_equal(lineA, getline('.'))
1035 call assert_equal(6, col('.'))
1036 norm! yl
1037 call assert_equal('f', @0)
1038 call assert_equal(3, winsaveview()['leftcol'])
1039
1040 " Test for zL
1041 norm! zL
1042 call assert_equal(11, col('.'))
1043 norm! yl
1044 call assert_equal('k', @0)
1045 call assert_equal(10, winsaveview()['leftcol'])
1046 norm! 2zL
1047 call assert_equal(25, col('.'))
1048 norm! yl
1049 call assert_equal('y', @0)
1050 call assert_equal(24, winsaveview()['leftcol'])
1051
1052 " Test for zH
1053 norm! 2zH
1054 call assert_equal(25, col('.'))
1055 call assert_equal(10, winsaveview()['leftcol'])
1056 norm! yl
1057 call assert_equal('y', @0)
1058
1059 " Test for zs
1060 norm! $zs
1061 call assert_equal(26, col('.'))
1062 call assert_equal(25, winsaveview()['leftcol'])
1063 norm! yl
1064 call assert_equal('z', @0)
1065
1066 " Test for ze
1067 norm! ze
1068 call assert_equal(26, col('.'))
1069 call assert_equal(11, winsaveview()['leftcol'])
1070 norm! yl
1071 call assert_equal('z', @0)
1072
Bram Moolenaar8a9bc952020-10-02 18:48:07 +02001073 " Test for zs and ze with folds
1074 %fold
1075 norm! $zs
1076 call assert_equal(26, col('.'))
1077 call assert_equal(0, winsaveview()['leftcol'])
1078 norm! yl
1079 call assert_equal('z', @0)
1080 norm! ze
1081 call assert_equal(26, col('.'))
1082 call assert_equal(0, winsaveview()['leftcol'])
1083 norm! yl
1084 call assert_equal('z', @0)
1085
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001086 " cleanup
1087 set wrap listchars=eol:$
1088 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001089endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001090
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001091func Test_normal17_z_scroll_hor2()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001092 " basic test for z commands that scroll the window
1093 " using 'sidescrolloff' setting
1094 10new
1095 20vsp
1096 set nowrap listchars= sidescrolloff=5
1097 let lineA='abcdefghijklmnopqrstuvwxyz'
1098 let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
1099 $put =lineA
1100 $put =lineB
1101 1d
1102
1103 " Test for zl
1104 1
1105 norm! 5zl
1106 call assert_equal(lineA, getline('.'))
1107 call assert_equal(11, col('.'))
1108 call assert_equal(5, winsaveview()['leftcol'])
1109 norm! yl
1110 call assert_equal('k', @0)
1111
1112 " Test for zh
1113 norm! 2zh
1114 call assert_equal(lineA, getline('.'))
1115 call assert_equal(11, col('.'))
1116 norm! yl
1117 call assert_equal('k', @0)
1118 call assert_equal(3, winsaveview()['leftcol'])
1119
1120 " Test for zL
1121 norm! 0zL
1122 call assert_equal(16, col('.'))
1123 norm! yl
1124 call assert_equal('p', @0)
1125 call assert_equal(10, winsaveview()['leftcol'])
1126 norm! 2zL
1127 call assert_equal(26, col('.'))
1128 norm! yl
1129 call assert_equal('z', @0)
1130 call assert_equal(15, winsaveview()['leftcol'])
1131
1132 " Test for zH
1133 norm! 2zH
1134 call assert_equal(15, col('.'))
1135 call assert_equal(0, winsaveview()['leftcol'])
1136 norm! yl
1137 call assert_equal('o', @0)
1138
1139 " Test for zs
1140 norm! $zs
1141 call assert_equal(26, col('.'))
1142 call assert_equal(20, winsaveview()['leftcol'])
1143 norm! yl
1144 call assert_equal('z', @0)
1145
1146 " Test for ze
1147 norm! ze
1148 call assert_equal(26, col('.'))
1149 call assert_equal(11, winsaveview()['leftcol'])
1150 norm! yl
1151 call assert_equal('z', @0)
1152
1153 " cleanup
1154 set wrap listchars=eol:$ sidescrolloff=0
1155 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001156endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001157
Bram Moolenaarbdd2c292020-06-22 21:34:30 +02001158" Test for commands that scroll the window horizontally. Test with folds.
1159" H, M, L, CTRL-E, CTRL-Y, CTRL-U, CTRL-D, PageUp, PageDown commands
1160func Test_vert_scroll_cmds()
Bram Moolenaar1671f442020-03-10 07:48:13 +01001161 15new
1162 call setline(1, range(1, 100))
1163 exe "normal! 30ggz\<CR>"
1164 set foldenable
1165 33,36fold
1166 40,43fold
1167 46,49fold
1168 let h = winheight(0)
Bram Moolenaarbdd2c292020-06-22 21:34:30 +02001169
1170 " Test for H, M and L commands
Bram Moolenaar1671f442020-03-10 07:48:13 +01001171 " Top of the screen = 30
1172 " Folded lines = 9
1173 " Bottom of the screen = 30 + h + 9 - 1
1174 normal! 4L
1175 call assert_equal(35 + h, line('.'))
1176 normal! 4H
1177 call assert_equal(33, line('.'))
Bram Moolenaarbdd2c292020-06-22 21:34:30 +02001178
Bram Moolenaar8a9bc952020-10-02 18:48:07 +02001179 " Test for using a large count value
1180 %d
1181 call setline(1, range(1, 4))
1182 norm! 6H
1183 call assert_equal(4, line('.'))
1184
1185 " Test for 'M' with folded lines
1186 %d
1187 call setline(1, range(1, 20))
1188 1,5fold
1189 norm! LM
1190 call assert_equal(12, line('.'))
1191
Bram Moolenaarbdd2c292020-06-22 21:34:30 +02001192 " Test for the CTRL-E and CTRL-Y commands with folds
1193 %d
1194 call setline(1, range(1, 10))
1195 3,5fold
1196 exe "normal 6G3\<C-E>"
1197 call assert_equal(6, line('w0'))
1198 exe "normal 2\<C-Y>"
1199 call assert_equal(2, line('w0'))
1200
1201 " Test for CTRL-Y on a folded line
1202 %d
1203 call setline(1, range(1, 100))
1204 exe (h + 2) .. "," .. (h + 4) .. "fold"
1205 exe h + 5
1206 normal z-
1207 exe "normal \<C-Y>\<C-Y>"
1208 call assert_equal(h + 1, line('w$'))
1209
Bram Moolenaard1ad99b2020-10-04 16:16:54 +02001210 " Test for CTRL-Y from the first line and CTRL-E from the last line
1211 %d
1212 set scrolloff=2
1213 call setline(1, range(1, 4))
1214 exe "normal gg\<C-Y>"
1215 call assert_equal(1, line('w0'))
1216 call assert_equal(1, line('.'))
1217 exe "normal G4\<C-E>\<C-E>"
1218 call assert_equal(4, line('w$'))
1219 call assert_equal(4, line('.'))
1220 set scrolloff&
1221
Bram Moolenaarbdd2c292020-06-22 21:34:30 +02001222 " Using <PageUp> and <PageDown> in an empty buffer should beep
1223 %d
1224 call assert_beeps('exe "normal \<PageUp>"')
1225 call assert_beeps('exe "normal \<C-B>"')
1226 call assert_beeps('exe "normal \<PageDown>"')
1227 call assert_beeps('exe "normal \<C-F>"')
1228
1229 " Test for <C-U> and <C-D> with fold
1230 %d
1231 call setline(1, range(1, 100))
1232 10,35fold
1233 set scroll=10
1234 exe "normal \<C-D>"
1235 call assert_equal(36, line('.'))
1236 exe "normal \<C-D>"
1237 call assert_equal(46, line('.'))
1238 exe "normal \<C-U>"
1239 call assert_equal(36, line('.'))
1240 exe "normal \<C-U>"
1241 call assert_equal(10, line('.'))
1242 exe "normal \<C-U>"
1243 call assert_equal(1, line('.'))
1244 set scroll&
1245
1246 " Test for scrolling to the top of the file with <C-U> and a fold
1247 10
1248 normal ztL
1249 exe "normal \<C-U>\<C-U>"
1250 call assert_equal(1, line('w0'))
1251
1252 " Test for CTRL-D on a folded line
1253 %d
1254 call setline(1, range(1, 100))
1255 50,100fold
1256 75
1257 normal z-
1258 exe "normal \<C-D>"
1259 call assert_equal(50, line('.'))
1260 call assert_equal(100, line('w$'))
1261 normal z.
1262 let lnum = winline()
1263 exe "normal \<C-D>"
1264 call assert_equal(lnum, winline())
1265 call assert_equal(50, line('.'))
1266 normal zt
1267 exe "normal \<C-D>"
1268 call assert_equal(50, line('w0'))
1269
Bram Moolenaard1ad99b2020-10-04 16:16:54 +02001270 " Test for <S-CR>. Page down.
1271 %d
1272 call setline(1, range(1, 100))
1273 call feedkeys("\<S-CR>", 'xt')
1274 call assert_equal(14, line('w0'))
1275 call assert_equal(28, line('w$'))
1276
1277 " Test for <S-->. Page up.
1278 call feedkeys("\<S-->", 'xt')
1279 call assert_equal(1, line('w0'))
1280 call assert_equal(15, line('w$'))
1281
Bram Moolenaar1671f442020-03-10 07:48:13 +01001282 set foldenable&
Yee Cheng Chin1881abf2022-12-08 09:41:24 +00001283 bwipe!
Bram Moolenaar1671f442020-03-10 07:48:13 +01001284endfunc
1285
Bram Moolenaar777e7c22021-10-25 17:07:04 +01001286func Test_scroll_in_ex_mode()
1287 " This was using invalid memory because w_botline was invalid.
1288 let lines =<< trim END
1289 diffsplit
1290 norm os00(
1291 call writefile(['done'], 'Xdone')
1292 qa!
1293 END
Bram Moolenaarb152b6a2022-09-29 21:37:33 +01001294 call writefile(lines, 'Xscript', 'D')
Bram Moolenaar777e7c22021-10-25 17:07:04 +01001295 call assert_equal(1, RunVim([], [], '--clean -X -Z -e -s -S Xscript'))
1296 call assert_equal(['done'], readfile('Xdone'))
1297
Bram Moolenaar777e7c22021-10-25 17:07:04 +01001298 call delete('Xdone')
1299endfunc
1300
Bram Moolenaarbdd2c292020-06-22 21:34:30 +02001301" Test for the 'sidescroll' option
1302func Test_sidescroll_opt()
1303 new
1304 20vnew
1305
1306 " scroll by 2 characters horizontally
1307 set sidescroll=2 nowrap
1308 call setline(1, repeat('a', 40))
1309 normal g$l
1310 call assert_equal(19, screenpos(0, 1, 21).col)
1311 normal l
1312 call assert_equal(20, screenpos(0, 1, 22).col)
1313 normal g0h
1314 call assert_equal(2, screenpos(0, 1, 2).col)
1315 call assert_equal(20, screenpos(0, 1, 20).col)
1316
1317 " when 'sidescroll' is 0, cursor positioned at the center
1318 set sidescroll=0
1319 normal g$l
1320 call assert_equal(11, screenpos(0, 1, 21).col)
1321 normal g0h
1322 call assert_equal(10, screenpos(0, 1, 10).col)
1323
1324 %bw!
1325 set wrap& sidescroll&
1326endfunc
1327
Bram Moolenaar004a6782020-04-11 17:09:31 +02001328" basic tests for foldopen/folddelete
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001329func Test_normal18_z_fold()
Bram Moolenaar004a6782020-04-11 17:09:31 +02001330 CheckFeature folding
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001331 call Setup_NewWindow()
1332 50
1333 setl foldenable fdm=marker foldlevel=5
1334
Bram Moolenaar1671f442020-03-10 07:48:13 +01001335 call assert_beeps('normal! zj')
1336 call assert_beeps('normal! zk')
1337
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001338 " Test for zF
1339 " First fold
1340 norm! 4zF
1341 " check that folds have been created
1342 call assert_equal(['50/*{{{*/', '51', '52', '53/*}}}*/'], getline(50,53))
1343
1344 " Test for zd
1345 51
1346 norm! 2zF
1347 call assert_equal(2, foldlevel('.'))
1348 norm! kzd
1349 call assert_equal(['50', '51/*{{{*/', '52/*}}}*/', '53'], getline(50,53))
1350 norm! j
1351 call assert_equal(1, foldlevel('.'))
1352
1353 " Test for zD
1354 " also deletes partially selected folds recursively
1355 51
1356 norm! zF
1357 call assert_equal(2, foldlevel('.'))
1358 norm! kV2jzD
1359 call assert_equal(['50', '51', '52', '53'], getline(50,53))
1360
1361 " Test for zE
1362 85
1363 norm! 4zF
1364 86
1365 norm! 2zF
1366 90
1367 norm! 4zF
1368 call assert_equal(['85/*{{{*/', '86/*{{{*/', '87/*}}}*/', '88/*}}}*/', '89', '90/*{{{*/', '91', '92', '93/*}}}*/'], getline(85,93))
1369 norm! zE
1370 call assert_equal(['85', '86', '87', '88', '89', '90', '91', '92', '93'], getline(85,93))
1371
1372 " Test for zn
1373 50
1374 set foldlevel=0
1375 norm! 2zF
1376 norm! zn
1377 norm! k
1378 call assert_equal('49', getline('.'))
1379 norm! j
1380 call assert_equal('50/*{{{*/', getline('.'))
1381 norm! j
1382 call assert_equal('51/*}}}*/', getline('.'))
1383 norm! j
1384 call assert_equal('52', getline('.'))
1385 call assert_equal(0, &foldenable)
1386
1387 " Test for zN
1388 49
1389 norm! zN
1390 call assert_equal('49', getline('.'))
1391 norm! j
1392 call assert_equal('50/*{{{*/', getline('.'))
1393 norm! j
1394 call assert_equal('52', getline('.'))
1395 call assert_equal(1, &foldenable)
1396
1397 " Test for zi
1398 norm! zi
1399 call assert_equal(0, &foldenable)
1400 norm! zi
1401 call assert_equal(1, &foldenable)
1402 norm! zi
1403 call assert_equal(0, &foldenable)
1404 norm! zi
1405 call assert_equal(1, &foldenable)
1406
1407 " Test for za
1408 50
1409 norm! za
1410 norm! k
1411 call assert_equal('49', getline('.'))
1412 norm! j
1413 call assert_equal('50/*{{{*/', getline('.'))
1414 norm! j
1415 call assert_equal('51/*}}}*/', getline('.'))
1416 norm! j
1417 call assert_equal('52', getline('.'))
1418 50
1419 norm! za
1420 norm! k
1421 call assert_equal('49', getline('.'))
1422 norm! j
1423 call assert_equal('50/*{{{*/', getline('.'))
1424 norm! j
1425 call assert_equal('52', getline('.'))
1426
1427 49
1428 norm! 5zF
1429 norm! k
1430 call assert_equal('48', getline('.'))
1431 norm! j
1432 call assert_equal('49/*{{{*/', getline('.'))
1433 norm! j
1434 call assert_equal('55', getline('.'))
1435 49
1436 norm! za
1437 call assert_equal('49/*{{{*/', getline('.'))
1438 norm! j
1439 call assert_equal('50/*{{{*/', getline('.'))
1440 norm! j
1441 call assert_equal('52', getline('.'))
1442 set nofoldenable
1443 " close fold and set foldenable
1444 norm! za
1445 call assert_equal(1, &foldenable)
1446
1447 50
1448 " have to use {count}za to open all folds and make the cursor visible
1449 norm! 2za
1450 norm! 2k
1451 call assert_equal('48', getline('.'))
1452 norm! j
1453 call assert_equal('49/*{{{*/', getline('.'))
1454 norm! j
1455 call assert_equal('50/*{{{*/', getline('.'))
1456 norm! j
1457 call assert_equal('51/*}}}*/', getline('.'))
1458 norm! j
1459 call assert_equal('52', getline('.'))
1460
1461 " Test for zA
1462 49
1463 set foldlevel=0
1464 50
1465 norm! zA
1466 norm! 2k
1467 call assert_equal('48', getline('.'))
1468 norm! j
1469 call assert_equal('49/*{{{*/', getline('.'))
1470 norm! j
1471 call assert_equal('50/*{{{*/', getline('.'))
1472 norm! j
1473 call assert_equal('51/*}}}*/', getline('.'))
1474 norm! j
1475 call assert_equal('52', getline('.'))
1476
Dominique Pelle923dce22021-11-21 11:36:04 +00001477 " zA on an opened fold when foldenable is not set
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001478 50
1479 set nofoldenable
1480 norm! zA
1481 call assert_equal(1, &foldenable)
1482 norm! k
1483 call assert_equal('48', getline('.'))
1484 norm! j
1485 call assert_equal('49/*{{{*/', getline('.'))
1486 norm! j
1487 call assert_equal('55', getline('.'))
1488
1489 " Test for zc
1490 norm! zE
1491 50
1492 norm! 2zF
1493 49
1494 norm! 5zF
1495 set nofoldenable
1496 50
1497 " There most likely is a bug somewhere:
1498 " https://groups.google.com/d/msg/vim_dev/v2EkfJ_KQjI/u-Cvv94uCAAJ
1499 " TODO: Should this only close the inner most fold or both folds?
1500 norm! zc
1501 call assert_equal(1, &foldenable)
1502 norm! k
1503 call assert_equal('48', getline('.'))
1504 norm! j
1505 call assert_equal('49/*{{{*/', getline('.'))
1506 norm! j
1507 call assert_equal('55', getline('.'))
1508 set nofoldenable
1509 50
1510 norm! Vjzc
1511 norm! k
1512 call assert_equal('48', getline('.'))
1513 norm! j
1514 call assert_equal('49/*{{{*/', getline('.'))
1515 norm! j
1516 call assert_equal('55', getline('.'))
1517
1518 " Test for zC
1519 set nofoldenable
1520 50
1521 norm! zCk
1522 call assert_equal('48', getline('.'))
1523 norm! j
1524 call assert_equal('49/*{{{*/', getline('.'))
1525 norm! j
1526 call assert_equal('55', getline('.'))
1527
1528 " Test for zx
1529 " 1) close folds at line 49-54
1530 set nofoldenable
1531 48
1532 norm! zx
1533 call assert_equal(1, &foldenable)
1534 norm! j
1535 call assert_equal('49/*{{{*/', getline('.'))
1536 norm! j
1537 call assert_equal('55', getline('.'))
1538
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02001539 " 2) do not close fold under cursor
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001540 51
1541 set nofoldenable
1542 norm! zx
1543 call assert_equal(1, &foldenable)
1544 norm! 3k
1545 call assert_equal('48', getline('.'))
1546 norm! j
1547 call assert_equal('49/*{{{*/', getline('.'))
1548 norm! j
1549 call assert_equal('50/*{{{*/', getline('.'))
1550 norm! j
1551 call assert_equal('51/*}}}*/', getline('.'))
1552 norm! j
1553 call assert_equal('52', getline('.'))
1554 norm! j
1555 call assert_equal('53', getline('.'))
1556 norm! j
1557 call assert_equal('54/*}}}*/', getline('.'))
1558 norm! j
1559 call assert_equal('55', getline('.'))
1560
1561 " 3) close one level of folds
1562 48
1563 set nofoldenable
1564 set foldlevel=1
1565 norm! zx
1566 call assert_equal(1, &foldenable)
1567 call assert_equal('48', getline('.'))
1568 norm! j
1569 call assert_equal('49/*{{{*/', getline('.'))
1570 norm! j
1571 call assert_equal('50/*{{{*/', getline('.'))
1572 norm! j
1573 call assert_equal('52', getline('.'))
1574 norm! j
1575 call assert_equal('53', getline('.'))
1576 norm! j
1577 call assert_equal('54/*}}}*/', getline('.'))
1578 norm! j
1579 call assert_equal('55', getline('.'))
1580
1581 " Test for zX
1582 " Close all folds
1583 set foldlevel=0 nofoldenable
1584 50
1585 norm! zX
1586 call assert_equal(1, &foldenable)
1587 norm! k
1588 call assert_equal('48', getline('.'))
1589 norm! j
1590 call assert_equal('49/*{{{*/', getline('.'))
1591 norm! j
1592 call assert_equal('55', getline('.'))
1593
1594 " Test for zm
1595 50
1596 set nofoldenable foldlevel=2
1597 norm! zm
1598 call assert_equal(1, &foldenable)
1599 call assert_equal(1, &foldlevel)
1600 norm! zm
1601 call assert_equal(0, &foldlevel)
1602 norm! zm
1603 call assert_equal(0, &foldlevel)
1604 norm! k
1605 call assert_equal('48', getline('.'))
1606 norm! j
1607 call assert_equal('49/*{{{*/', getline('.'))
1608 norm! j
1609 call assert_equal('55', getline('.'))
1610
Bram Moolenaar8a9bc952020-10-02 18:48:07 +02001611 " Test for zm with a count
1612 50
1613 set foldlevel=2
1614 norm! 3zm
1615 call assert_equal(0, &foldlevel)
1616 call assert_equal(49, foldclosed(line('.')))
1617
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001618 " Test for zM
1619 48
1620 set nofoldenable foldlevel=99
1621 norm! zM
1622 call assert_equal(1, &foldenable)
1623 call assert_equal(0, &foldlevel)
1624 call assert_equal('48', getline('.'))
1625 norm! j
1626 call assert_equal('49/*{{{*/', getline('.'))
1627 norm! j
1628 call assert_equal('55', getline('.'))
1629
1630 " Test for zr
1631 48
1632 set nofoldenable foldlevel=0
1633 norm! zr
1634 call assert_equal(0, &foldenable)
1635 call assert_equal(1, &foldlevel)
1636 set foldlevel=0 foldenable
1637 norm! zr
1638 call assert_equal(1, &foldenable)
1639 call assert_equal(1, &foldlevel)
1640 norm! zr
1641 call assert_equal(2, &foldlevel)
1642 call assert_equal('48', getline('.'))
1643 norm! j
1644 call assert_equal('49/*{{{*/', getline('.'))
1645 norm! j
1646 call assert_equal('50/*{{{*/', getline('.'))
1647 norm! j
1648 call assert_equal('51/*}}}*/', getline('.'))
1649 norm! j
1650 call assert_equal('52', getline('.'))
1651
1652 " Test for zR
1653 48
1654 set nofoldenable foldlevel=0
1655 norm! zR
1656 call assert_equal(0, &foldenable)
1657 call assert_equal(2, &foldlevel)
1658 set foldenable foldlevel=0
1659 norm! zR
1660 call assert_equal(1, &foldenable)
1661 call assert_equal(2, &foldlevel)
1662 call assert_equal('48', getline('.'))
1663 norm! j
1664 call assert_equal('49/*{{{*/', getline('.'))
1665 norm! j
1666 call assert_equal('50/*{{{*/', getline('.'))
1667 norm! j
1668 call assert_equal('51/*}}}*/', getline('.'))
1669 norm! j
1670 call assert_equal('52', getline('.'))
1671 call append(50, ['a /*{{{*/', 'b /*}}}*/'])
1672 48
1673 call assert_equal('48', getline('.'))
1674 norm! j
1675 call assert_equal('49/*{{{*/', getline('.'))
1676 norm! j
1677 call assert_equal('50/*{{{*/', getline('.'))
1678 norm! j
1679 call assert_equal('a /*{{{*/', getline('.'))
1680 norm! j
1681 call assert_equal('51/*}}}*/', getline('.'))
1682 norm! j
1683 call assert_equal('52', getline('.'))
1684 48
1685 norm! zR
1686 call assert_equal(1, &foldenable)
1687 call assert_equal(3, &foldlevel)
1688 call assert_equal('48', getline('.'))
1689 norm! j
1690 call assert_equal('49/*{{{*/', getline('.'))
1691 norm! j
1692 call assert_equal('50/*{{{*/', getline('.'))
1693 norm! j
1694 call assert_equal('a /*{{{*/', getline('.'))
1695 norm! j
1696 call assert_equal('b /*}}}*/', getline('.'))
1697 norm! j
1698 call assert_equal('51/*}}}*/', getline('.'))
1699 norm! j
1700 call assert_equal('52', getline('.'))
1701
1702 " clean up
1703 setl nofoldenable fdm=marker foldlevel=0
1704 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001705endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001706
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001707func Test_normal20_exmode()
Bram Moolenaar004a6782020-04-11 17:09:31 +02001708 " Reading from redirected file doesn't work on MS-Windows
1709 CheckNotMSWindows
Bram Moolenaarb152b6a2022-09-29 21:37:33 +01001710 call writefile(['1a', 'foo', 'bar', '.', 'w! Xn20file2', 'q!'], 'Xn20script', 'D')
1711 call writefile(['1', '2'], 'Xn20file', 'D')
Bram Moolenaarb18b4962022-09-02 21:55:50 +01001712 call system(GetVimCommand() .. ' -e -s < Xn20script Xn20file')
Bram Moolenaarb152b6a2022-09-29 21:37:33 +01001713 let a = readfile('Xn20file2')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001714 call assert_equal(['1', 'foo', 'bar', '2'], a)
1715
1716 " clean up
Bram Moolenaarb152b6a2022-09-29 21:37:33 +01001717 call delete('Xn20file2')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001718 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001719endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001720
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001721func Test_normal21_nv_hat()
1722
1723 " Edit a fresh file and wipe the buffer list so that there is no alternate
1724 " file present. Next, check for the expected command failures.
1725 edit Xfoo | %bw
Bram Moolenaare2e40752020-09-04 21:18:46 +02001726 call assert_fails(':buffer #', 'E86:')
1727 call assert_fails(':execute "normal! \<C-^>"', 'E23:')
Bram Moolenaarb7e24832020-06-24 13:37:35 +02001728 call assert_fails("normal i\<C-R>#", 'E23:')
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001729
1730 " Test for the expected behavior when switching between two named buffers.
1731 edit Xfoo | edit Xbar
1732 call feedkeys("\<C-^>", 'tx')
1733 call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t'))
1734 call feedkeys("\<C-^>", 'tx')
1735 call assert_equal('Xbar', fnamemodify(bufname('%'), ':t'))
1736
1737 " Test for the expected behavior when only one buffer is named.
1738 enew | let l:nr = bufnr('%')
1739 call feedkeys("\<C-^>", 'tx')
1740 call assert_equal('Xbar', fnamemodify(bufname('%'), ':t'))
1741 call feedkeys("\<C-^>", 'tx')
1742 call assert_equal('', bufname('%'))
1743 call assert_equal(l:nr, bufnr('%'))
1744
1745 " Test that no action is taken by "<C-^>" when an operator is pending.
1746 edit Xfoo
1747 call feedkeys("ci\<C-^>", 'tx')
1748 call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t'))
1749
1750 %bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001751endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001752
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001753func Test_normal22_zet()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001754 " Test for ZZ
Bram Moolenaar0913a102016-09-03 19:11:59 +02001755 " let shell = &shell
1756 " let &shell = 'sh'
Bram Moolenaarb152b6a2022-09-29 21:37:33 +01001757 call writefile(['1', '2'], 'Xn22file', 'D')
Bram Moolenaar93344c22019-08-14 21:12:05 +02001758 let args = ' -N -i NONE --noplugins -X --not-a-term'
Bram Moolenaarb18b4962022-09-02 21:55:50 +01001759 call system(GetVimCommand() .. args .. ' -c "%d" -c ":norm! ZZ" Xn22file')
1760 let a = readfile('Xn22file')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001761 call assert_equal([], a)
1762 " Test for ZQ
Bram Moolenaarb18b4962022-09-02 21:55:50 +01001763 call writefile(['1', '2'], 'Xn22file')
1764 call system(GetVimCommand() . args . ' -c "%d" -c ":norm! ZQ" Xn22file')
1765 let a = readfile('Xn22file')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001766 call assert_equal(['1', '2'], a)
1767
Bram Moolenaar1671f442020-03-10 07:48:13 +01001768 " Unsupported Z command
1769 call assert_beeps('normal! ZW')
1770
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001771 " clean up
Bram Moolenaar0913a102016-09-03 19:11:59 +02001772 " let &shell = shell
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001773endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001774
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001775func Test_normal23_K()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001776 " Test for K command
1777 new
Bram Moolenaar426f3752016-11-04 21:22:37 +01001778 call append(0, ['version8.txt', 'man', 'aa%bb', 'cc|dd'])
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001779 let k = &keywordprg
1780 set keywordprg=:help
1781 1
1782 norm! VK
1783 call assert_equal('version8.txt', fnamemodify(bufname('%'), ':t'))
1784 call assert_equal('help', &ft)
1785 call assert_match('\*version8.txt\*', getline('.'))
1786 helpclose
1787 norm! 0K
1788 call assert_equal('version8.txt', fnamemodify(bufname('%'), ':t'))
1789 call assert_equal('help', &ft)
Bram Moolenaarb1c91982018-05-17 17:04:55 +02001790 call assert_match('\*version8\.\d\*', getline('.'))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001791 helpclose
1792
Bram Moolenaar426f3752016-11-04 21:22:37 +01001793 set keywordprg=:new
1794 set iskeyword+=%
1795 set iskeyword+=\|
1796 2
1797 norm! K
1798 call assert_equal('man', fnamemodify(bufname('%'), ':t'))
1799 bwipe!
1800 3
1801 norm! K
1802 call assert_equal('aa%bb', fnamemodify(bufname('%'), ':t'))
1803 bwipe!
Bram Moolenaareb828d02016-11-05 19:54:01 +01001804 if !has('win32')
1805 4
1806 norm! K
1807 call assert_equal('cc|dd', fnamemodify(bufname('%'), ':t'))
1808 bwipe!
1809 endif
Bram Moolenaar426f3752016-11-04 21:22:37 +01001810 set iskeyword-=%
1811 set iskeyword-=\|
1812
Bram Moolenaar8a9bc952020-10-02 18:48:07 +02001813 " Test for specifying a count to K
1814 1
1815 com! -nargs=* Kprog let g:Kprog_Args = <q-args>
1816 set keywordprg=:Kprog
1817 norm! 3K
1818 call assert_equal('3 version8', g:Kprog_Args)
1819 delcom Kprog
1820
Bram Moolenaar0913a102016-09-03 19:11:59 +02001821 " Only expect "man" to work on Unix
1822 if !has("unix")
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001823 let &keywordprg = k
1824 bw!
1825 return
1826 endif
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02001827
Bram Moolenaar9134f1e2019-11-29 20:26:13 +01001828 let not_gnu_man = has('mac') || has('bsd')
1829 if not_gnu_man
Dominique Pelle923dce22021-11-21 11:36:04 +00001830 " In macOS and BSD, the option for specifying a pager is different
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02001831 set keywordprg=man\ -P\ cat
1832 else
1833 set keywordprg=man\ --pager=cat
1834 endif
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001835 " Test for using man
1836 2
1837 let a = execute('unsilent norm! K')
Bram Moolenaar9134f1e2019-11-29 20:26:13 +01001838 if not_gnu_man
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02001839 call assert_match("man -P cat 'man'", a)
1840 else
1841 call assert_match("man --pager=cat 'man'", a)
1842 endif
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001843
Bram Moolenaar1671f442020-03-10 07:48:13 +01001844 " Error cases
1845 call setline(1, '#$#')
1846 call assert_fails('normal! ggK', 'E349:')
1847 call setline(1, '---')
1848 call assert_fails('normal! ggv2lK', 'E349:')
1849 call setline(1, ['abc', 'xyz'])
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001850 call assert_fails("normal! gg2lv2h\<C-]>", 'E433:')
Bram Moolenaar1671f442020-03-10 07:48:13 +01001851 call assert_beeps("normal! ggVjK")
Bram Moolenaar8a9bc952020-10-02 18:48:07 +02001852 norm! V
1853 call assert_beeps("norm! cK")
Bram Moolenaar1671f442020-03-10 07:48:13 +01001854
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001855 " clean up
1856 let &keywordprg = k
1857 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001858endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001859
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001860func Test_normal24_rot13()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001861 " Testing for g?? g?g?
1862 new
1863 call append(0, 'abcdefghijklmnopqrstuvwxyzäüö')
1864 1
1865 norm! g??
1866 call assert_equal('nopqrstuvwxyzabcdefghijklmäüö', getline('.'))
1867 norm! g?g?
1868 call assert_equal('abcdefghijklmnopqrstuvwxyzäüö', getline('.'))
1869
1870 " clean up
1871 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001872endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001873
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001874func Test_normal25_tag()
Bram Moolenaar5a4c3082019-12-01 15:23:11 +01001875 CheckFeature quickfix
1876
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001877 " Testing for CTRL-] g CTRL-] g]
1878 " CTRL-W g] CTRL-W CTRL-] CTRL-W g CTRL-]
1879 h
1880 " Test for CTRL-]
1881 call search('\<x\>$')
1882 exe "norm! \<c-]>"
1883 call assert_equal("change.txt", fnamemodify(bufname('%'), ':t'))
1884 norm! yiW
1885 call assert_equal("*x*", @0)
1886 exe ":norm \<c-o>"
1887
1888 " Test for g_CTRL-]
1889 call search('\<v_u\>$')
1890 exe "norm! g\<c-]>"
1891 call assert_equal("change.txt", fnamemodify(bufname('%'), ':t'))
1892 norm! yiW
1893 call assert_equal("*v_u*", @0)
1894 exe ":norm \<c-o>"
1895
1896 " Test for g]
1897 call search('\<i_<Esc>$')
1898 let a = execute(":norm! g]")
1899 call assert_match('i_<Esc>.*insert.txt', a)
1900
1901 if !empty(exepath('cscope')) && has('cscope')
1902 " setting cscopetag changes how g] works
1903 set cst
1904 exe "norm! g]"
1905 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
1906 norm! yiW
1907 call assert_equal("*i_<Esc>*", @0)
1908 exe ":norm \<c-o>"
1909 " Test for CTRL-W g]
1910 exe "norm! \<C-W>g]"
1911 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
1912 norm! yiW
1913 call assert_equal("*i_<Esc>*", @0)
1914 call assert_equal(3, winnr('$'))
1915 helpclose
1916 set nocst
1917 endif
1918
1919 " Test for CTRL-W g]
1920 let a = execute("norm! \<C-W>g]")
1921 call assert_match('i_<Esc>.*insert.txt', a)
1922
1923 " Test for CTRL-W CTRL-]
1924 exe "norm! \<C-W>\<C-]>"
1925 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
1926 norm! yiW
1927 call assert_equal("*i_<Esc>*", @0)
1928 call assert_equal(3, winnr('$'))
1929 helpclose
1930
1931 " Test for CTRL-W g CTRL-]
1932 exe "norm! \<C-W>g\<C-]>"
1933 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
1934 norm! yiW
1935 call assert_equal("*i_<Esc>*", @0)
1936 call assert_equal(3, winnr('$'))
1937 helpclose
1938
1939 " clean up
1940 helpclose
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001941endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001942
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001943func Test_normal26_put()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001944 " Test for ]p ]P [p and [P
1945 new
1946 call append(0, ['while read LINE', 'do', ' ((count++))', ' if [ $? -ne 0 ]; then', " echo 'Error writing file'", ' fi', 'done'])
1947 1
1948 /Error/y a
1949 2
1950 norm! "a]pj"a[p
1951 call assert_equal(['do', "echo 'Error writing file'", " echo 'Error writing file'", ' ((count++))'], getline(2,5))
1952 1
1953 /^\s\{4}/
1954 exe "norm! \"a]P3Eldt'"
1955 exe "norm! j\"a[P2Eldt'"
1956 call assert_equal([' if [ $? -ne 0 ]; then', " echo 'Error writing'", " echo 'Error'", " echo 'Error writing file'", ' fi'], getline(6,10))
1957
1958 " clean up
1959 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001960endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001961
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001962func Test_normal27_bracket()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001963 " Test for [' [` ]' ]`
1964 call Setup_NewWindow()
1965 1,21s/.\+/ & b/
1966 1
1967 norm! $ma
1968 5
1969 norm! $mb
1970 10
1971 norm! $mc
1972 15
1973 norm! $md
1974 20
1975 norm! $me
1976
1977 " Test for ['
1978 9
1979 norm! 2['
1980 call assert_equal(' 1 b', getline('.'))
1981 call assert_equal(1, line('.'))
1982 call assert_equal(3, col('.'))
1983
1984 " Test for ]'
1985 norm! ]'
1986 call assert_equal(' 5 b', getline('.'))
1987 call assert_equal(5, line('.'))
1988 call assert_equal(3, col('.'))
1989
zeertzjqcf344342022-07-06 12:57:31 +01001990 " No mark before line 1, cursor moves to first non-blank on current line
1991 1
1992 norm! 5|['
1993 call assert_equal(' 1 b', getline('.'))
1994 call assert_equal(1, line('.'))
1995 call assert_equal(3, col('.'))
1996
1997 " No mark after line 21, cursor moves to first non-blank on current line
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001998 21
zeertzjqcf344342022-07-06 12:57:31 +01001999 norm! 5|]'
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002000 call assert_equal(' 21 b', getline('.'))
2001 call assert_equal(21, line('.'))
2002 call assert_equal(3, col('.'))
2003
2004 " Test for [`
2005 norm! 2[`
2006 call assert_equal(' 15 b', getline('.'))
2007 call assert_equal(15, line('.'))
2008 call assert_equal(8, col('.'))
2009
2010 " Test for ]`
2011 norm! ]`
2012 call assert_equal(' 20 b', getline('.'))
2013 call assert_equal(20, line('.'))
2014 call assert_equal(8, col('.'))
2015
zeertzjqcf344342022-07-06 12:57:31 +01002016 " No mark before line 1, cursor does not move
2017 1
2018 norm! 5|[`
2019 call assert_equal(' 1 b', getline('.'))
2020 call assert_equal(1, line('.'))
2021 call assert_equal(5, col('.'))
2022
2023 " No mark after line 21, cursor does not move
2024 21
2025 norm! 5|]`
2026 call assert_equal(' 21 b', getline('.'))
2027 call assert_equal(21, line('.'))
2028 call assert_equal(5, col('.'))
2029
2030 " Count too large for [`
2031 " cursor moves to first lowercase mark
2032 norm! 99[`
2033 call assert_equal(' 1 b', getline('.'))
2034 call assert_equal(1, line('.'))
2035 call assert_equal(7, col('.'))
2036
2037 " Count too large for ]`
2038 " cursor moves to last lowercase mark
2039 norm! 99]`
2040 call assert_equal(' 20 b', getline('.'))
2041 call assert_equal(20, line('.'))
2042 call assert_equal(8, col('.'))
2043
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002044 " clean up
2045 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002046endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002047
Bram Moolenaar1671f442020-03-10 07:48:13 +01002048" Test for ( and ) sentence movements
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002049func Test_normal28_parenthesis()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002050 new
2051 call append(0, ['This is a test. With some sentences!', '', 'Even with a question? And one more. And no sentence here'])
2052
2053 $
2054 norm! d(
2055 call assert_equal(['This is a test. With some sentences!', '', 'Even with a question? And one more. ', ''], getline(1, '$'))
2056 norm! 2d(
2057 call assert_equal(['This is a test. With some sentences!', '', ' ', ''], getline(1, '$'))
2058 1
2059 norm! 0d)
2060 call assert_equal(['With some sentences!', '', ' ', ''], getline(1, '$'))
2061
2062 call append('$', ['This is a long sentence', '', 'spanning', 'over several lines. '])
2063 $
2064 norm! $d(
2065 call assert_equal(['With some sentences!', '', ' ', '', 'This is a long sentence', ''], getline(1, '$'))
2066
Bram Moolenaar224a5f12020-04-28 20:29:07 +02002067 " Move to the next sentence from a paragraph macro
2068 %d
2069 call setline(1, ['.LP', 'blue sky!. blue sky.', 'blue sky. blue sky.'])
2070 call cursor(1, 1)
2071 normal )
2072 call assert_equal([2, 1], [line('.'), col('.')])
2073 normal )
2074 call assert_equal([2, 12], [line('.'), col('.')])
2075 normal ((
2076 call assert_equal([1, 1], [line('.'), col('.')])
2077
Bram Moolenaar1671f442020-03-10 07:48:13 +01002078 " It is an error if a next sentence is not found
2079 %d
2080 call setline(1, '.SH')
2081 call assert_beeps('normal )')
2082
Bram Moolenaar224a5f12020-04-28 20:29:07 +02002083 " If only dot is present, don't treat that as a sentence
2084 call setline(1, '. This is a sentence.')
2085 normal $((
2086 call assert_equal(3, col('.'))
2087
Bram Moolenaar1671f442020-03-10 07:48:13 +01002088 " Jumping to a fold should open the fold
2089 call setline(1, ['', '', 'one', 'two', 'three'])
2090 set foldenable
2091 2,$fold
2092 call feedkeys(')', 'xt')
2093 call assert_equal(3, line('.'))
2094 call assert_equal(1, foldlevel('.'))
2095 call assert_equal(-1, foldclosed('.'))
2096 set foldenable&
2097
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002098 " clean up
2099 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002100endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002101
Bram Moolenaar1671f442020-03-10 07:48:13 +01002102" Test for { and } paragraph movements
2103func Test_normal29_brace()
Bram Moolenaarc79745a2019-05-20 22:12:34 +02002104 let text =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02002105 A paragraph begins after each empty line, and also at each of a set of
2106 paragraph macros, specified by the pairs of characters in the 'paragraphs'
2107 option. The default is "IPLPPPQPP TPHPLIPpLpItpplpipbp", which corresponds to
2108 the macros ".IP", ".LP", etc. (These are nroff macros, so the dot must be in
2109 the first column). A section boundary is also a paragraph boundary.
2110 Note that a blank line (only containing white space) is NOT a paragraph
2111 boundary.
Bram Moolenaarc79745a2019-05-20 22:12:34 +02002112
2113
Bram Moolenaare7eb9272019-06-24 00:58:07 +02002114 Also note that this does not include a '{' or '}' in the first column. When
2115 the '{' flag is in 'cpoptions' then '{' in the first column is used as a
2116 paragraph boundary |posix|.
2117 {
2118 This is no paragraph
2119 unless the '{' is set
2120 in 'cpoptions'
2121 }
2122 .IP
2123 The nroff macros IP separates a paragraph
2124 That means, it must be a '.'
2125 followed by IP
2126 .LPIt does not matter, if afterwards some
2127 more characters follow.
2128 .SHAlso section boundaries from the nroff
2129 macros terminate a paragraph. That means
2130 a character like this:
2131 .NH
2132 End of text here
Bram Moolenaarc79745a2019-05-20 22:12:34 +02002133 [DATA]
2134
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002135 new
2136 call append(0, text)
2137 1
2138 norm! 0d2}
Bram Moolenaarc79745a2019-05-20 22:12:34 +02002139
2140 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02002141 .IP
2142 The nroff macros IP separates a paragraph
2143 That means, it must be a '.'
2144 followed by IP
2145 .LPIt does not matter, if afterwards some
2146 more characters follow.
2147 .SHAlso section boundaries from the nroff
2148 macros terminate a paragraph. That means
2149 a character like this:
2150 .NH
2151 End of text here
Bram Moolenaarc79745a2019-05-20 22:12:34 +02002152
2153 [DATA]
2154 call assert_equal(expected, getline(1, '$'))
2155
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002156 norm! 0d}
Bram Moolenaarc79745a2019-05-20 22:12:34 +02002157
2158 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02002159 .LPIt does not matter, if afterwards some
2160 more characters follow.
2161 .SHAlso section boundaries from the nroff
2162 macros terminate a paragraph. That means
2163 a character like this:
2164 .NH
2165 End of text here
2166
Bram Moolenaarc79745a2019-05-20 22:12:34 +02002167 [DATA]
2168 call assert_equal(expected, getline(1, '$'))
2169
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002170 $
2171 norm! d{
Bram Moolenaarc79745a2019-05-20 22:12:34 +02002172
2173 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02002174 .LPIt does not matter, if afterwards some
2175 more characters follow.
2176 .SHAlso section boundaries from the nroff
2177 macros terminate a paragraph. That means
2178 a character like this:
Bram Moolenaarc79745a2019-05-20 22:12:34 +02002179
2180 [DATA]
2181 call assert_equal(expected, getline(1, '$'))
2182
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002183 norm! d{
Bram Moolenaarc79745a2019-05-20 22:12:34 +02002184
2185 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02002186 .LPIt does not matter, if afterwards some
2187 more characters follow.
Bram Moolenaarc79745a2019-05-20 22:12:34 +02002188
2189 [DATA]
2190 call assert_equal(expected, getline(1, '$'))
2191
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002192 " Test with { in cpooptions
2193 %d
2194 call append(0, text)
2195 set cpo+={
2196 1
2197 norm! 0d2}
Bram Moolenaarc79745a2019-05-20 22:12:34 +02002198
2199 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02002200 {
2201 This is no paragraph
2202 unless the '{' is set
2203 in 'cpoptions'
2204 }
2205 .IP
2206 The nroff macros IP separates a paragraph
2207 That means, it must be a '.'
2208 followed by IP
2209 .LPIt does not matter, if afterwards some
2210 more characters follow.
2211 .SHAlso section boundaries from the nroff
2212 macros terminate a paragraph. That means
2213 a character like this:
2214 .NH
2215 End of text here
Bram Moolenaarc79745a2019-05-20 22:12:34 +02002216
2217 [DATA]
2218 call assert_equal(expected, getline(1, '$'))
2219
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002220 $
2221 norm! d}
Bram Moolenaarc79745a2019-05-20 22:12:34 +02002222
2223 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02002224 {
2225 This is no paragraph
2226 unless the '{' is set
2227 in 'cpoptions'
2228 }
2229 .IP
2230 The nroff macros IP separates a paragraph
2231 That means, it must be a '.'
2232 followed by IP
2233 .LPIt does not matter, if afterwards some
2234 more characters follow.
2235 .SHAlso section boundaries from the nroff
2236 macros terminate a paragraph. That means
2237 a character like this:
2238 .NH
2239 End of text here
Bram Moolenaarc79745a2019-05-20 22:12:34 +02002240
2241 [DATA]
2242 call assert_equal(expected, getline(1, '$'))
2243
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002244 norm! gg}
2245 norm! d5}
Bram Moolenaarc79745a2019-05-20 22:12:34 +02002246
2247 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02002248 {
2249 This is no paragraph
2250 unless the '{' is set
2251 in 'cpoptions'
2252 }
Bram Moolenaarc79745a2019-05-20 22:12:34 +02002253
2254 [DATA]
2255 call assert_equal(expected, getline(1, '$'))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002256
Bram Moolenaar1671f442020-03-10 07:48:13 +01002257 " Jumping to a fold should open the fold
2258 %d
2259 call setline(1, ['', 'one', 'two', ''])
2260 set foldenable
2261 2,$fold
2262 call feedkeys('}', 'xt')
2263 call assert_equal(4, line('.'))
2264 call assert_equal(1, foldlevel('.'))
2265 call assert_equal(-1, foldclosed('.'))
2266 set foldenable&
2267
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002268 " clean up
2269 set cpo-={
2270 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002271endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002272
Bram Moolenaar8a9bc952020-10-02 18:48:07 +02002273" Test for section movements
2274func Test_normal_section()
2275 new
2276 let lines =<< trim [END]
2277 int foo()
2278 {
2279 if (1)
2280 {
2281 a = 1;
2282 }
2283 }
2284 [END]
2285 call setline(1, lines)
2286
2287 " jumping to a folded line using [[ should open the fold
2288 2,3fold
2289 call cursor(5, 1)
2290 call feedkeys("[[", 'xt')
2291 call assert_equal(2, line('.'))
2292 call assert_equal(-1, foldclosedend(line('.')))
2293
Yee Cheng Chin1881abf2022-12-08 09:41:24 +00002294 bwipe!
Bram Moolenaar8a9bc952020-10-02 18:48:07 +02002295endfunc
2296
Bram Moolenaard1ad99b2020-10-04 16:16:54 +02002297" Test for changing case using u, U, gu, gU and ~ (tilde) commands
Bram Moolenaar1671f442020-03-10 07:48:13 +01002298func Test_normal30_changecase()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002299 new
2300 call append(0, 'This is a simple test: äüöß')
2301 norm! 1ggVu
2302 call assert_equal('this is a simple test: äüöß', getline('.'))
2303 norm! VU
2304 call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.'))
2305 norm! guu
2306 call assert_equal('this is a simple test: äüöss', getline('.'))
2307 norm! gUgU
2308 call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.'))
2309 norm! gugu
2310 call assert_equal('this is a simple test: äüöss', getline('.'))
2311 norm! gUU
2312 call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.'))
2313 norm! 010~
2314 call assert_equal('this is a SIMPLE TEST: ÄÜÖSS', getline('.'))
2315 norm! V~
2316 call assert_equal('THIS IS A simple test: äüöss', getline('.'))
Bram Moolenaard1ad99b2020-10-04 16:16:54 +02002317 call assert_beeps('norm! c~')
2318 %d
2319 call assert_beeps('norm! ~')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002320
Bram Moolenaar1671f442020-03-10 07:48:13 +01002321 " Test for changing case across lines using 'whichwrap'
2322 call setline(1, ['aaaaaa', 'aaaaaa'])
2323 normal! gg10~
2324 call assert_equal(['AAAAAA', 'aaaaaa'], getline(1, 2))
2325 set whichwrap+=~
2326 normal! gg10~
2327 call assert_equal(['aaaaaa', 'AAAAaa'], getline(1, 2))
2328 set whichwrap&
2329
Bram Moolenaar3e72dca2021-05-29 16:30:12 +02002330 " try changing the case with a double byte encoding (DBCS)
2331 %bw!
2332 let enc = &enc
2333 set encoding=cp932
2334 call setline(1, "\u8470")
2335 normal ~
2336 normal gU$gu$gUgUg~g~gugu
2337 call assert_equal("\u8470", getline(1))
2338 let &encoding = enc
2339
Bram Moolenaar1671f442020-03-10 07:48:13 +01002340 " clean up
2341 bw!
2342endfunc
2343
2344" Turkish ASCII turns to multi-byte. On some systems Turkish locale
2345" is available but toupper()/tolower() don't do the right thing.
2346func Test_normal_changecase_turkish()
2347 new
Bram Moolenaarf1c118b2018-09-03 22:08:10 +02002348 try
2349 lang tr_TR.UTF-8
2350 set casemap=
2351 let iupper = toupper('i')
2352 if iupper == "\u0130"
Bram Moolenaar9f4de1f2017-04-08 19:39:43 +02002353 call setline(1, 'iI')
2354 1normal gUU
2355 call assert_equal("\u0130I", getline(1))
2356 call assert_equal("\u0130I", toupper("iI"))
Bram Moolenaar3317d5e2017-04-08 19:12:06 +02002357
Bram Moolenaar9f4de1f2017-04-08 19:39:43 +02002358 call setline(1, 'iI')
2359 1normal guu
2360 call assert_equal("i\u0131", getline(1))
2361 call assert_equal("i\u0131", tolower("iI"))
Bram Moolenaarf1c118b2018-09-03 22:08:10 +02002362 elseif iupper == "I"
Bram Moolenaar1cc48202017-04-09 13:41:59 +02002363 call setline(1, 'iI')
2364 1normal gUU
2365 call assert_equal("II", getline(1))
2366 call assert_equal("II", toupper("iI"))
2367
2368 call setline(1, 'iI')
2369 1normal guu
2370 call assert_equal("ii", getline(1))
2371 call assert_equal("ii", tolower("iI"))
Bram Moolenaarf1c118b2018-09-03 22:08:10 +02002372 else
2373 call assert_true(false, "expected toupper('i') to be either 'I' or '\u0130'")
2374 endif
2375 set casemap&
2376 call setline(1, 'iI')
2377 1normal gUU
2378 call assert_equal("II", getline(1))
2379 call assert_equal("II", toupper("iI"))
Bram Moolenaar1cc48202017-04-09 13:41:59 +02002380
Bram Moolenaarf1c118b2018-09-03 22:08:10 +02002381 call setline(1, 'iI')
2382 1normal guu
2383 call assert_equal("ii", getline(1))
2384 call assert_equal("ii", tolower("iI"))
2385
2386 lang en_US.UTF-8
2387 catch /E197:/
2388 " can't use Turkish locale
2389 throw 'Skipped: Turkish locale not available'
2390 endtry
Yee Cheng Chin1881abf2022-12-08 09:41:24 +00002391
2392 bwipe!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002393endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002394
Bram Moolenaar1671f442020-03-10 07:48:13 +01002395" Test for r (replace) command
2396func Test_normal31_r_cmd()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002397 new
2398 call append(0, 'This is a simple test: abcd')
2399 exe "norm! 1gg$r\<cr>"
2400 call assert_equal(['This is a simple test: abc', '', ''], getline(1,'$'))
2401 exe "norm! 1gg2wlr\<cr>"
2402 call assert_equal(['This is a', 'simple test: abc', '', ''], getline(1,'$'))
2403 exe "norm! 2gg0W5r\<cr>"
2404 call assert_equal(['This is a', 'simple ', ' abc', '', ''], getline('1', '$'))
2405 set autoindent
2406 call setline(2, ['simple test: abc', ''])
2407 exe "norm! 2gg0W5r\<cr>"
2408 call assert_equal(['This is a', 'simple ', 'abc', '', '', ''], getline('1', '$'))
2409 exe "norm! 1ggVr\<cr>"
2410 call assert_equal('^M^M^M^M^M^M^M^M^M', strtrans(getline(1)))
2411 call setline(1, 'This is a')
2412 exe "norm! 1gg05rf"
2413 call assert_equal('fffffis a', getline(1))
2414
Bram Moolenaar1671f442020-03-10 07:48:13 +01002415 " When replacing characters, copy characters from above and below lines
2416 " using CTRL-Y and CTRL-E.
2417 " Different code paths are used for utf-8 and latin1 encodings
2418 set showmatch
2419 for enc in ['latin1', 'utf-8']
2420 enew!
2421 let &encoding = enc
2422 call setline(1, [' {a}', 'xxxxxxxxxx', ' [b]'])
2423 exe "norm! 2gg5r\<C-Y>l5r\<C-E>"
2424 call assert_equal(' {a}x [b]x', getline(2))
2425 endfor
2426 set showmatch&
2427
2428 " r command should fail in operator pending mode
2429 call assert_beeps('normal! cr')
2430
Bram Moolenaar004a6782020-04-11 17:09:31 +02002431 " replace a tab character in visual mode
2432 %d
2433 call setline(1, ["a\tb", "c\td", "e\tf"])
2434 normal gglvjjrx
2435 call assert_equal(['axx', 'xxx', 'xxf'], getline(1, '$'))
2436
Bram Moolenaard7e5e942020-10-07 16:54:52 +02002437 " replace with a multibyte character (with multiple composing characters)
2438 %d
2439 new
2440 call setline(1, 'aaa')
2441 exe "normal $ra\u0328\u0301"
2442 call assert_equal("aaa\u0328\u0301", getline(1))
2443
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002444 " clean up
2445 set noautoindent
2446 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002447endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002448
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002449" Test for g*, g#
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002450func Test_normal32_g_cmd1()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002451 new
2452 call append(0, ['abc.x_foo', 'x_foobar.abc'])
2453 1
2454 norm! $g*
2455 call assert_equal('x_foo', @/)
2456 call assert_equal('x_foobar.abc', getline('.'))
2457 norm! $g#
2458 call assert_equal('abc', @/)
2459 call assert_equal('abc.x_foo', getline('.'))
2460
2461 " clean up
2462 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002463endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002464
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002465" Test for g`, g;, g,, g&, gv, gk, gj, gJ, g0, g^, g_, gm, g$, gM, g CTRL-G,
2466" gi and gI commands
Bram Moolenaar1671f442020-03-10 07:48:13 +01002467func Test_normal33_g_cmd2()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002468 call Setup_NewWindow()
2469 " Test for g`
2470 clearjumps
2471 norm! ma10j
2472 let a=execute(':jumps')
2473 " empty jumplist
2474 call assert_equal('>', a[-1:])
2475 norm! g`a
2476 call assert_equal('>', a[-1:])
2477 call assert_equal(1, line('.'))
2478 call assert_equal('1', getline('.'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002479 call cursor(10, 1)
2480 norm! g'a
2481 call assert_equal('>', a[-1:])
2482 call assert_equal(1, line('.'))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002483
2484 " Test for g; and g,
2485 norm! g;
2486 " there is only one change in the changelist
2487 " currently, when we setup the window
2488 call assert_equal(2, line('.'))
Bram Moolenaare2e40752020-09-04 21:18:46 +02002489 call assert_fails(':norm! g;', 'E662:')
2490 call assert_fails(':norm! g,', 'E663:')
Bram Moolenaar7a1d3282022-06-16 13:04:45 +01002491 let &ul = &ul
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002492 call append('$', ['a', 'b', 'c', 'd'])
Bram Moolenaar7a1d3282022-06-16 13:04:45 +01002493 let &ul = &ul
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002494 call append('$', ['Z', 'Y', 'X', 'W'])
2495 let a = execute(':changes')
2496 call assert_match('2\s\+0\s\+2', a)
2497 call assert_match('101\s\+0\s\+a', a)
2498 call assert_match('105\s\+0\s\+Z', a)
2499 norm! 3g;
2500 call assert_equal(2, line('.'))
2501 norm! 2g,
2502 call assert_equal(105, line('.'))
2503
2504 " Test for g& - global substitute
2505 %d
2506 call setline(1, range(1,10))
2507 call append('$', ['a', 'b', 'c', 'd'])
2508 $s/\w/&&/g
2509 exe "norm! /[1-8]\<cr>"
2510 norm! g&
2511 call assert_equal(['11', '22', '33', '44', '55', '66', '77', '88', '9', '110', 'a', 'b', 'c', 'dd'], getline(1, '$'))
2512
Bram Moolenaar1671f442020-03-10 07:48:13 +01002513 " Jumping to a fold using gg should open the fold
2514 set foldenable
2515 set foldopen+=jump
2516 5,8fold
2517 call feedkeys('6gg', 'xt')
2518 call assert_equal(1, foldlevel('.'))
2519 call assert_equal(-1, foldclosed('.'))
2520 set foldopen-=jump
2521 set foldenable&
2522
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002523 " Test for gv
2524 %d
2525 call append('$', repeat(['abcdefgh'], 8))
2526 exe "norm! 2gg02l\<c-v>2j2ly"
2527 call assert_equal(['cde', 'cde', 'cde'], getreg(0, 1, 1))
2528 " in visual mode, gv swaps current and last selected region
2529 exe "norm! G0\<c-v>4k4lgvd"
2530 call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh'], getline(1,'$'))
2531 exe "norm! G0\<c-v>4k4ly"
2532 exe "norm! gvood"
2533 call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'fgh', 'fgh', 'fgh', 'fgh', 'fgh'], getline(1,'$'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002534 " gv cannot be used in operator pending mode
2535 call assert_beeps('normal! cgv')
2536 " gv should beep without a previously selected visual area
2537 new
2538 call assert_beeps('normal! gv')
2539 close
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002540
2541 " Test for gk/gj
2542 %d
2543 15vsp
2544 set wrap listchars= sbr=
Bram Moolenaar74ede802021-05-29 19:18:01 +02002545 let lineA = 'abcdefghijklmnopqrstuvwxyz'
2546 let lineB = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
2547 let lineC = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002548 $put =lineA
2549 $put =lineB
2550
2551 norm! 3gg0dgk
2552 call assert_equal(['', 'abcdefghijklmno', '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'], getline(1, '$'))
2553 set nu
2554 norm! 3gg0gjdgj
2555 call assert_equal(['', 'abcdefghijklmno', '0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
2556
2557 " Test for gJ
2558 norm! 2gggJ
2559 call assert_equal(['', 'abcdefghijklmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
2560 call assert_equal(16, col('.'))
2561 " shouldn't do anything
2562 norm! 10gJ
2563 call assert_equal(1, col('.'))
2564
2565 " Test for g0 g^ gm g$
2566 exe "norm! 2gg0gji "
2567 call assert_equal(['', 'abcdefghijk lmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
2568 norm! g0yl
2569 call assert_equal(12, col('.'))
2570 call assert_equal(' ', getreg(0))
2571 norm! g$yl
2572 call assert_equal(22, col('.'))
2573 call assert_equal('3', getreg(0))
2574 norm! gmyl
2575 call assert_equal(17, col('.'))
2576 call assert_equal('n', getreg(0))
2577 norm! g^yl
2578 call assert_equal(15, col('.'))
2579 call assert_equal('l', getreg(0))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002580 call assert_beeps('normal 5g$')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002581
Bram Moolenaar74ede802021-05-29 19:18:01 +02002582 " Test for g$ with double-width character half displayed
2583 vsplit
2584 9wincmd |
2585 setlocal nowrap nonumber
2586 call setline(2, 'asdfasdf')
2587 2
2588 normal 0g$
2589 call assert_equal(8, col('.'))
2590 10wincmd |
2591 normal 0g$
2592 call assert_equal(9, col('.'))
2593
2594 setlocal signcolumn=yes
2595 11wincmd |
2596 normal 0g$
2597 call assert_equal(8, col('.'))
2598 12wincmd |
2599 normal 0g$
2600 call assert_equal(9, col('.'))
2601
2602 close
2603
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002604 " Test for g_
2605 call assert_beeps('normal! 100g_')
2606 call setline(2, [' foo ', ' foobar '])
2607 normal! 2ggg_
2608 call assert_equal(5, col('.'))
2609 normal! 2g_
2610 call assert_equal(8, col('.'))
2611
2612 norm! 2ggdG
Bram Moolenaar8b530c12019-10-28 02:13:05 +01002613 $put =lineC
2614
2615 " Test for gM
2616 norm! gMyl
2617 call assert_equal(73, col('.'))
2618 call assert_equal('0', getreg(0))
2619 " Test for 20gM
2620 norm! 20gMyl
2621 call assert_equal(29, col('.'))
2622 call assert_equal('S', getreg(0))
2623 " Test for 60gM
2624 norm! 60gMyl
2625 call assert_equal(87, col('.'))
2626 call assert_equal('E', getreg(0))
2627
Bram Moolenaar71c41252021-12-26 15:00:07 +00002628 " Test for gM with Tab characters
2629 call setline('.', "\ta\tb\tc\td\te\tf")
2630 norm! gMyl
2631 call assert_equal(6, col('.'))
2632 call assert_equal("c", getreg(0))
2633
Bram Moolenaar8b530c12019-10-28 02:13:05 +01002634 " Test for g Ctrl-G
Bram Moolenaar71c41252021-12-26 15:00:07 +00002635 call setline('.', lineC)
2636 norm! 60gMyl
Bram Moolenaar8b530c12019-10-28 02:13:05 +01002637 set ff=unix
2638 let a=execute(":norm! g\<c-g>")
2639 call assert_match('Col 87 of 144; Line 2 of 2; Word 1 of 1; Byte 88 of 146', a)
2640
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002641 " Test for gI
2642 norm! gIfoo
Bram Moolenaar8b530c12019-10-28 02:13:05 +01002643 call assert_equal(['', 'foo0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'], getline(1,'$'))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002644
2645 " Test for gi
2646 wincmd c
2647 %d
2648 set tw=0
2649 call setline(1, ['foobar', 'new line'])
2650 norm! A next word
2651 $put ='third line'
2652 norm! gi another word
2653 call assert_equal(['foobar next word another word', 'new line', 'third line'], getline(1,'$'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002654 call setline(1, 'foobar')
2655 normal! Ggifirst line
2656 call assert_equal('foobarfirst line', getline(1))
2657 " Test gi in 'virtualedit' mode with cursor after the end of the line
2658 set virtualedit=all
2659 call setline(1, 'foo')
2660 exe "normal! Abar\<Right>\<Right>\<Right>\<Right>"
2661 call setline(1, 'foo')
2662 normal! Ggifirst line
2663 call assert_equal('foo first line', getline(1))
2664 set virtualedit&
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002665
Dominique Pelle923dce22021-11-21 11:36:04 +00002666 " Test for aborting a g command using CTRL-\ CTRL-G
Bram Moolenaar1671f442020-03-10 07:48:13 +01002667 exe "normal! g\<C-\>\<C-G>"
2668 call assert_equal('foo first line', getline('.'))
2669
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002670 " clean up
2671 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002672endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002673
Bram Moolenaarce416b42022-04-03 12:59:34 +01002674func Test_normal_ex_substitute()
2675 " This was hanging on the substitute prompt.
2676 new
2677 call setline(1, 'a')
2678 exe "normal! gggQs/a/b/c\<CR>"
2679 call assert_equal('a', getline(1))
2680 bwipe!
2681endfunc
2682
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002683" Test for g CTRL-G
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002684func Test_g_ctrl_g()
Bram Moolenaar05295832018-08-24 22:07:58 +02002685 new
2686
2687 let a = execute(":norm! g\<c-g>")
2688 call assert_equal("\n--No lines in buffer--", a)
2689
Bram Moolenaar1671f442020-03-10 07:48:13 +01002690 " Test for CTRL-G (same as :file)
2691 let a = execute(":norm! \<c-g>")
2692 call assert_equal("\n\n\"[No Name]\" --No lines in buffer--", a)
2693
Bram Moolenaar05295832018-08-24 22:07:58 +02002694 call setline(1, ['first line', 'second line'])
2695
2696 " Test g CTRL-g with dos, mac and unix file type.
2697 norm! gojll
2698 set ff=dos
2699 let a = execute(":norm! g\<c-g>")
2700 call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 15 of 25", a)
2701
2702 set ff=mac
2703 let a = execute(":norm! g\<c-g>")
2704 call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 14 of 23", a)
2705
2706 set ff=unix
2707 let a = execute(":norm! g\<c-g>")
2708 call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 14 of 23", a)
2709
2710 " Test g CTRL-g in visual mode (v)
2711 let a = execute(":norm! gojllvlg\<c-g>")
2712 call assert_equal("\nSelected 1 of 2 Lines; 1 of 4 Words; 2 of 23 Bytes", a)
2713
2714 " Test g CTRL-g in visual mode (CTRL-V) with end col > start col
2715 let a = execute(":norm! \<Esc>gojll\<C-V>kllg\<c-g>")
2716 call assert_equal("\nSelected 3 Cols; 2 of 2 Lines; 2 of 4 Words; 6 of 23 Bytes", a)
2717
2718 " Test g_CTRL-g in visual mode (CTRL-V) with end col < start col
2719 let a = execute(":norm! \<Esc>goll\<C-V>jhhg\<c-g>")
2720 call assert_equal("\nSelected 3 Cols; 2 of 2 Lines; 2 of 4 Words; 6 of 23 Bytes", a)
2721
2722 " Test g CTRL-g in visual mode (CTRL-V) with end_vcol being MAXCOL
2723 let a = execute(":norm! \<Esc>gojll\<C-V>k$g\<c-g>")
2724 call assert_equal("\nSelected 2 of 2 Lines; 4 of 4 Words; 17 of 23 Bytes", a)
2725
2726 " There should be one byte less with noeol
2727 set bin noeol
2728 let a = execute(":norm! \<Esc>gog\<c-g>")
2729 call assert_equal("\nCol 1 of 10; Line 1 of 2; Word 1 of 4; Char 1 of 23; Byte 1 of 22", a)
2730 set bin & eol&
2731
Bram Moolenaar30276f22019-01-24 17:59:39 +01002732 call setline(1, ['Français', '日本語'])
Bram Moolenaar05295832018-08-24 22:07:58 +02002733
Bram Moolenaar30276f22019-01-24 17:59:39 +01002734 let a = execute(":norm! \<Esc>gojlg\<c-g>")
2735 call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20", a)
Bram Moolenaar05295832018-08-24 22:07:58 +02002736
Bram Moolenaar30276f22019-01-24 17:59:39 +01002737 let a = execute(":norm! \<Esc>gojvlg\<c-g>")
2738 call assert_equal("\nSelected 1 of 2 Lines; 1 of 2 Words; 2 of 13 Chars; 6 of 20 Bytes", a)
Bram Moolenaar05295832018-08-24 22:07:58 +02002739
Bram Moolenaar30276f22019-01-24 17:59:39 +01002740 let a = execute(":norm! \<Esc>goll\<c-v>jlg\<c-g>")
2741 call assert_equal("\nSelected 4 Cols; 2 of 2 Lines; 2 of 2 Words; 6 of 13 Chars; 11 of 20 Bytes", a)
Bram Moolenaar05295832018-08-24 22:07:58 +02002742
Bram Moolenaar30276f22019-01-24 17:59:39 +01002743 set fenc=utf8 bomb
2744 let a = execute(":norm! \<Esc>gojlg\<c-g>")
2745 call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20(+3 for BOM)", a)
Bram Moolenaar05295832018-08-24 22:07:58 +02002746
Bram Moolenaar30276f22019-01-24 17:59:39 +01002747 set fenc=utf16 bomb
2748 let a = execute(":norm! g\<c-g>")
2749 call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20(+2 for BOM)", a)
Bram Moolenaar05295832018-08-24 22:07:58 +02002750
Bram Moolenaar30276f22019-01-24 17:59:39 +01002751 set fenc=utf32 bomb
2752 let a = execute(":norm! g\<c-g>")
2753 call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20(+4 for BOM)", a)
Bram Moolenaar05295832018-08-24 22:07:58 +02002754
Bram Moolenaar30276f22019-01-24 17:59:39 +01002755 set fenc& bomb&
Bram Moolenaar05295832018-08-24 22:07:58 +02002756
2757 set ff&
2758 bwipe!
2759endfunc
2760
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002761" Test for g8
Bram Moolenaar1671f442020-03-10 07:48:13 +01002762func Test_normal34_g_cmd3()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002763 new
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02002764 let a=execute(':norm! 1G0g8')
2765 call assert_equal("\nNUL", a)
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002766
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02002767 call setline(1, 'abcdefghijklmnopqrstuvwxyzäüö')
2768 let a=execute(':norm! 1G$g8')
2769 call assert_equal("\nc3 b6 ", a)
2770
2771 call setline(1, "a\u0302")
2772 let a=execute(':norm! 1G0g8')
2773 call assert_equal("\n61 + cc 82 ", a)
2774
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002775 " clean up
2776 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002777endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002778
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002779" Test 8g8 which finds invalid utf8 at or after the cursor.
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02002780func Test_normal_8g8()
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02002781 new
2782
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02002783 " With invalid byte.
2784 call setline(1, "___\xff___")
2785 norm! 1G08g8g
2786 call assert_equal([0, 1, 4, 0, 1], getcurpos())
2787
2788 " With invalid byte before the cursor.
2789 call setline(1, "___\xff___")
2790 norm! 1G$h8g8g
2791 call assert_equal([0, 1, 6, 0, 9], getcurpos())
2792
2793 " With truncated sequence.
2794 call setline(1, "___\xE2\x82___")
2795 norm! 1G08g8g
2796 call assert_equal([0, 1, 4, 0, 1], getcurpos())
2797
2798 " With overlong sequence.
2799 call setline(1, "___\xF0\x82\x82\xAC___")
2800 norm! 1G08g8g
2801 call assert_equal([0, 1, 4, 0, 1], getcurpos())
2802
2803 " With valid utf8.
2804 call setline(1, "café")
2805 norm! 1G08g8
2806 call assert_equal([0, 1, 1, 0, 1], getcurpos())
2807
2808 bw!
2809endfunc
2810
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002811" Test for g<
Bram Moolenaar1671f442020-03-10 07:48:13 +01002812func Test_normal35_g_cmd4()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002813 " Cannot capture its output,
2814 " probably a bug, therefore, test disabled:
Bram Moolenaar31845092016-09-05 22:58:31 +02002815 throw "Skipped: output of g< can't be tested currently"
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002816 echo "a\nb\nc\nd"
2817 let b=execute(':norm! g<')
2818 call assert_true(!empty(b), 'failed `execute(g<)`')
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002819endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002820
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002821" Test for gp gP go
Bram Moolenaar1671f442020-03-10 07:48:13 +01002822func Test_normal36_g_cmd5()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002823 new
2824 call append(0, 'abcdefghijklmnopqrstuvwxyz')
Bram Moolenaar0913a102016-09-03 19:11:59 +02002825 set ff=unix
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002826 " Test for gp gP
2827 call append(1, range(1,10))
2828 1
2829 norm! 1yy
2830 3
2831 norm! gp
2832 call assert_equal([0, 5, 1, 0, 1], getcurpos())
2833 $
2834 norm! gP
2835 call assert_equal([0, 14, 1, 0, 1], getcurpos())
2836
2837 " Test for go
2838 norm! 26go
2839 call assert_equal([0, 1, 26, 0, 26], getcurpos())
2840 norm! 27go
2841 call assert_equal([0, 1, 26, 0, 26], getcurpos())
2842 norm! 28go
2843 call assert_equal([0, 2, 1, 0, 1], getcurpos())
2844 set ff=dos
2845 norm! 29go
2846 call assert_equal([0, 2, 1, 0, 1], getcurpos())
2847 set ff=unix
2848 norm! gg0
2849 norm! 101go
2850 call assert_equal([0, 13, 26, 0, 26], getcurpos())
2851 norm! 103go
2852 call assert_equal([0, 14, 1, 0, 1], getcurpos())
2853 " count > buffer content
2854 norm! 120go
naohiro ono56200ee2022-01-01 14:59:44 +00002855 call assert_equal([0, 14, 1, 0, v:maxcol], getcurpos())
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002856 " clean up
2857 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002858endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002859
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002860" Test for gt and gT
Bram Moolenaar1671f442020-03-10 07:48:13 +01002861func Test_normal37_g_cmd6()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002862 tabnew 1.txt
2863 tabnew 2.txt
2864 tabnew 3.txt
2865 norm! 1gt
2866 call assert_equal(1, tabpagenr())
2867 norm! 3gt
2868 call assert_equal(3, tabpagenr())
2869 norm! 1gT
2870 " count gT goes not to the absolute tabpagenumber
2871 " but, but goes to the count previous tabpagenumber
2872 call assert_equal(2, tabpagenr())
2873 " wrap around
2874 norm! 3gT
2875 call assert_equal(3, tabpagenr())
2876 " gt does not wrap around
2877 norm! 5gt
2878 call assert_equal(3, tabpagenr())
2879
2880 for i in range(3)
2881 tabclose
2882 endfor
2883 " clean up
Bram Moolenaarbc2b71d2020-02-17 21:33:30 +01002884 call assert_fails(':tabclose', 'E784:')
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002885endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002886
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002887" Test for <Home> and <C-Home> key
Bram Moolenaar1671f442020-03-10 07:48:13 +01002888func Test_normal38_nvhome()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002889 new
2890 call setline(1, range(10))
2891 $
2892 setl et sw=2
2893 norm! V10>$
2894 " count is ignored
2895 exe "norm! 10\<home>"
2896 call assert_equal(1, col('.'))
2897 exe "norm! \<home>"
2898 call assert_equal([0, 10, 1, 0, 1], getcurpos())
2899 exe "norm! 5\<c-home>"
2900 call assert_equal([0, 5, 1, 0, 1], getcurpos())
2901 exe "norm! \<c-home>"
2902 call assert_equal([0, 1, 1, 0, 1], getcurpos())
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002903 exe "norm! G\<c-kHome>"
2904 call assert_equal([0, 1, 1, 0, 1], getcurpos())
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002905
2906 " clean up
2907 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002908endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002909
Bram Moolenaar1671f442020-03-10 07:48:13 +01002910" Test for <End> and <C-End> keys
2911func Test_normal_nvend()
2912 new
2913 call setline(1, map(range(1, 10), '"line" .. v:val'))
2914 exe "normal! \<End>"
2915 call assert_equal(5, col('.'))
2916 exe "normal! 4\<End>"
2917 call assert_equal([4, 5], [line('.'), col('.')])
2918 exe "normal! \<C-End>"
2919 call assert_equal([10, 6], [line('.'), col('.')])
Yee Cheng Chin1881abf2022-12-08 09:41:24 +00002920
2921 bwipe!
Bram Moolenaar1671f442020-03-10 07:48:13 +01002922endfunc
2923
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002924" Test for cw cW ce
Bram Moolenaar1671f442020-03-10 07:48:13 +01002925func Test_normal39_cw()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002926 " Test for cw and cW on whitespace
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002927 new
2928 set tw=0
2929 call append(0, 'here are some words')
2930 norm! 1gg0elcwZZZ
2931 call assert_equal('hereZZZare some words', getline('.'))
2932 norm! 1gg0elcWYYY
2933 call assert_equal('hereZZZareYYYsome words', getline('.'))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002934 norm! 2gg0cwfoo
2935 call assert_equal('foo', getline('.'))
2936
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002937 call setline(1, 'one; two')
2938 call cursor(1, 1)
2939 call feedkeys('cwvim', 'xt')
2940 call assert_equal('vim; two', getline(1))
2941 call feedkeys('0cWone', 'xt')
2942 call assert_equal('one two', getline(1))
2943 "When cursor is at the end of a word 'ce' will change until the end of the
2944 "next word, but 'cw' will change only one character
2945 call setline(1, 'one two')
2946 call feedkeys('0ecwce', 'xt')
2947 call assert_equal('once two', getline(1))
2948 call setline(1, 'one two')
2949 call feedkeys('0ecely', 'xt')
2950 call assert_equal('only', getline(1))
2951
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002952 " clean up
2953 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002954endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002955
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002956" Test for CTRL-\ commands
Bram Moolenaar1671f442020-03-10 07:48:13 +01002957func Test_normal40_ctrl_bsl()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002958 new
2959 call append(0, 'here are some words')
2960 exe "norm! 1gg0a\<C-\>\<C-N>"
2961 call assert_equal('n', mode())
2962 call assert_equal(1, col('.'))
2963 call assert_equal('', visualmode())
2964 exe "norm! 1gg0viw\<C-\>\<C-N>"
2965 call assert_equal('n', mode())
2966 call assert_equal(4, col('.'))
2967 exe "norm! 1gg0a\<C-\>\<C-G>"
2968 call assert_equal('n', mode())
2969 call assert_equal(1, col('.'))
2970 "imap <buffer> , <c-\><c-n>
2971 set im
2972 exe ":norm! \<c-\>\<c-n>dw"
2973 set noim
2974 call assert_equal('are some words', getline(1))
2975 call assert_false(&insertmode)
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02002976 call assert_beeps("normal! \<C-\>\<C-A>")
Bram Moolenaar1671f442020-03-10 07:48:13 +01002977
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002978 " clean up
2979 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002980endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002981
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002982" Test for <c-r>=, <c-r><c-r>= and <c-r><c-o>= in insert mode
Bram Moolenaar1671f442020-03-10 07:48:13 +01002983func Test_normal41_insert_reg()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002984 new
2985 set sts=2 sw=2 ts=8 tw=0
2986 call append(0, ["aaa\tbbb\tccc", '', '', ''])
2987 let a=getline(1)
2988 norm! 2gg0
2989 exe "norm! a\<c-r>=a\<cr>"
2990 norm! 3gg0
2991 exe "norm! a\<c-r>\<c-r>=a\<cr>"
2992 norm! 4gg0
2993 exe "norm! a\<c-r>\<c-o>=a\<cr>"
2994 call assert_equal(['aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', ''], getline(1, '$'))
2995
2996 " clean up
2997 set sts=0 sw=8 ts=8
Bram Moolenaar31845092016-09-05 22:58:31 +02002998 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002999endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02003000
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01003001" Test for Ctrl-D and Ctrl-U
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01003002func Test_normal42_halfpage()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02003003 call Setup_NewWindow()
3004 call assert_equal(5, &scroll)
3005 exe "norm! \<c-d>"
3006 call assert_equal('6', getline('.'))
3007 exe "norm! 2\<c-d>"
3008 call assert_equal('8', getline('.'))
3009 call assert_equal(2, &scroll)
3010 set scroll=5
3011 exe "norm! \<c-u>"
3012 call assert_equal('3', getline('.'))
3013 1
3014 set scrolloff=5
3015 exe "norm! \<c-d>"
3016 call assert_equal('10', getline('.'))
3017 exe "norm! \<c-u>"
3018 call assert_equal('5', getline('.'))
3019 1
3020 set scrolloff=99
3021 exe "norm! \<c-d>"
3022 call assert_equal('10', getline('.'))
3023 set scrolloff=0
3024 100
3025 exe "norm! $\<c-u>"
3026 call assert_equal('95', getline('.'))
3027 call assert_equal([0, 95, 1, 0, 1], getcurpos())
3028 100
3029 set nostartofline
3030 exe "norm! $\<c-u>"
3031 call assert_equal('95', getline('.'))
naohiro ono56200ee2022-01-01 14:59:44 +00003032 call assert_equal([0, 95, 2, 0, v:maxcol], getcurpos())
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02003033 " cleanup
3034 set startofline
3035 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02003036endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02003037
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01003038func Test_normal45_drop()
Bram Moolenaar29495952018-02-12 22:49:00 +01003039 if !has('dnd')
Bram Moolenaarb48e96f2018-02-13 12:26:14 +01003040 " The ~ register does not exist
3041 call assert_beeps('norm! "~')
Bram Moolenaar29495952018-02-12 22:49:00 +01003042 return
3043 endif
3044
3045 " basic test for drag-n-drop
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02003046 " unfortunately, without a gui, we can't really test much here,
3047 " so simply test that ~p fails (which uses the drop register)
3048 new
Bram Moolenaare2e40752020-09-04 21:18:46 +02003049 call assert_fails(':norm! "~p', 'E353:')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02003050 call assert_equal([], getreg('~', 1, 1))
3051 " the ~ register is read only
Bram Moolenaare2e40752020-09-04 21:18:46 +02003052 call assert_fails(':let @~="1"', 'E354:')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02003053 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02003054endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02003055
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01003056func Test_normal46_ignore()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02003057 new
3058 " How to test this?
3059 " let's just for now test, that the buffer
3060 " does not change
3061 call feedkeys("\<c-s>", 't')
3062 call assert_equal([''], getline(1,'$'))
3063
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02003064 " no valid commands
3065 exe "norm! \<char-0x100>"
3066 call assert_equal([''], getline(1,'$'))
3067
3068 exe "norm! ä"
3069 call assert_equal([''], getline(1,'$'))
3070
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02003071 " clean up
3072 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02003073endfunc
Bram Moolenaarc4a908e2016-09-08 23:35:30 +02003074
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01003075func Test_normal47_visual_buf_wipe()
Bram Moolenaarc4a908e2016-09-08 23:35:30 +02003076 " This was causing a crash or ml_get error.
3077 enew!
3078 call setline(1,'xxx')
3079 normal $
3080 new
3081 call setline(1, range(1,2))
3082 2
3083 exe "norm \<C-V>$"
3084 bw!
3085 norm yp
3086 set nomodified
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02003087endfunc
3088
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01003089func Test_normal48_wincmd()
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02003090 new
3091 exe "norm! \<c-w>c"
3092 call assert_equal(1, winnr('$'))
Bram Moolenaare2e40752020-09-04 21:18:46 +02003093 call assert_fails(":norm! \<c-w>c", 'E444:')
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02003094endfunc
3095
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01003096func Test_normal49_counts()
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02003097 new
3098 call setline(1, 'one two three four five six seven eight nine ten')
3099 1
3100 norm! 3d2w
3101 call assert_equal('seven eight nine ten', getline(1))
3102 bw!
3103endfunc
3104
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01003105func Test_normal50_commandline()
Bram Moolenaar004a6782020-04-11 17:09:31 +02003106 CheckFeature timers
3107 CheckFeature cmdline_hist
Bram Moolenaarc255b782022-11-26 19:16:48 +00003108
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02003109 func! DoTimerWork(id)
3110 call assert_equal('[Command Line]', bufname(''))
Bram Moolenaarc255b782022-11-26 19:16:48 +00003111
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02003112 " should fail, with E11, but does fail with E23?
3113 "call feedkeys("\<c-^>", 'tm')
3114
Bram Moolenaarc255b782022-11-26 19:16:48 +00003115 " should fail with E11 - "Invalid in command-line window"
Bram Moolenaare2e40752020-09-04 21:18:46 +02003116 call assert_fails(":wincmd p", 'E11:')
Bram Moolenaarc255b782022-11-26 19:16:48 +00003117
3118 " Return from commandline window.
3119 call feedkeys("\<CR>", 't')
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02003120 endfunc
3121
3122 let oldlang=v:lang
3123 lang C
3124 set updatetime=20
3125 call timer_start(100, 'DoTimerWork')
3126 try
3127 " throws E23, for whatever reason...
3128 call feedkeys('q:', 'x!')
3129 catch /E23/
3130 " no-op
3131 endtry
Bram Moolenaarc255b782022-11-26 19:16:48 +00003132
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02003133 " clean up
Bram Moolenaarc255b782022-11-26 19:16:48 +00003134 delfunc DoTimerWork
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02003135 set updatetime=4000
3136 exe "lang" oldlang
3137 bw!
3138endfunc
3139
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01003140func Test_normal51_FileChangedRO()
Bram Moolenaar004a6782020-04-11 17:09:31 +02003141 CheckFeature autocmd
Bram Moolenaare5f2a072017-02-01 22:31:49 +01003142 " Don't sleep after the warning message.
3143 call test_settime(1)
Bram Moolenaarb152b6a2022-09-29 21:37:33 +01003144 call writefile(['foo'], 'Xreadonly.log', 'D')
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02003145 new Xreadonly.log
3146 setl ro
3147 au FileChangedRO <buffer> :call feedkeys("\<c-^>", 'tix')
Bram Moolenaare2e40752020-09-04 21:18:46 +02003148 call assert_fails(":norm! Af", 'E788:')
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02003149 call assert_equal(['foo'], getline(1,'$'))
3150 call assert_equal('Xreadonly.log', bufname(''))
3151
3152 " cleanup
Bram Moolenaare5f2a072017-02-01 22:31:49 +01003153 call test_settime(0)
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02003154 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02003155endfunc
3156
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01003157func Test_normal52_rl()
Bram Moolenaar004a6782020-04-11 17:09:31 +02003158 CheckFeature rightleft
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02003159 new
3160 call setline(1, 'abcde fghij klmnopq')
3161 norm! 1gg$
3162 set rl
3163 call assert_equal(19, col('.'))
3164 call feedkeys('l', 'tx')
3165 call assert_equal(18, col('.'))
3166 call feedkeys('h', 'tx')
3167 call assert_equal(19, col('.'))
3168 call feedkeys("\<right>", 'tx')
3169 call assert_equal(18, col('.'))
Bram Moolenaar1671f442020-03-10 07:48:13 +01003170 call feedkeys("\<left>", 'tx')
3171 call assert_equal(19, col('.'))
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02003172 call feedkeys("\<s-right>", 'tx')
3173 call assert_equal(13, col('.'))
3174 call feedkeys("\<c-right>", 'tx')
3175 call assert_equal(7, col('.'))
3176 call feedkeys("\<c-left>", 'tx')
3177 call assert_equal(13, col('.'))
3178 call feedkeys("\<s-left>", 'tx')
3179 call assert_equal(19, col('.'))
3180 call feedkeys("<<", 'tx')
3181 call assert_equal(' abcde fghij klmnopq',getline(1))
3182 call feedkeys(">>", 'tx')
3183 call assert_equal('abcde fghij klmnopq',getline(1))
3184
3185 " cleanup
3186 set norl
3187 bw!
3188endfunc
3189
Bram Moolenaarb1e04fc2017-03-29 13:08:35 +02003190func Test_normal54_Ctrl_bsl()
3191 new
3192 call setline(1, 'abcdefghijklmn')
3193 exe "norm! df\<c-\>\<c-n>"
3194 call assert_equal(['abcdefghijklmn'], getline(1,'$'))
3195 exe "norm! df\<c-\>\<c-g>"
3196 call assert_equal(['abcdefghijklmn'], getline(1,'$'))
3197 exe "norm! df\<c-\>m"
3198 call assert_equal(['abcdefghijklmn'], getline(1,'$'))
Bram Moolenaar30276f22019-01-24 17:59:39 +01003199
Bram Moolenaarb1e04fc2017-03-29 13:08:35 +02003200 call setline(2, 'abcdefghijklmnāf')
3201 norm! 2gg0
3202 exe "norm! df\<Char-0x101>"
3203 call assert_equal(['abcdefghijklmn', 'f'], getline(1,'$'))
3204 norm! 1gg0
3205 exe "norm! df\<esc>"
3206 call assert_equal(['abcdefghijklmn', 'f'], getline(1,'$'))
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02003207
Bram Moolenaarb1e04fc2017-03-29 13:08:35 +02003208 " clean up
3209 bw!
3210endfunc
3211
3212func Test_normal_large_count()
3213 " This may fail with 32bit long, how do we detect that?
3214 new
3215 normal o
3216 normal 6666666666dL
3217 bwipe!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02003218endfunc
Bram Moolenaarbf3d5802017-03-29 19:48:11 +02003219
3220func Test_delete_until_paragraph()
Bram Moolenaarbf3d5802017-03-29 19:48:11 +02003221 new
3222 normal grádv}
3223 call assert_equal('á', getline(1))
3224 normal grád}
3225 call assert_equal('', getline(1))
3226 bwipe!
3227endfunc
Bram Moolenaarfb094e12017-11-05 20:59:28 +01003228
3229" Test for the gr (virtual replace) command
3230" Test for the bug fixed by 7.4.387
3231func Test_gr_command()
3232 enew!
3233 let save_cpo = &cpo
3234 call append(0, ['First line', 'Second line', 'Third line'])
3235 exe "normal i\<C-G>u"
3236 call cursor(2, 1)
3237 set cpo-=X
3238 normal 4gro
3239 call assert_equal('oooond line', getline(2))
3240 undo
3241 set cpo+=X
3242 normal 4gro
3243 call assert_equal('ooooecond line', getline(2))
3244 let &cpo = save_cpo
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01003245 normal! ggvegrx
3246 call assert_equal('xxxxx line', getline(1))
3247 exe "normal! gggr\<C-V>122"
3248 call assert_equal('zxxxx line', getline(1))
3249 set virtualedit=all
3250 normal! 15|grl
3251 call assert_equal('zxxxx line l', getline(1))
3252 set virtualedit&
3253 set nomodifiable
3254 call assert_fails('normal! grx', 'E21:')
3255 call assert_fails('normal! gRx', 'E21:')
3256 set modifiable&
Bram Moolenaarfb094e12017-11-05 20:59:28 +01003257 enew!
3258endfunc
3259
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01003260func Test_nv_hat_count()
3261 %bwipeout!
3262 let l:nr = bufnr('%') + 1
Bram Moolenaare2e40752020-09-04 21:18:46 +02003263 call assert_fails(':execute "normal! ' . l:nr . '\<C-^>"', 'E92:')
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01003264
3265 edit Xfoo
3266 let l:foo_nr = bufnr('Xfoo')
3267
3268 edit Xbar
3269 let l:bar_nr = bufnr('Xbar')
3270
3271 " Make sure we are not just using the alternate file.
3272 edit Xbaz
3273
3274 call feedkeys(l:foo_nr . "\<C-^>", 'tx')
3275 call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t'))
3276
3277 call feedkeys(l:bar_nr . "\<C-^>", 'tx')
3278 call assert_equal('Xbar', fnamemodify(bufname('%'), ':t'))
3279
3280 %bwipeout!
3281endfunc
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01003282
3283func Test_message_when_using_ctrl_c()
Bram Moolenaar553e5a52019-03-25 23:16:34 +01003284 " Make sure no buffers are changed.
3285 %bwipe!
3286
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01003287 exe "normal \<C-C>"
3288 call assert_match("Type :qa and press <Enter> to exit Vim", Screenline(&lines))
Bram Moolenaar553e5a52019-03-25 23:16:34 +01003289
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01003290 new
3291 cal setline(1, 'hi!')
3292 exe "normal \<C-C>"
3293 call assert_match("Type :qa! and press <Enter> to abandon all changes and exit Vim", Screenline(&lines))
Bram Moolenaar553e5a52019-03-25 23:16:34 +01003294
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01003295 bwipe!
3296endfunc
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02003297
Bram Moolenaar7a1d3282022-06-16 13:04:45 +01003298func Test_mode_updated_after_ctrl_c()
3299 CheckScreendump
3300
3301 let buf = RunVimInTerminal('', {'rows': 5})
3302 call term_sendkeys(buf, "i")
3303 call term_sendkeys(buf, "\<C-O>")
3304 " wait a moment so that the "-- (insert) --" message is displayed
3305 call TermWait(buf, 50)
3306 call term_sendkeys(buf, "\<C-C>")
3307 call VerifyScreenDump(buf, 'Test_mode_updated_1', {})
3308
3309 call StopVimInTerminal(buf)
3310endfunc
3311
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02003312" Test for '[m', ']m', '[M' and ']M'
3313" Jumping to beginning and end of methods in Java-like languages
3314func Test_java_motion()
3315 new
Bram Moolenaar1671f442020-03-10 07:48:13 +01003316 call assert_beeps('normal! [m')
3317 call assert_beeps('normal! ]m')
3318 call assert_beeps('normal! [M')
3319 call assert_beeps('normal! ]M')
Bram Moolenaar8a9bc952020-10-02 18:48:07 +02003320 let lines =<< trim [CODE]
3321 Piece of Java
3322 {
3323 tt m1 {
3324 t1;
3325 } e1
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02003326
Bram Moolenaar8a9bc952020-10-02 18:48:07 +02003327 tt m2 {
3328 t2;
3329 } e2
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02003330
Bram Moolenaar8a9bc952020-10-02 18:48:07 +02003331 tt m3 {
3332 if (x)
3333 {
3334 t3;
3335 }
3336 } e3
3337 }
3338 [CODE]
3339 call setline(1, lines)
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02003340
3341 normal gg
3342
3343 normal 2]maA
3344 call assert_equal("\ttt m1 {A", getline('.'))
3345 call assert_equal([3, 9, 16], [line('.'), col('.'), virtcol('.')])
3346
3347 normal j]maB
3348 call assert_equal("\ttt m2 {B", getline('.'))
3349 call assert_equal([7, 9, 16], [line('.'), col('.'), virtcol('.')])
3350
3351 normal ]maC
3352 call assert_equal("\ttt m3 {C", getline('.'))
3353 call assert_equal([11, 9, 16], [line('.'), col('.'), virtcol('.')])
3354
3355 normal [maD
3356 call assert_equal("\ttt m3 {DC", getline('.'))
3357 call assert_equal([11, 9, 16], [line('.'), col('.'), virtcol('.')])
3358
3359 normal k2[maE
3360 call assert_equal("\ttt m1 {EA", getline('.'))
3361 call assert_equal([3, 9, 16], [line('.'), col('.'), virtcol('.')])
3362
3363 normal 3[maF
3364 call assert_equal("{F", getline('.'))
3365 call assert_equal([2, 2, 2], [line('.'), col('.'), virtcol('.')])
3366
3367 normal ]MaG
3368 call assert_equal("\t}G e1", getline('.'))
3369 call assert_equal([5, 3, 10], [line('.'), col('.'), virtcol('.')])
3370
3371 normal j2]MaH
3372 call assert_equal("\t}H e3", getline('.'))
3373 call assert_equal([16, 3, 10], [line('.'), col('.'), virtcol('.')])
3374
3375 normal ]M]M
3376 normal aI
3377 call assert_equal("}I", getline('.'))
3378 call assert_equal([17, 2, 2], [line('.'), col('.'), virtcol('.')])
3379
3380 normal 2[MaJ
3381 call assert_equal("\t}JH e3", getline('.'))
3382 call assert_equal([16, 3, 10], [line('.'), col('.'), virtcol('.')])
3383
3384 normal k[MaK
3385 call assert_equal("\t}K e2", getline('.'))
3386 call assert_equal([9, 3, 10], [line('.'), col('.'), virtcol('.')])
3387
3388 normal 3[MaL
3389 call assert_equal("{LF", getline('.'))
3390 call assert_equal([2, 2, 2], [line('.'), col('.'), virtcol('.')])
3391
Bram Moolenaar8a9bc952020-10-02 18:48:07 +02003392 call cursor(2, 1)
3393 call assert_beeps('norm! 5]m')
3394
3395 " jumping to a method in a fold should open the fold
3396 6,10fold
3397 call feedkeys("gg3]m", 'xt')
3398 call assert_equal([7, 8, 15], [line('.'), col('.'), virtcol('.')])
3399 call assert_equal(-1, foldclosedend(7))
3400
Yee Cheng Chin1881abf2022-12-08 09:41:24 +00003401 bwipe!
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02003402endfunc
Bram Moolenaard5c82342019-07-27 18:44:57 +02003403
Bram Moolenaar004a6782020-04-11 17:09:31 +02003404" Tests for g cmds
Bram Moolenaar1671f442020-03-10 07:48:13 +01003405func Test_normal_gdollar_cmd()
Bram Moolenaard5c82342019-07-27 18:44:57 +02003406 call Setup_NewWindow()
3407 " Make long lines that will wrap
3408 %s/$/\=repeat(' foobar', 10)/
3409 20vsp
3410 set wrap
3411 " Test for g$ with count
3412 norm! gg
3413 norm! 0vg$y
3414 call assert_equal(20, col("'>"))
3415 call assert_equal('1 foobar foobar foob', getreg(0))
3416 norm! gg
3417 norm! 0v4g$y
3418 call assert_equal(72, col("'>"))
3419 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.."\n", getreg(0))
3420 norm! gg
3421 norm! 0v6g$y
3422 call assert_equal(40, col("'>"))
3423 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
3424 \ '2 foobar foobar foobar foobar foobar foo', getreg(0))
3425 set nowrap
3426 " clean up
3427 norm! gg
3428 norm! 0vg$y
3429 call assert_equal(20, col("'>"))
3430 call assert_equal('1 foobar foobar foob', getreg(0))
3431 norm! gg
3432 norm! 0v4g$y
3433 call assert_equal(20, col("'>"))
3434 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
3435 \ '2 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
3436 \ '3 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
3437 \ '4 foobar foobar foob', getreg(0))
3438 norm! gg
3439 norm! 0v6g$y
3440 call assert_equal(20, col("'>"))
3441 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
3442 \ '2 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
3443 \ '3 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
3444 \ '4 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
3445 \ '5 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
3446 \ '6 foobar foobar foob', getreg(0))
3447 " Move to last line, also down movement is not possible, should still move
3448 " the cursor to the last visible char
3449 norm! G
3450 norm! 0v6g$y
3451 call assert_equal(20, col("'>"))
3452 call assert_equal('100 foobar foobar fo', getreg(0))
3453 bw!
3454endfunc
Bram Moolenaar03ac52f2019-09-24 22:47:46 +02003455
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01003456func Test_normal_gk_gj()
Bram Moolenaar03ac52f2019-09-24 22:47:46 +02003457 " needs 80 column new window
3458 new
3459 vert 80new
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01003460 call assert_beeps('normal gk')
Bram Moolenaar03ac52f2019-09-24 22:47:46 +02003461 put =[repeat('x',90)..' {{{1', 'x {{{1']
3462 norm! gk
3463 " In a 80 column wide terminal the window will be only 78 char
3464 " (because Vim will leave space for the other window),
3465 " but if the terminal is larger, it will be 80 chars, so verify the
3466 " cursor column correctly.
3467 call assert_equal(winwidth(0)+1, col('.'))
3468 call assert_equal(winwidth(0)+1, virtcol('.'))
3469 norm! j
3470 call assert_equal(6, col('.'))
3471 call assert_equal(6, virtcol('.'))
3472 norm! gk
3473 call assert_equal(95, col('.'))
3474 call assert_equal(95, virtcol('.'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01003475 %bw!
Bram Moolenaarceba3dd2019-10-12 16:12:54 +02003476
3477 " needs 80 column new window
3478 new
3479 vert 80new
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01003480 call assert_beeps('normal gj')
Bram Moolenaarceba3dd2019-10-12 16:12:54 +02003481 set number
3482 set numberwidth=10
3483 set cpoptions+=n
3484 put =[repeat('0',90), repeat('1',90)]
3485 norm! 075l
3486 call assert_equal(76, col('.'))
3487 norm! gk
3488 call assert_equal(1, col('.'))
3489 norm! gk
3490 call assert_equal(76, col('.'))
3491 norm! gk
3492 call assert_equal(1, col('.'))
3493 norm! gj
3494 call assert_equal(76, col('.'))
3495 norm! gj
3496 call assert_equal(1, col('.'))
3497 norm! gj
3498 call assert_equal(76, col('.'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01003499 " When 'nowrap' is set, gk and gj behave like k and j
3500 set nowrap
3501 normal! gk
3502 call assert_equal([2, 76], [line('.'), col('.')])
3503 normal! gj
3504 call assert_equal([3, 76], [line('.'), col('.')])
3505 %bw!
3506 set cpoptions& number& numberwidth& wrap&
Bram Moolenaar03ac52f2019-09-24 22:47:46 +02003507endfunc
Bram Moolenaarf0cee192020-02-16 13:33:56 +01003508
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01003509" Test for using : to run a multi-line Ex command in operator pending mode
3510func Test_normal_yank_with_excmd()
3511 new
3512 call setline(1, ['foo', 'bar', 'baz'])
3513 let @a = ''
3514 call feedkeys("\"ay:if v:true\<CR>normal l\<CR>endif\<CR>", 'xt')
3515 call assert_equal('f', @a)
Yee Cheng Chin1881abf2022-12-08 09:41:24 +00003516
3517 bwipe!
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01003518endfunc
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01003519
3520" Test for supplying a count to a normal-mode command across a cursorhold call
3521func Test_normal_cursorhold_with_count()
3522 func s:cHold()
3523 let g:cHold_Called += 1
3524 endfunc
3525 new
3526 augroup normalcHoldTest
3527 au!
3528 au CursorHold <buffer> call s:cHold()
3529 augroup END
3530 let g:cHold_Called = 0
3531 call feedkeys("3\<CursorHold>2ix", 'xt')
3532 call assert_equal(1, g:cHold_Called)
3533 call assert_equal(repeat('x', 32), getline(1))
3534 augroup normalcHoldTest
3535 au!
3536 augroup END
3537 au! normalcHoldTest
Yee Cheng Chin1881abf2022-12-08 09:41:24 +00003538
3539 bwipe!
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01003540 delfunc s:cHold
3541endfunc
3542
3543" Test for using a count and a command with CTRL-W
3544func Test_wincmd_with_count()
3545 call feedkeys("\<C-W>12n", 'xt')
3546 call assert_equal(12, winheight(0))
3547endfunc
3548
3549" Test for 'b', 'B' 'ge' and 'gE' commands
Bram Moolenaar1671f442020-03-10 07:48:13 +01003550func Test_horiz_motion()
3551 new
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01003552 normal! gg
3553 call assert_beeps('normal! b')
3554 call assert_beeps('normal! B')
3555 call assert_beeps('normal! gE')
3556 call assert_beeps('normal! ge')
Bram Moolenaar1671f442020-03-10 07:48:13 +01003557 " <S-Backspace> moves one word left and <C-Backspace> moves one WORD left
3558 call setline(1, 'one ,two ,three')
3559 exe "normal! $\<S-BS>"
3560 call assert_equal(11, col('.'))
3561 exe "normal! $\<C-BS>"
3562 call assert_equal(10, col('.'))
Yee Cheng Chin1881abf2022-12-08 09:41:24 +00003563
3564 bwipe!
Bram Moolenaar1671f442020-03-10 07:48:13 +01003565endfunc
3566
3567" Test for using a : command in operator pending mode
3568func Test_normal_colon_op()
3569 new
3570 call setline(1, ['one', 'two'])
3571 call assert_beeps("normal! Gc:d\<CR>")
Yee Cheng Chin1881abf2022-12-08 09:41:24 +00003572 bwipe!
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01003573endfunc
3574
Bram Moolenaar004a6782020-04-11 17:09:31 +02003575" Test for d and D commands
3576func Test_normal_delete_cmd()
3577 new
3578 " D in an empty line
3579 call setline(1, '')
3580 normal D
3581 call assert_equal('', getline(1))
3582 " D in an empty line in virtualedit mode
3583 set virtualedit=all
3584 normal D
3585 call assert_equal('', getline(1))
3586 set virtualedit&
3587 " delete to a readonly register
3588 call setline(1, ['abcd'])
3589 call assert_beeps('normal ":d2l')
Bram Moolenaar6fd367a2021-03-13 13:14:04 +01003590
3591 " D and d with 'nomodifiable'
3592 call setline(1, ['abcd'])
3593 setlocal nomodifiable
3594 call assert_fails('normal D', 'E21:')
3595 call assert_fails('normal d$', 'E21:')
3596
Yee Cheng Chin1881abf2022-12-08 09:41:24 +00003597 bwipe!
Bram Moolenaar004a6782020-04-11 17:09:31 +02003598endfunc
3599
Bram Moolenaar8a9bc952020-10-02 18:48:07 +02003600" Test for deleting or changing characters across lines with 'whichwrap'
3601" containing 's'. Should count <EOL> as one character.
3602func Test_normal_op_across_lines()
3603 new
3604 set whichwrap&
3605 call setline(1, ['one two', 'three four'])
3606 exe "norm! $3d\<Space>"
3607 call assert_equal(['one twhree four'], getline(1, '$'))
3608
3609 call setline(1, ['one two', 'three four'])
3610 exe "norm! $3c\<Space>x"
3611 call assert_equal(['one twxhree four'], getline(1, '$'))
3612
3613 set whichwrap+=l
3614 call setline(1, ['one two', 'three four'])
3615 exe "norm! $3x"
3616 call assert_equal(['one twhree four'], getline(1, '$'))
Yee Cheng Chin1881abf2022-12-08 09:41:24 +00003617
3618 bwipe!
Bram Moolenaar8a9bc952020-10-02 18:48:07 +02003619 set whichwrap&
3620endfunc
3621
Bram Moolenaar224a5f12020-04-28 20:29:07 +02003622" Test for 'w' and 'b' commands
3623func Test_normal_word_move()
3624 new
3625 call setline(1, ['foo bar a', '', 'foo bar b'])
3626 " copy a single character word at the end of a line
3627 normal 1G$yw
3628 call assert_equal('a', @")
3629 " copy a single character word at the end of a file
3630 normal G$yw
3631 call assert_equal('b', @")
3632 " check for a word movement handling an empty line properly
3633 normal 1G$vwy
3634 call assert_equal("a\n\n", @")
3635
3636 " copy using 'b' command
3637 %d
3638 " non-empty blank line at the start of file
3639 call setline(1, [' ', 'foo bar'])
3640 normal 2Gyb
3641 call assert_equal(" \n", @")
3642 " try to copy backwards from the start of the file
3643 call setline(1, ['one two', 'foo bar'])
3644 call assert_beeps('normal ggyb')
3645 " 'b' command should stop at an empty line
3646 call setline(1, ['one two', '', 'foo bar'])
3647 normal 3Gyb
3648 call assert_equal("\n", @")
3649 normal 3Gy2b
3650 call assert_equal("two\n", @")
3651 " 'b' command should not stop at a non-empty blank line
3652 call setline(1, ['one two', ' ', 'foo bar'])
3653 normal 3Gyb
3654 call assert_equal("two\n ", @")
3655
Yee Cheng Chin1881abf2022-12-08 09:41:24 +00003656 bwipe!
Bram Moolenaar224a5f12020-04-28 20:29:07 +02003657endfunc
3658
Bram Moolenaarbdd2c292020-06-22 21:34:30 +02003659" Test for 'scrolloff' with a long line that doesn't fit in the screen
Yee Cheng Chin1881abf2022-12-08 09:41:24 +00003660func Test_normal_scrolloff()
Bram Moolenaarbdd2c292020-06-22 21:34:30 +02003661 10new
Bram Moolenaar4b6172e2022-10-13 20:23:28 +01003662 60vnew
3663 call setline(1, ' 1 ' .. repeat('a', 57)
3664 \ .. ' 2 ' .. repeat('b', 57)
3665 \ .. ' 3 ' .. repeat('c', 57)
3666 \ .. ' 4 ' .. repeat('d', 57)
3667 \ .. ' 5 ' .. repeat('e', 57)
3668 \ .. ' 6 ' .. repeat('f', 57)
3669 \ .. ' 7 ' .. repeat('g', 57)
3670 \ .. ' 8 ' .. repeat('h', 57)
3671 \ .. ' 9 ' .. repeat('i', 57)
3672 \ .. '10 ' .. repeat('j', 57)
3673 \ .. '11 ' .. repeat('k', 57)
3674 \ .. '12 ' .. repeat('l', 57)
3675 \ .. '13 ' .. repeat('m', 57)
3676 \ .. '14 ' .. repeat('n', 57)
3677 \ .. '15 ' .. repeat('o', 57)
3678 \ .. '16 ' .. repeat('p', 57)
3679 \ .. '17 ' .. repeat('q', 57)
3680 \ .. '18 ' .. repeat('r', 57)
3681 \ .. '19 ' .. repeat('s', 57)
3682 \ .. '20 ' .. repeat('t', 57)
3683 \ .. '21 ' .. repeat('u', 57)
3684 \ .. '22 ' .. repeat('v', 57)
3685 \ .. '23 ' .. repeat('w', 57)
3686 \ .. '24 ' .. repeat('x', 57)
3687 \ .. '25 ' .. repeat('y', 57)
3688 \ .. '26 ' .. repeat('z', 57)
3689 \ )
Bram Moolenaarbdd2c292020-06-22 21:34:30 +02003690 set scrolloff=10
3691 normal gg10gj
Bram Moolenaar4b6172e2022-10-13 20:23:28 +01003692 call assert_equal(6, winline())
Bram Moolenaarbdd2c292020-06-22 21:34:30 +02003693 normal 10gj
Bram Moolenaar4b6172e2022-10-13 20:23:28 +01003694 call assert_equal(6, winline())
Bram Moolenaarbdd2c292020-06-22 21:34:30 +02003695 normal 10gk
Bram Moolenaar4b6172e2022-10-13 20:23:28 +01003696 call assert_equal(6, winline())
3697 normal 0
3698 call assert_equal(1, winline())
3699 normal $
3700 call assert_equal(10, winline())
Yee Cheng Chin1881abf2022-12-08 09:41:24 +00003701
Bram Moolenaarbdd2c292020-06-22 21:34:30 +02003702 set scrolloff&
Yee Cheng Chin1881abf2022-12-08 09:41:24 +00003703 bwipe!
Bram Moolenaarbdd2c292020-06-22 21:34:30 +02003704endfunc
3705
3706" Test for vertical scrolling with CTRL-F and CTRL-B with a long line
3707func Test_normal_vert_scroll_longline()
3708 10new
3709 80vnew
3710 call setline(1, range(1, 10))
3711 call append(5, repeat('a', 1000))
3712 exe "normal gg\<C-F>"
3713 call assert_equal(6, line('.'))
3714 exe "normal \<C-F>\<C-F>"
3715 call assert_equal(11, line('.'))
3716 call assert_equal(1, winline())
3717 exe "normal \<C-B>"
3718 call assert_equal(10, line('.'))
3719 call assert_equal(3, winline())
3720 exe "normal \<C-B>\<C-B>"
3721 call assert_equal(5, line('.'))
3722 call assert_equal(5, winline())
Yee Cheng Chin1881abf2022-12-08 09:41:24 +00003723
3724 bwipe!
Bram Moolenaarbdd2c292020-06-22 21:34:30 +02003725endfunc
3726
Bram Moolenaar8a9bc952020-10-02 18:48:07 +02003727" Test for jumping in a file using %
3728func Test_normal_percent_jump()
3729 new
3730 call setline(1, range(1, 100))
3731
3732 " jumping to a folded line should open the fold
3733 25,75fold
3734 call feedkeys('50%', 'xt')
3735 call assert_equal(50, line('.'))
3736 call assert_equal(-1, foldclosedend(50))
Yee Cheng Chin1881abf2022-12-08 09:41:24 +00003737
3738 bwipe!
Bram Moolenaar8a9bc952020-10-02 18:48:07 +02003739endfunc
3740
Bram Moolenaar3e72dca2021-05-29 16:30:12 +02003741" Test for << and >> commands to shift text by 'shiftwidth'
3742func Test_normal_shift_rightleft()
3743 new
3744 call setline(1, ['one', '', "\t", ' two', "\tthree", ' four'])
3745 set shiftwidth=2 tabstop=8
3746 normal gg6>>
3747 call assert_equal([' one', '', "\t ", ' two', "\t three", "\tfour"],
3748 \ getline(1, '$'))
3749 normal ggVG2>>
3750 call assert_equal([' one', '', "\t ", "\ttwo",
3751 \ "\t three", "\t four"], getline(1, '$'))
3752 normal gg6<<
3753 call assert_equal([' one', '', "\t ", ' two', "\t three",
3754 \ "\t four"], getline(1, '$'))
3755 normal ggVG2<<
3756 call assert_equal(['one', '', "\t", ' two', "\tthree", ' four'],
3757 \ getline(1, '$'))
3758 set shiftwidth& tabstop&
3759 bw!
3760endfunc
3761
Yegappan Lakshmanan2ac71842021-05-31 19:23:01 +02003762" Some commands like yy, cc, dd, >>, << and !! accept a count after
3763" typing the first letter of the command.
3764func Test_normal_count_after_operator()
3765 new
3766 setlocal shiftwidth=4 tabstop=8 autoindent
3767 call setline(1, ['one', 'two', 'three', 'four', 'five'])
3768 let @a = ''
3769 normal! j"ay4y
3770 call assert_equal("two\nthree\nfour\nfive\n", @a)
3771 normal! 3G>2>
3772 call assert_equal(['one', 'two', ' three', ' four', 'five'],
3773 \ getline(1, '$'))
3774 exe "normal! 3G0c2cred\nblue"
3775 call assert_equal(['one', 'two', ' red', ' blue', 'five'],
3776 \ getline(1, '$'))
3777 exe "normal! gg<8<"
3778 call assert_equal(['one', 'two', 'red', 'blue', 'five'],
3779 \ getline(1, '$'))
3780 exe "normal! ggd3d"
3781 call assert_equal(['blue', 'five'], getline(1, '$'))
3782 call setline(1, range(1, 4))
3783 call feedkeys("gg!3!\<C-B>\"\<CR>", 'xt')
3784 call assert_equal('".,.+2!', @:)
3785 call feedkeys("gg!1!\<C-B>\"\<CR>", 'xt')
3786 call assert_equal('".!', @:)
3787 call feedkeys("gg!9!\<C-B>\"\<CR>", 'xt')
3788 call assert_equal('".,$!', @:)
3789 bw!
3790endfunc
3791
Christian Brabandtaaec1d42021-11-04 13:28:29 +00003792func Test_normal_gj_on_extra_wide_char()
3793 new | 25vsp
3794 let text='1 foooooooo ar e inszwe1 foooooooo inszwei' .
3795 \ ' i drei vier fünf sechs sieben acht un zehn elf zwöfl' .
3796 \ ' dreizehn v ierzehn fünfzehn'
3797 put =text
3798 call cursor(2,1)
3799 norm! gj
3800 call assert_equal([0,2,25,0], getpos('.'))
3801 bw!
3802endfunc
3803
Bram Moolenaar03725c52021-11-24 12:17:53 +00003804func Test_normal_count_out_of_range()
3805 new
3806 call setline(1, 'text')
3807 normal 44444444444|
3808 call assert_equal(999999999, v:count)
3809 normal 444444444444|
3810 call assert_equal(999999999, v:count)
3811 normal 4444444444444|
3812 call assert_equal(999999999, v:count)
3813 normal 4444444444444444444|
3814 call assert_equal(999999999, v:count)
3815
3816 normal 9y99999999|
3817 call assert_equal(899999991, v:count)
3818 normal 10y99999999|
3819 call assert_equal(999999999, v:count)
3820 normal 44444444444y44444444444|
3821 call assert_equal(999999999, v:count)
3822 bwipe!
3823endfunc
3824
zeertzjqcdeb6572022-11-15 13:46:12 +00003825" Test that mouse shape is restored to Normal mode after failed "c" operation.
3826func Test_mouse_shape_after_failed_change()
3827 CheckFeature mouseshape
3828 CheckCanRunGui
3829
3830 let lines =<< trim END
Yee Cheng Chin1881abf2022-12-08 09:41:24 +00003831 vim9script
zeertzjqcdeb6572022-11-15 13:46:12 +00003832 set mouseshape+=o:busy
3833 setlocal nomodifiable
Yee Cheng Chin1881abf2022-12-08 09:41:24 +00003834 var mouse_shapes = []
zeertzjqcdeb6572022-11-15 13:46:12 +00003835
Yee Cheng Chin1881abf2022-12-08 09:41:24 +00003836 feedkeys('c')
3837 timer_start(50, (_) => {
3838 mouse_shapes += [getmouseshape()]
3839 timer_start(50, (_) => {
3840 feedkeys('c')
3841 timer_start(50, (_) => {
3842 mouse_shapes += [getmouseshape()]
3843 timer_start(50, (_) => {
3844 writefile(mouse_shapes, 'Xmouseshapes')
3845 quit
3846 })
3847 })
3848 })
3849 })
zeertzjqcdeb6572022-11-15 13:46:12 +00003850 END
3851 call writefile(lines, 'Xmouseshape.vim', 'D')
3852 call RunVim([], [], "-g -S Xmouseshape.vim")
3853 sleep 300m
3854 call assert_equal(['busy', 'arrow'], readfile('Xmouseshapes'))
3855
3856 call delete('Xmouseshapes')
3857endfunc
3858
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01003859" vim: shiftwidth=2 sts=2 expandtab